package registry // Description of an entry type Description struct { Name string `json:"name"` Desc string `json:"description"` Tags []string `json:"categories"` //InputType Inputs []DescType `json:"inputs"` Output DescType `json:"output"` Extra map[string]interface{} `json:"extra"` } //EDescriber helper to batch set properties type EDescriber []*Entry // Describer returns a batch of entries for easy manipulation func Describer(params ...interface{}) EDescriber { ret := EDescriber{} for _, el := range params { switch v := el.(type) { case EDescriber: ret = append(ret, v...) case *Entry: ret = append(ret, v) } } return ret } // Description set node description func (d EDescriber) Description(m string) EDescriber { for _, e := range d { if e.Description == nil { continue } e.Description.Desc = m } return d } //Tags set categories of the group func (d EDescriber) Tags(tags ...string) EDescriber { for _, e := range d { if e.Description == nil { continue } e.Description.Tags = tags } return d } // Inputs describe inputs func (d EDescriber) Inputs(inputs ...string) EDescriber { for _, e := range d { if e.Description == nil { continue } for i, dstr := range inputs { if i >= len(e.Description.Inputs) { // do nothing break // next entry } curDesc := e.Description.Inputs[i] e.Description.Inputs[i] = DescType{curDesc.Type, dstr} } } return d } // Output describe the output func (d EDescriber) Output(output string) EDescriber { for _, e := range d { if e.Description == nil { continue } e.Description.Output = DescType{e.Description.Output.Type, output} } return d } // Extra set extras of the group func (d EDescriber) Extra(name string, value interface{}) EDescriber { for _, e := range d { if e.Description == nil { continue } e.Description.Extra[name] = value } return d }