diff --git a/internal/config/member.go b/internal/config/member.go index 2875c8f7..13c4261a 100644 --- a/internal/config/member.go +++ b/internal/config/member.go @@ -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") } diff --git a/internal/member/file/provider.go b/internal/member/file/provider.go index e6435051..4a9db72d 100644 --- a/internal/member/file/provider.go +++ b/internal/member/file/provider.go @@ -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) } diff --git a/internal/member/file/types.go b/internal/member/file/types.go index 4a79b652..32ed0b0e 100644 --- a/internal/member/file/types.go +++ b/internal/member/file/types.go @@ -10,5 +10,5 @@ type MemberEntry struct { } type Config struct { - File string + Path string } diff --git a/internal/member/manager.go b/internal/member/manager.go index 83f2851b..f52a417f 100644 --- a/internal/member/manager.go +++ b/internal/member/manager.go @@ -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: