|
@@ -5,15 +5,20 @@ import (
|
|
|
"reflect"
|
|
|
)
|
|
|
|
|
|
+//DescType type Description
|
|
|
+type DescType struct {
|
|
|
+ Type string `json:"type"`
|
|
|
+ Name string `json:"name"`
|
|
|
+}
|
|
|
+
|
|
|
// Description of an entry
|
|
|
type Description struct {
|
|
|
Name string `json:"name"`
|
|
|
Tags []string `json:"categories"`
|
|
|
|
|
|
- Inputs []string `json:"inputs"`
|
|
|
- InputDesc map[int]string `json:"inputsDesc"`
|
|
|
- Output string `json:"output"`
|
|
|
- OutputDesc string `json:"outputDesc"`
|
|
|
+ //InputType
|
|
|
+ Inputs []DescType `json:"inputs"`
|
|
|
+ Output DescType `json:"output"`
|
|
|
|
|
|
Extra map[string]interface{} `json:"extra"`
|
|
|
}
|
|
@@ -43,21 +48,20 @@ func NewEntry(r *R, fn interface{}) *Entry {
|
|
|
}
|
|
|
|
|
|
fnTyp := reflect.TypeOf(e.fn)
|
|
|
- Inputs := []string{}
|
|
|
nInputs := fnTyp.NumIn()
|
|
|
+ Inputs := make([]DescType, nInputs)
|
|
|
for i := 0; i < nInputs; i++ {
|
|
|
- e.Inputs = append(e.Inputs, fnTyp.In(i))
|
|
|
- Inputs = append(Inputs, fmt.Sprint(fnTyp.In(i)))
|
|
|
+ Inputs[i] = DescType{fmt.Sprint(fnTyp.In(i)), ""}
|
|
|
+ e.Inputs = append(e.Inputs, fnTyp.In(i)) // ?
|
|
|
}
|
|
|
- Output := fmt.Sprint(fnTyp.Out(0))
|
|
|
- e.Output = fnTyp.Out(0)
|
|
|
+ Output := DescType{fmt.Sprint(fnTyp.Out(0)), ""}
|
|
|
+ e.Output = fnTyp.Out(0) // ?
|
|
|
|
|
|
e.Description = &Description{
|
|
|
- Tags: []string{"generic"},
|
|
|
- Inputs: Inputs,
|
|
|
- Output: Output,
|
|
|
- InputDesc: map[int]string{},
|
|
|
- Extra: map[string]interface{}{},
|
|
|
+ Tags: []string{"generic"},
|
|
|
+ Inputs: Inputs,
|
|
|
+ Output: Output,
|
|
|
+ Extra: map[string]interface{}{},
|
|
|
}
|
|
|
return e
|
|
|
}
|
|
@@ -67,6 +71,10 @@ func (e *Entry) Err() error {
|
|
|
return e.err
|
|
|
}
|
|
|
|
|
|
+/////////////
|
|
|
+// Descriptions
|
|
|
+/////
|
|
|
+
|
|
|
//Tags of the entry
|
|
|
func (e *Entry) Tags(cat ...string) *Entry {
|
|
|
if e.err != nil {
|
|
@@ -76,12 +84,18 @@ func (e *Entry) Tags(cat ...string) *Entry {
|
|
|
return e
|
|
|
}
|
|
|
|
|
|
-// DescInput description for Input
|
|
|
-func (e *Entry) DescInput(i int, desc string) *Entry {
|
|
|
+// DescInputs description for Inputs
|
|
|
+func (e *Entry) DescInputs(desc ...string) *Entry {
|
|
|
if e.err != nil {
|
|
|
return e
|
|
|
}
|
|
|
- e.Description.InputDesc[i] = desc
|
|
|
+ for i, d := range desc {
|
|
|
+ if i >= len(e.Description.Inputs) { // do nothing
|
|
|
+ return e
|
|
|
+ }
|
|
|
+ curDesc := e.Description.Inputs[i]
|
|
|
+ e.Description.Inputs[i] = DescType{curDesc.Type, d}
|
|
|
+ }
|
|
|
return e
|
|
|
}
|
|
|
|
|
@@ -90,7 +104,10 @@ func (e *Entry) DescOutput(desc string) *Entry {
|
|
|
if e.err != nil {
|
|
|
return e
|
|
|
}
|
|
|
- e.Description.OutputDesc = desc
|
|
|
+ e.Description.Output = DescType{
|
|
|
+ e.Description.Output.Type,
|
|
|
+ desc,
|
|
|
+ }
|
|
|
return e
|
|
|
}
|
|
|
|
|
@@ -102,22 +119,3 @@ func (e *Entry) Extra(name string, extra interface{}) *Entry {
|
|
|
e.Description.Extra[name] = extra
|
|
|
return e
|
|
|
}
|
|
|
-
|
|
|
-//Batch helper to batch set properties
|
|
|
-type Batch []*Entry
|
|
|
-
|
|
|
-//Tags set categories of the group
|
|
|
-func (eg Batch) Tags(cat ...string) Batch {
|
|
|
- for _, e := range eg {
|
|
|
- e.Tags(cat...)
|
|
|
- }
|
|
|
- return eg
|
|
|
-}
|
|
|
-
|
|
|
-// Extra set extras of the group
|
|
|
-func (eg Batch) Extra(name string, value interface{}) Batch {
|
|
|
- for _, e := range eg {
|
|
|
- e.Extra(name, value)
|
|
|
- }
|
|
|
- return eg
|
|
|
-}
|