lang: core: Simplify list and map lookup default functions
This commit is contained in:
@@ -108,16 +108,30 @@ func (obj *LookupDefaultFunc) Build(typ *types.Type) (*types.Type, error) {
|
||||
return nil, fmt.Errorf("first arg must have a type")
|
||||
}
|
||||
|
||||
name := ""
|
||||
if tListOrMap.Kind == types.KindList {
|
||||
obj.fn = &ListLookupDefaultFunc{} // set it
|
||||
return obj.fn.Build(typ)
|
||||
name = ListLookupDefaultFuncName
|
||||
}
|
||||
if tListOrMap.Kind == types.KindMap {
|
||||
obj.fn = &MapLookupDefaultFunc{} // set it
|
||||
return obj.fn.Build(typ)
|
||||
name = MapLookupDefaultFuncName
|
||||
}
|
||||
if name == "" {
|
||||
return nil, fmt.Errorf("we must lookup from either a list or a map")
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("we must lookup from either a list or a map")
|
||||
f, err := funcs.Lookup(name)
|
||||
if err != nil {
|
||||
// programming error
|
||||
return nil, err
|
||||
}
|
||||
bf, ok := f.(interfaces.BuildableFunc)
|
||||
if !ok {
|
||||
// programming error
|
||||
return nil, fmt.Errorf("not a BuildableFunc")
|
||||
}
|
||||
obj.fn = bf
|
||||
|
||||
return obj.fn.Build(typ)
|
||||
}
|
||||
|
||||
// Validate tells us if the input struct takes a valid form.
|
||||
|
||||
Reference in New Issue
Block a user