feat: add driver config in driver info
This commit is contained in:
@ -1,13 +1,14 @@
|
||||
package driver
|
||||
|
||||
type Config struct {
|
||||
Name string
|
||||
LocalSort bool
|
||||
OnlyLocal bool
|
||||
OnlyProxy bool
|
||||
NoCache bool
|
||||
NoUpload bool
|
||||
DefaultRoot string
|
||||
Name string `json:"name"`
|
||||
LocalSort bool `json:"local_sort"`
|
||||
OnlyLocal bool `json:"only_local"`
|
||||
OnlyProxy bool `json:"only_proxy"`
|
||||
NoCache bool `json:"no_cache"`
|
||||
NoUpload bool `json:"no_upload"`
|
||||
NeedMs bool `json:"need_ms"` // if need get message from user, such as validate code
|
||||
DefaultRoot string `json:"default_root"`
|
||||
}
|
||||
|
||||
func (c Config) MustProxy() bool {
|
||||
|
@ -13,9 +13,10 @@ type Item struct {
|
||||
Help string `json:"help"`
|
||||
}
|
||||
|
||||
type Items struct {
|
||||
type Info struct {
|
||||
Common []Item `json:"common"`
|
||||
Additional []Item `json:"additional"`
|
||||
Config Config `json:"config"`
|
||||
}
|
||||
|
||||
type IRootFolderPath interface {
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
type New func() driver.Driver
|
||||
|
||||
var driverNewMap = map[string]New{}
|
||||
var driverItemsMap = map[string]driver.Items{}
|
||||
var driverInfoMap = map[string]driver.Info{}
|
||||
|
||||
func RegisterDriver(config driver.Config, driver New) {
|
||||
// log.Infof("register driver: [%s]", config.Name)
|
||||
@ -31,14 +31,14 @@ func GetDriverNew(name string) (New, error) {
|
||||
|
||||
func GetDriverNames() []string {
|
||||
var driverNames []string
|
||||
for k := range driverItemsMap {
|
||||
for k := range driverInfoMap {
|
||||
driverNames = append(driverNames, k)
|
||||
}
|
||||
return driverNames
|
||||
}
|
||||
|
||||
func GetDriverItemsMap() map[string]driver.Items {
|
||||
return driverItemsMap
|
||||
func GetDriverInfoMap() map[string]driver.Info {
|
||||
return driverInfoMap
|
||||
}
|
||||
|
||||
func registerDriverItems(config driver.Config, addition driver.Additional) {
|
||||
@ -46,9 +46,10 @@ func registerDriverItems(config driver.Config, addition driver.Additional) {
|
||||
tAddition := reflect.TypeOf(addition)
|
||||
mainItems := getMainItems(config)
|
||||
additionalItems := getAdditionalItems(tAddition, config.DefaultRoot)
|
||||
driverItemsMap[config.Name] = driver.Items{
|
||||
driverInfoMap[config.Name] = driver.Info{
|
||||
Common: mainItems,
|
||||
Additional: additionalItems,
|
||||
Config: config,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,10 +8,10 @@ import (
|
||||
)
|
||||
|
||||
func TestDriverItemsMap(t *testing.T) {
|
||||
itemsMap := operations.GetDriverItemsMap()
|
||||
itemsMap := operations.GetDriverInfoMap()
|
||||
if len(itemsMap) != 0 {
|
||||
t.Logf("driverItemsMap: %v", itemsMap)
|
||||
t.Logf("driverInfoMap: %v", itemsMap)
|
||||
} else {
|
||||
t.Errorf("expected driverItemsMap not empty, but got empty")
|
||||
t.Errorf("expected driverInfoMap not empty, but got empty")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user