feat: driver manage

This commit is contained in:
Noah Hsu
2022-06-07 18:13:55 +08:00
parent 84eb978731
commit 0d93a6aa41
10 changed files with 153 additions and 11 deletions

View File

@ -1,4 +1,13 @@
package driver
type Addition interface {
type Additional interface {
}
type Item struct {
Name string `json:"name"`
Type string `json:"type"`
Default string `json:"default"`
Values string `json:"values"`
Required bool `json:"required"`
Desc string `json:"desc"`
}

View File

@ -3,4 +3,6 @@ package driver
type Config struct {
Name string
LocalSort bool
OnlyLocal bool
OnlyProxy bool
}

View File

@ -6,9 +6,18 @@ import (
)
type Driver interface {
Other
Reader
Writer
Other
}
type Other interface {
Config() Config
Init(ctx context.Context, account model.Account) error
Update(ctx context.Context, account model.Account) error
Drop(ctx context.Context) error
// GetAccount transform additional field to string and assign to account's addition
GetAccount() model.Account
}
type Reader interface {
@ -25,12 +34,3 @@ type Writer interface {
Remove(ctx context.Context, path string) error
Put(ctx context.Context, stream FileStream, parentPath string) error
}
type Other interface {
Init(ctx context.Context, account model.Account) error
Update(ctx context.Context, account model.Account) error
Drop(ctx context.Context) error
// GetAccount transform additional field to string and assign to account's addition
GetAccount() model.Account
Config() Config
}

14
internal/driver/manage.go Normal file
View File

@ -0,0 +1,14 @@
package driver
import (
log "github.com/sirupsen/logrus"
)
type New func() Driver
var driversMap = map[string]New{}
func RegisterDriver(name string, new New) {
log.Infof("register driver: [%s]", name)
driversMap[name] = new
}

View File

@ -0,0 +1 @@
package operations

View File

@ -7,6 +7,7 @@ type Account struct {
Driver string `json:"driver"`
Status string `json:"status"`
Addition string `json:"addition"`
Remark string `json:"remark"`
Sort
Proxy
}