-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_config.go
55 lines (43 loc) · 1.15 KB
/
user_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package config
import (
"github.com/spf13/viper"
"github.com/yolo-sh/yolo/github"
)
type UserConfigKey string
const (
UserConfigKeyUserIsLoggedIn UserConfigKey = "user_is_logged_in"
UserConfigKeyGitHubAccessToken UserConfigKey = "github_access_token"
UserConfigKeyGitHubUsername UserConfigKey = "github_username"
UserConfigKeyGitHubEmail UserConfigKey = "github_email"
UserConfigKeyGitHubFullName UserConfigKey = "github_full_name"
)
type UserConfig struct{}
func NewUserConfig() UserConfig {
return UserConfig{}
}
func (UserConfig) GetString(key UserConfigKey) string {
return viper.GetString(string(key))
}
func (UserConfig) GetBool(key UserConfigKey) bool {
return viper.GetBool(string(key))
}
func (UserConfig) Set(key UserConfigKey, value interface{}) {
viper.Set(string(key), value)
}
func (u UserConfig) PopulateFromGitHubUser(githubUser *github.AuthenticatedUser) {
u.Set(
UserConfigKeyGitHubEmail,
githubUser.PrimaryEmail,
)
u.Set(
UserConfigKeyGitHubFullName,
githubUser.FullName,
)
u.Set(
UserConfigKeyGitHubUsername,
githubUser.Username,
)
}
func (UserConfig) WriteConfig() error {
return viper.WriteConfig()
}