package registry import ( "fmt" "reflect" ) //DescType type Description type DescType struct { Type string `json:"type"` Name string `json:"name"` } // Entry contains a function description params etc type Entry struct { registry *R fn interface{} Inputs []reflect.Type Output reflect.Type Description *Description err error } // NewEntry creates and describes a New Entry func NewEntry(r *R, fn interface{}) *Entry { e := &Entry{registry: r, fn: fn} fntyp := reflect.TypeOf(e.fn) if fntyp.Kind() != reflect.Func { e.err = ErrNotAFunc return e } if fntyp.NumOut() == 0 { e.err = ErrOutput return e } fnTyp := reflect.TypeOf(e.fn) nInputs := fnTyp.NumIn() Inputs := make([]DescType, nInputs) for i := 0; i < nInputs; i++ { Inputs[i] = DescType{fmt.Sprint(fnTyp.In(i)), ""} e.Inputs = append(e.Inputs, fnTyp.In(i)) // ? } Output := DescType{fmt.Sprint(fnTyp.Out(0)), ""} e.Output = fnTyp.Out(0) // ? e.Description = &Description{ Tags: []string{"generic"}, Inputs: Inputs, Output: Output, Extra: map[string]interface{}{}, } return e } // Describer return a description builder func (e *Entry) Describer() EDescriber { return Describer(e) } // Err returns error of the entry if any func (e *Entry) Err() error { return e.err }