1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- 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
- }
|