优化结构
This commit is contained in:
@@ -36,12 +36,6 @@ func (r *Registry) Register(method Method) {
|
||||
r.methods[method.Name] = method
|
||||
}
|
||||
|
||||
func (r *Registry) RegisterAll(methods []Method) {
|
||||
for _, method := range methods {
|
||||
r.Register(method)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Registry) Lookup(name string) (MethodFunc, bool) {
|
||||
if r == nil {
|
||||
return nil, false
|
||||
|
||||
@@ -8,7 +8,9 @@ import (
|
||||
|
||||
func TestRegistryIsComposableAndIdempotent(t *testing.T) {
|
||||
registry := NewRegistry()
|
||||
registry.RegisterAll([]Method{{Name: "orders.sync", Run: func(context.Context, json.RawMessage) error { return nil }}, {Name: "system.cleanup", Run: func(context.Context, json.RawMessage) error { return nil }}})
|
||||
for _, method := range []Method{{Name: "orders.sync", Run: func(context.Context, json.RawMessage) error { return nil }}, {Name: "system.cleanup", Run: func(context.Context, json.RawMessage) error { return nil }}} {
|
||||
registry.Register(method)
|
||||
}
|
||||
registry.Register(Method{Name: "orders.sync", Description: "updated", Run: func(context.Context, json.RawMessage) error { return nil }})
|
||||
methods := registry.List()
|
||||
if len(methods) != 2 || methods[0].Name != "orders.sync" || methods[0].Description != "updated" {
|
||||
|
||||
Reference in New Issue
Block a user