Skip to content

Commit

Permalink
chore: set default root folder in driver config
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jul 19, 2022
1 parent 184b9d1 commit fe94016
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
9 changes: 5 additions & 4 deletions drivers/local/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ type Addition struct {
}

var config = driver.Config{
Name: "Local",
OnlyLocal: true,
LocalSort: true,
NoCache: true,
Name: "Local",
OnlyLocal: true,
LocalSort: true,
NoCache: true,
DefaultRoot: "/",
}

func New() driver.Driver {
Expand Down
4 changes: 2 additions & 2 deletions internal/driver/addition.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ type IRootFolderId interface {
}

type RootFolderPath struct {
RootFolder string `json:"root_folder" help:"root folder path" default:"/"`
RootFolder string `json:"root_folder" required:"true" help:"root folder path"`
}

type RootFolderId struct {
RootFolder string `json:"root_folder" help:"root folder id"`
RootFolder string `json:"root_folder" required:"true" help:"root folder id"`
}

func (r RootFolderPath) GetRootFolderPath() string {
Expand Down
13 changes: 7 additions & 6 deletions internal/driver/config.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package driver

type Config struct {
Name string
LocalSort bool
OnlyLocal bool
OnlyProxy bool
NoCache bool
NoUpload bool
Name string
LocalSort bool
OnlyLocal bool
OnlyProxy bool
NoCache bool
NoUpload bool
DefaultRoot string
}

func (c Config) MustProxy() bool {
Expand Down
9 changes: 6 additions & 3 deletions internal/operations/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func registerDriverItems(config driver.Config, addition driver.Additional) {
log.Debugf("addition of %s: %+v", config.Name, addition)
tAddition := reflect.TypeOf(addition)
mainItems := getMainItems(config)
additionalItems := getAdditionalItems(tAddition)
additionalItems := getAdditionalItems(tAddition, config.DefaultRoot)
driverItemsMap[config.Name] = driver.Items{
Main: mainItems,
Additional: additionalItems,
Expand Down Expand Up @@ -109,12 +109,12 @@ func getMainItems(config driver.Config) []driver.Item {
return items
}

func getAdditionalItems(t reflect.Type) []driver.Item {
func getAdditionalItems(t reflect.Type, defaultRoot string) []driver.Item {
var items []driver.Item
for i := 0; i < t.NumField(); i++ {
field := t.Field(i)
if field.Type.Kind() == reflect.Struct {
items = append(items, getAdditionalItems(field.Type)...)
items = append(items, getAdditionalItems(field.Type, defaultRoot)...)
continue
}
tag := field.Tag
Expand All @@ -133,6 +133,9 @@ func getAdditionalItems(t reflect.Type) []driver.Item {
if tag.Get("type") != "" {
item.Type = tag.Get("type")
}
if item.Name == "root_folder" && item.Default == "" {
item.Default = defaultRoot
}
// set default type to string
if item.Type == "" {
item.Type = "string"
Expand Down

0 comments on commit fe94016

Please sign in to comment.