MCPcopy Create free account
hub / github.com/despiteallobjections/amigo / NewStruct

Function NewStruct

types/struct.go:26–39  ·  view source on GitHub ↗

NewStruct returns a new struct with the given fields and corresponding field tags. If a field with index i has a tag, tags[i] must be that tag, but len(tags) may be only as long as required to hold the tag with the largest index i. Consequently, if no field has a tag, tags may be nil.

(fields []*Var, tags []string)

Source from the content-addressed store, hash-verified

24// only as long as required to hold the tag with the largest index i. Consequently,
25// if no field has a tag, tags may be nil.
26func NewStruct(fields []*Var, tags []string) *Struct {
27 var fset objset
28 for _, f := range fields {
29 if f.name != "_" && fset.insert(f) != nil {
30 panic("multiple fields with the same name")
31 }
32 }
33 if len(tags) > len(fields) {
34 panic("more tags than fields")
35 }
36 s := &Struct{fields: fields, tags: tags}
37 s.markComplete()
38 return s
39}
40
41// NumFields returns the number of fields in the struct (including blank and embedded fields).
42func (s *Struct) NumFields() int { return len(s.fields) }

Callers 2

initReflectFunction · 0.92
TestIssue43088Function · 0.85

Calls 2

insertMethod · 0.95
markCompleteMethod · 0.95

Tested by 1

TestIssue43088Function · 0.68