From 2fd98cb040b617d2a018ae00a3a68b320de7dbc6 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Tue, 21 May 2019 14:22:21 -0600 Subject: Module.New() does not need to return an error --- context.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'context.go') diff --git a/context.go b/context.go index e437f08..bdf9f60 100644 --- a/context.go +++ b/context.go @@ -75,10 +75,7 @@ func (ctx Context) LoadModule(name string, rawMsg json.RawMessage) (interface{}, return nil, fmt.Errorf("module '%s' has no constructor", mod.Name) } - val, err := mod.New() - if err != nil { - return nil, fmt.Errorf("initializing module '%s': %v", mod.Name, err) - } + val := mod.New() // value must be a pointer for unmarshaling into concrete type if rv := reflect.ValueOf(val); rv.Kind() != reflect.Ptr { @@ -87,7 +84,7 @@ func (ctx Context) LoadModule(name string, rawMsg json.RawMessage) (interface{}, // fill in its config only if there is a config to fill in if len(rawMsg) > 0 { - err = json.Unmarshal(rawMsg, &val) + err := json.Unmarshal(rawMsg, &val) if err != nil { return nil, fmt.Errorf("decoding module config: %s: %v", mod.Name, err) } -- cgit v1.2.3