You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
872 B
Go
59 lines
872 B
Go
5 years ago
|
package config
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
"path"
|
||
|
|
||
|
"github.com/fatih/structs"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
BTCQRCodesDir = "qrcodes"
|
||
|
)
|
||
|
|
||
|
type Config struct {
|
||
|
WebsitePath string
|
||
|
GithubAccessToken string
|
||
|
RelBitcoinAddrContentPath string
|
||
|
ApiPort int
|
||
|
}
|
||
|
|
||
|
var (
|
||
|
C *Config
|
||
|
)
|
||
|
|
||
|
func HugoData() string {
|
||
|
return path.Join(C.WebsitePath, "data")
|
||
|
}
|
||
|
|
||
|
func HugoContent() string {
|
||
|
return path.Join(C.WebsitePath, "content")
|
||
|
}
|
||
|
|
||
|
func RelBitcoinAddrContentPath() string {
|
||
|
return path.Join(C.WebsitePath, C.RelBitcoinAddrContentPath)
|
||
|
}
|
||
|
|
||
|
func RegisterConf(conf string, val interface{}) error {
|
||
|
log.Printf("Setting %#v to %#v", conf, val)
|
||
|
s := structs.New(C)
|
||
|
|
||
|
field, ok := s.FieldOk(conf)
|
||
|
|
||
|
// Conf option not registered in Config struct
|
||
|
if !ok {
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
err := field.Set(val)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func init() {
|
||
|
C = new(Config)
|
||
|
}
|