-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtypes.go
50 lines (42 loc) · 1.12 KB
/
types.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
package jumper
import (
"encoding/base64"
)
type Config struct {
Current Current `json:"current"`
Repos []Repo `json:"repos"`
}
type Repo struct {
Url string `json:"url"`
Name string `json:"name"`
Username string `json:"username"`
// UsernameStr is plaintext
UsernameStr string `json:"-"`
Password string `json:"password"`
// PasswordStr is plaintext
PasswordStr string `json:"-"`
}
func (repo *Repo) SetUsernamePassword(username, password string) {
repo.UsernameStr = username
repo.PasswordStr = password
repo.Username = base64.StdEncoding.EncodeToString([]byte(repo.UsernameStr))
repo.Password = base64.StdEncoding.EncodeToString([]byte(repo.PasswordStr))
}
func (repo Repo) GetUsernamePassword() (string, string, error) {
if repo.Username == "" {
return "", "", nil
}
username, err := base64.StdEncoding.DecodeString(repo.Username)
if err != nil {
return "", "", err
}
password, err := base64.StdEncoding.DecodeString(repo.Password)
if err != nil {
return "", "", err
}
return string(username), string(password), nil
}
type Current struct {
// Repo is current repo name
Repo string
}