Able to edit settings in interface
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
25b896c41d
commit
8df05d57c7
14 changed files with 538 additions and 2 deletions
53
sources/fields.go
Normal file
53
sources/fields.go
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package sources
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type SourceField struct {
|
||||
Id string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Label string `json:"label,omitempty"`
|
||||
Placeholder string `json:"placeholder,omitempty"`
|
||||
Default interface{} `json:"default,omitempty"`
|
||||
Required bool `json:"required,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
}
|
||||
|
||||
func GenFields(data interface{}) (fields []*SourceField) {
|
||||
if data != nil {
|
||||
dataMeta := reflect.Indirect(reflect.ValueOf(data)).Type()
|
||||
|
||||
for i := 0; i < dataMeta.NumField(); i += 1 {
|
||||
field := dataMeta.Field(i)
|
||||
if field.IsExported() {
|
||||
fields = append(fields, GenField(field))
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GenField(field reflect.StructField) (f *SourceField) {
|
||||
f = &SourceField{
|
||||
Id: field.Name,
|
||||
Type: field.Type.String(),
|
||||
Label: field.Tag.Get("label"),
|
||||
Placeholder: field.Tag.Get("placeholder"),
|
||||
Default: field.Tag.Get("default"),
|
||||
Description: field.Tag.Get("description"),
|
||||
}
|
||||
|
||||
jsonTag := field.Tag.Get("json")
|
||||
jsonTuples := strings.Split(jsonTag, ",")
|
||||
if len(jsonTuples) > 0 && len(jsonTuples[0]) > 0 {
|
||||
f.Id = jsonTuples[0]
|
||||
}
|
||||
|
||||
if f.Label == "" {
|
||||
f.Label = field.Name
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue