-
Notifications
You must be signed in to change notification settings - Fork 19
/
admin_stop_service.go
51 lines (39 loc) · 1.23 KB
/
admin_stop_service.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package api
import (
"context"
"code.vegaprotocol.io/vega/libs/jsonrpc"
"github.com/mitchellh/mapstructure"
)
type AdminStopServiceParams struct {
Network string `json:"network"`
}
type AdminStopService struct {
servicesManager *ServicesManager
}
// Handle closes all opened connections to a running service and stop the service.
func (h *AdminStopService) Handle(_ context.Context, rawParams jsonrpc.Params, _ jsonrpc.RequestMetadata) (jsonrpc.Result, *jsonrpc.ErrorDetails) {
params, err := validateAdminStopServiceParams(rawParams)
if err != nil {
return nil, invalidParams(err)
}
h.servicesManager.StopService(params.Network)
return nil, nil
}
func validateAdminStopServiceParams(rawParams jsonrpc.Params) (AdminStopServiceParams, error) {
if rawParams == nil {
return AdminStopServiceParams{}, ErrParamsRequired
}
params := AdminStopServiceParams{}
if err := mapstructure.Decode(rawParams, ¶ms); err != nil {
return AdminStopServiceParams{}, ErrParamsDoNotMatch
}
if params.Network == "" {
return AdminStopServiceParams{}, ErrNetworkIsRequired
}
return params, nil
}
func NewAdminStopService(servicesManager *ServicesManager) *AdminStopService {
return &AdminStopService{
servicesManager: servicesManager,
}
}