mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
cda14447ad
Co-authored-by: Giulio <giulio.rebuffo@gmail.com>
44 lines
737 B
Go
44 lines
737 B
Go
package spectest
|
|
|
|
import (
|
|
"golang.org/x/exp/slices"
|
|
)
|
|
|
|
type Format struct {
|
|
handlers map[string]Handler
|
|
}
|
|
|
|
func NewFormat() *Format {
|
|
o := &Format{
|
|
handlers: map[string]Handler{},
|
|
}
|
|
return o
|
|
}
|
|
|
|
func (r *Format) With(name string, handler Handler) *Format {
|
|
r.handlers[name] = handler
|
|
return r
|
|
}
|
|
|
|
func (r *Format) WithFn(name string, handler HandlerFunc) *Format {
|
|
r.handlers[name] = handler
|
|
return r
|
|
}
|
|
|
|
func (r *Format) GetHandlers() []string {
|
|
o := make([]string, 0, len(r.handlers))
|
|
for k := range r.handlers {
|
|
o = append(o, k)
|
|
}
|
|
slices.Sort(o)
|
|
return o
|
|
}
|
|
|
|
func (r *Format) GetHandler(name string) (Handler, error) {
|
|
val, ok := r.handlers[name]
|
|
if !ok {
|
|
return nil, ErrHandlerNotFound(name)
|
|
}
|
|
return val, nil
|
|
}
|