TypeMatch accepts a list of possible type signatures that we want to check against after type unification. This helper function returns a function which is suitable for use in the scaffold check function field.
(typeList []string)
| 226 | // against after type unification. This helper function returns a function which |
| 227 | // is suitable for use in the scaffold check function field. |
| 228 | func TypeMatch(typeList []string) func(*types.Type) error { |
| 229 | return func(typ *types.Type) error { |
| 230 | for _, s := range typeList { |
| 231 | t := types.NewType(s) |
| 232 | if t == nil { |
| 233 | // TODO: should we panic? |
| 234 | continue // skip |
| 235 | } |
| 236 | if unificationUtil.UnifyCmp(typ, t) == nil { |
| 237 | return nil |
| 238 | } |
| 239 | } |
| 240 | return fmt.Errorf("did not match") |
| 241 | |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | // StructRegister takes an CLI args struct with optional struct tags, and |
| 246 | // generates simple functions from the contained fields in the specified |