-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_handler.go
50 lines (39 loc) · 1.03 KB
/
service_handler.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
package suzu
import (
"context"
"fmt"
"io"
"golang.org/x/exp/slices"
)
var (
NewServiceHandlerFuncs = make(newServiceHandlerFuncs)
ErrServiceNotFound = fmt.Errorf("SERVICE-NOT-FOUND")
)
type serviceHandlerInterface interface {
Handle(context.Context, io.Reader) (*io.PipeReader, error)
UpdateRetryCount() int
GetRetryCount() int
ResetRetryCount() int
}
type newServiceHandlerFunc func(Config, string, string, uint32, uint16, string, any) serviceHandlerInterface
type newServiceHandlerFuncs map[string]newServiceHandlerFunc
func (sh *newServiceHandlerFuncs) register(name string, f newServiceHandlerFunc) {
(*sh)[name] = f
}
func (sh *newServiceHandlerFuncs) get(name string) (*newServiceHandlerFunc, error) {
h, ok := (*sh)[name]
if !ok {
return nil, ErrServiceNotFound
}
return &h, nil
}
func (sh *newServiceHandlerFuncs) GetNames(exclude []string) []string {
names := make([]string, 0, len(*sh))
for name := range *sh {
if slices.Contains(exclude, name) {
continue
}
names = append(names, name)
}
return names
}