github.com/koko1123/flow-go-1@v0.29.6/admin/commands/uploader/toggle_uploader.go (about) 1 package uploader 2 3 import ( 4 "context" 5 6 "github.com/koko1123/flow-go-1/admin" 7 "github.com/koko1123/flow-go-1/admin/commands" 8 "github.com/koko1123/flow-go-1/engine/execution/ingestion/uploader" 9 ) 10 11 var _ commands.AdminCommand = (*ToggleUploaderCommand)(nil) 12 13 type ToggleUploaderCommand struct { 14 uploadManager *uploader.Manager 15 } 16 17 func (t *ToggleUploaderCommand) Handler(ctx context.Context, req *admin.CommandRequest) (interface{}, error) { 18 enabled := req.ValidatorData.(bool) 19 t.uploadManager.SetEnabled(enabled) 20 return "ok", nil 21 } 22 23 // Validator validates the request. 24 // Returns admin.InvalidAdminReqError for invalid/malformed requests. 25 func (t *ToggleUploaderCommand) Validator(req *admin.CommandRequest) error { 26 enabled, ok := req.Data.(bool) 27 if !ok { 28 return admin.NewInvalidAdminReqFormatError("expected bool") 29 } 30 31 req.ValidatorData = enabled 32 return nil 33 } 34 35 func NewToggleUploaderCommand(uploadManager *uploader.Manager) commands.AdminCommand { 36 return &ToggleUploaderCommand{ 37 uploadManager: uploadManager, 38 } 39 }