neko/internal/config/member.go

55 lines
1.6 KiB
Go
Raw Normal View History

2021-03-14 13:08:50 +13:00
package config
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
2021-03-17 03:28:40 +13:00
"demodesk/neko/internal/member/file"
"demodesk/neko/internal/member/object"
2021-03-14 13:08:50 +13:00
)
type Member struct {
2021-03-17 03:24:58 +13:00
Provider string
2021-03-17 03:28:40 +13:00
// providers
File file.Config
Object object.Config
2021-03-14 13:08:50 +13:00
}
func (Member) Init(cmd *cobra.Command) error {
2021-03-17 03:24:58 +13:00
cmd.PersistentFlags().String("member.provider", "object", "choose member provider")
if err := viper.BindPFlag("member.provider", cmd.PersistentFlags().Lookup("member.provider")); err != nil {
2021-03-14 13:08:50 +13:00
return err
}
2021-03-17 03:24:58 +13:00
// file provider
cmd.PersistentFlags().String("member.file.path", "", "member file provider: storage path")
if err := viper.BindPFlag("member.file.path", cmd.PersistentFlags().Lookup("member.file.path")); err != nil {
2021-03-14 13:08:50 +13:00
return err
}
2021-03-17 03:24:58 +13:00
// object provider
cmd.PersistentFlags().String("member.object.user_password", "", "member object provider: user password")
if err := viper.BindPFlag("member.object.user_password", cmd.PersistentFlags().Lookup("member.object.user_password")); err != nil {
2021-03-14 13:08:50 +13:00
return err
}
2021-03-17 03:24:58 +13:00
cmd.PersistentFlags().String("member.object.admin_password", "", "member object provider: admin password")
if err := viper.BindPFlag("member.object.admin_password", cmd.PersistentFlags().Lookup("member.object.admin_password")); err != nil {
2021-03-14 13:08:50 +13:00
return err
}
return nil
}
func (s *Member) Set() {
2021-03-17 03:24:58 +13:00
s.Provider = viper.GetString("member.provider")
// file provider
2021-03-17 03:28:40 +13:00
s.File.Path = viper.GetString("member.file.path")
2021-03-17 03:24:58 +13:00
// object provider
2021-03-17 03:28:40 +13:00
s.Object.UserPassword = viper.GetString("member.object.user_password")
s.Object.AdminPassword = viper.GetString("member.object.admin_password")
2021-03-14 13:08:50 +13:00
}