Skip to content

Commit

Permalink
feat: get type from field's type
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jun 8, 2022
1 parent ae755db commit ba648fa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion drivers/local/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
9 changes: 9 additions & 0 deletions internal/driver/addition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
9 changes: 7 additions & 2 deletions internal/driver/manage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package driver
import (
log "github.com/sirupsen/logrus"
"reflect"
"strings"
)

type New func() Driver
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit ba648fa

Please sign in to comment.