-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
41 lines (37 loc) · 874 Bytes
/
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
package main
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"io/ioutil"
"strings"
"time"
)
type Config struct {
AdminHash string `json:"admin_hash"`
ClientID string `json:"client_id"`
Secret string `json:"secret"`
CallbackURI string `json:"callback_uri"`
Timezone string `json:"timezone"`
Location *time.Location
}
func LoadConfig(path string) (*Config, error) {
contents, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
var res Config
if err := json.Unmarshal(contents, &res); err != nil {
return nil, err
}
res.Location, err = time.LoadLocation(res.Timezone)
if err != nil {
return nil, err
}
return &res, nil
}
func (c *Config) CheckPassword(pass string) bool {
hash := sha256.Sum256([]byte(pass))
readableHash := strings.ToLower(hex.EncodeToString(hash[:]))
return readableHash == c.AdminHash
}