-
Notifications
You must be signed in to change notification settings - Fork 175
/
command.go
30 lines (26 loc) · 1.27 KB
/
command.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package commands
import (
"context"
"github.com/onflow/flow-go/admin"
)
// AdminCommand defines the interface expected for admin command handlers.
type AdminCommand interface {
// Validator is responsible for validating the input of a command, available in
// the Data field of the request argument. By convention, Validator may set the
// ValidatorData field on the request, and this will persist when the request
// is passed to Handler.
//
// Returns admin.InvalidAdminReqError if request validation fails.
// Any error returned will abort the command execution.
// Expected errors will be returned to the caller with InvalidArg error code.
// Unexpected errors will be returned with Internal error code, but will not be otherwise propagated.
Validator(request *admin.CommandRequest) error
// Handler is responsible for handling the request. It applies any state
// changes associated with the request and returns any values which should
// be displayed to the initiator of the request.
//
// No errors are expected during normal operation.
// If any error is returned, the command was aborted.
// Unexpected errors will be returned with Internal error code, but will not be otherwise propagated.
Handler(ctx context.Context, request *admin.CommandRequest) (any, error)
}