-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.go
85 lines (74 loc) · 1.53 KB
/
settings.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
)
type Setting struct {
path string
HTTPPort int
HTTPAddress string
EnableSSH bool
SSHPort int
SSHAddress string
SSHHostKey string
SSHPublicKey string
GitRoot string
PathPrefix string
HttpAuth bool
SSHAuthType string
Credentials map[string]string
}
func (s *Setting) SetConfigPath(path string) {
s.path = path
}
func (s *Setting) GetHttpListenAddr() string {
return fmt.Sprintf("%s:%d", s.HTTPAddress, s.HTTPPort)
}
func (s *Setting) GetSSHListenAddr() string {
return fmt.Sprintf("%s:%d", s.SSHAddress, s.SSHPort)
}
func (s *Setting) Output() string {
out, err := json.MarshalIndent(s, "", " ")
if err != nil {
log.Panic(err)
}
return string(out)
}
func (s *Setting) Reload() error {
data, err := ioutil.ReadFile(s.path)
if err != nil {
return err
}
err = json.Unmarshal(data, &s)
if err != nil {
return err
}
return nil
}
var Settings *Setting
func init() {
workDir, _ := os.Getwd()
gitRoot := filepath.Join(workDir, "repo")
publicKey := filepath.Join(workDir, "repo", "key")
hostKey := filepath.Join(workDir, "repo", "hostkey")
Settings = &Setting{
GitRoot: gitRoot,
HTTPPort: 3011,
HTTPAddress: "0.0.0.0",
EnableSSH: true,
SSHPort: 3022,
SSHAddress: "0.0.0.0",
SSHHostKey: hostKey,
SSHPublicKey: publicKey,
PathPrefix: "repo",
HttpAuth: false,
SSHAuthType: "password",
Credentials: map[string]string{
"user": "password",
},
}
}