mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
members: direct providers config.
This commit is contained in:
parent
524d895db8
commit
0233daf125
@ -3,17 +3,17 @@ package config
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"demodesk/neko/internal/member/file"
|
||||
"demodesk/neko/internal/member/object"
|
||||
)
|
||||
|
||||
type Member struct {
|
||||
Provider string
|
||||
|
||||
// file provider
|
||||
FilePath string
|
||||
|
||||
// object provider
|
||||
ObjectUserPassword string
|
||||
ObjectAdminPassword string
|
||||
// providers
|
||||
File file.Config
|
||||
Object object.Config
|
||||
}
|
||||
|
||||
func (Member) Init(cmd *cobra.Command) error {
|
||||
@ -46,9 +46,9 @@ func (s *Member) Set() {
|
||||
s.Provider = viper.GetString("member.provider")
|
||||
|
||||
// file provider
|
||||
s.FilePath = viper.GetString("member.file.path")
|
||||
s.File.Path = viper.GetString("member.file.path")
|
||||
|
||||
// object provider
|
||||
s.ObjectUserPassword = viper.GetString("member.object.user_password")
|
||||
s.ObjectAdminPassword = viper.GetString("member.object.admin_password")
|
||||
s.Object.UserPassword = viper.GetString("member.object.user_password")
|
||||
s.Object.AdminPassword = viper.GetString("member.object.admin_password")
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ func (provider *MemberProviderCtx) Delete(id string) error {
|
||||
}
|
||||
|
||||
func (provider *MemberProviderCtx) deserialize() (map[string]MemberEntry, error) {
|
||||
file, err := os.OpenFile(provider.config.File, os.O_RDONLY|os.O_CREATE, os.ModePerm)
|
||||
file, err := os.OpenFile(provider.config.Path, os.O_RDONLY|os.O_CREATE, os.ModePerm)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -190,5 +190,5 @@ func (provider *MemberProviderCtx) serialize(data map[string]MemberEntry) error
|
||||
return err
|
||||
}
|
||||
|
||||
return ioutil.WriteFile(provider.config.File, raw, os.ModePerm)
|
||||
return ioutil.WriteFile(provider.config.Path, raw, os.ModePerm)
|
||||
}
|
||||
|
@ -10,5 +10,5 @@ type MemberEntry struct {
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
File string
|
||||
Path string
|
||||
}
|
||||
|
@ -23,14 +23,9 @@ func New(sessions types.SessionManager, config *config.Member) *MemberManagerCtx
|
||||
|
||||
switch config.Provider {
|
||||
case "file":
|
||||
manager.provider = file.New(file.Config{
|
||||
File: config.FilePath,
|
||||
})
|
||||
manager.provider = file.New(config.File)
|
||||
case "object":
|
||||
manager.provider = object.New(object.Config{
|
||||
AdminPassword: config.ObjectAdminPassword,
|
||||
UserPassword: config.ObjectUserPassword,
|
||||
})
|
||||
manager.provider = object.New(config.Object)
|
||||
case "dummy":
|
||||
fallthrough
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user