mirror of https://github.com/Xhofe/alist
feat: get type from field's type
parent
ae755db2d2
commit
ba648fa10c
|
@ -3,7 +3,7 @@ package local
|
|||
import "github.com/alist-org/alist/v3/internal/driver"
|
||||
|
||||
type Addition struct {
|
||||
RootFolder string `json:"root_folder" type:"string" help:"root folder path" default:"/"`
|
||||
RootFolder string `json:"root_folder" help:"root folder path" default:"/"`
|
||||
}
|
||||
|
||||
var config = driver.Config{
|
||||
|
|
|
@ -2,6 +2,15 @@ package driver
|
|||
|
||||
type Additional interface{}
|
||||
|
||||
type Select string
|
||||
|
||||
const (
|
||||
TypeString = "string"
|
||||
TypeSelect = "select"
|
||||
TypeBool = "bool"
|
||||
TypeText = "text"
|
||||
)
|
||||
|
||||
type Item struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
|
|
|
@ -3,6 +3,7 @@ package driver
|
|||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type New func() Driver
|
||||
|
@ -73,19 +74,23 @@ func getMainItems(config Config) []Item {
|
|||
func getAdditionalItems(t reflect.Type) []Item {
|
||||
var items []Item
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
tag := t.Field(i).Tag
|
||||
field := t.Field(i)
|
||||
tag := field.Tag
|
||||
ignore, ok := tag.Lookup("ignore")
|
||||
if !ok || ignore == "false" {
|
||||
continue
|
||||
}
|
||||
item := Item{
|
||||
Name: tag.Get("json"),
|
||||
Type: tag.Get("type"),
|
||||
Type: strings.ToLower(field.Name),
|
||||
Default: tag.Get("default"),
|
||||
Values: tag.Get("values"),
|
||||
Required: tag.Get("required") == "true",
|
||||
Help: tag.Get("help"),
|
||||
}
|
||||
if tag.Get("type") != "" {
|
||||
item.Type = tag.Get("type")
|
||||
}
|
||||
// set default type to string
|
||||
if item.Type == "" {
|
||||
item.Type = "string"
|
||||
|
|
Loading…
Reference in New Issue