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