mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-25 06:01:35 +00:00
Add type core.AddHandlerFunc
This commit is contained in:
parent
3613614b41
commit
538ee13669
@ -39,7 +39,7 @@ type AdminSocketResponse struct {
|
|||||||
|
|
||||||
type handler struct {
|
type handler struct {
|
||||||
args []string // List of human-readable argument names
|
args []string // List of human-readable argument names
|
||||||
handler func(json.RawMessage) (interface{}, error) // First is input map, second is output
|
handler core.AddHandlerFunc // First is input map, second is output
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListResponse struct {
|
type ListResponse struct {
|
||||||
@ -51,7 +51,7 @@ type ListEntry struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddHandler is called for each admin function to add the handler and help documentation to the API.
|
// AddHandler is called for each admin function to add the handler and help documentation to the API.
|
||||||
func (a *AdminSocket) AddHandler(name string, args []string, handlerfunc func(json.RawMessage) (interface{}, error)) error {
|
func (a *AdminSocket) AddHandler(name string, args []string, handlerfunc core.AddHandlerFunc) error {
|
||||||
if _, ok := a.handlers[strings.ToLower(name)]; ok {
|
if _, ok := a.handlers[strings.ToLower(name)]; ok {
|
||||||
return errors.New("handler already exists")
|
return errors.New("handler already exists")
|
||||||
}
|
}
|
||||||
|
@ -242,9 +242,11 @@ func (c *Core) PublicKey() ed25519.PublicKey {
|
|||||||
// Hack to get the admin stuff working, TODO something cleaner
|
// Hack to get the admin stuff working, TODO something cleaner
|
||||||
|
|
||||||
type AddHandler interface {
|
type AddHandler interface {
|
||||||
AddHandler(name string, args []string, handlerfunc func(json.RawMessage) (interface{}, error)) error
|
AddHandler(name string, args []string, handlerfunc AddHandlerFunc) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AddHandlerFunc func(json.RawMessage) (interface{}, error)
|
||||||
|
|
||||||
// SetAdmin must be called after Init and before Start.
|
// SetAdmin must be called after Init and before Start.
|
||||||
// It sets the admin handler for NodeInfo and the Debug admin functions.
|
// It sets the admin handler for NodeInfo and the Debug admin functions.
|
||||||
func (c *Core) SetAdmin(a AddHandler) error {
|
func (c *Core) SetAdmin(a AddHandler) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user