Config yaml #3
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,7 +2,7 @@
|
||||
*~
|
||||
go-bouquins
|
||||
calibre.db
|
||||
bouquins.json
|
||||
bouquins.yml
|
||||
Gopkg.lock
|
||||
vendor/
|
||||
users.db
|
||||
|
@ -70,24 +70,24 @@ var UnprotectedCalibreSuffix = [1]string{"jpg"}
|
||||
|
||||
// Conf App configuration
|
||||
type Conf struct {
|
||||
BindAddress string `json:"bind-address"`
|
||||
DbPath string `json:"db-path"`
|
||||
CalibrePath string `json:"calibre-path"`
|
||||
Prod bool `json:"prod"`
|
||||
UserDbPath string `json:"user-db-path"`
|
||||
CookieSecret string `json:"cookie-secret"`
|
||||
ExternalURL string `json:"external-url"`
|
||||
ProvidersConf []ProviderConf `json:"providers"`
|
||||
BindAddress string `yaml:"bind-address"`
|
||||
DbPath string `yaml:"db-path"`
|
||||
CalibrePath string `yaml:"calibre-path"`
|
||||
Prod bool `yaml:"prod"`
|
||||
UserDbPath string `yaml:"user-db-path"`
|
||||
CookieSecret string `yaml:"cookie-secret"`
|
||||
ExternalURL string `yaml:"external-url"`
|
||||
ProvidersConf []ProviderConf `yaml:"providers"`
|
||||
}
|
||||
|
||||
// ProviderConf OAuth2 provider configuration
|
||||
type ProviderConf struct {
|
||||
Name string `json:"name"`
|
||||
ClientID string `json:"client-id"`
|
||||
ClientSecret string `json:"client-secret"`
|
||||
AuthURL string `json:"auth-url"`
|
||||
TokenURL string `json:"token-url"`
|
||||
ProfileURL string `json:"profile-url"`
|
||||
Name string `yaml:"name"`
|
||||
ClientID string `yaml:"client-id"`
|
||||
ClientSecret string `yaml:"client-secret"`
|
||||
AuthURL string `yaml:"auth-url"`
|
||||
TokenURL string `yaml:"token-url"`
|
||||
ProfileURL string `yaml:"profile-url"`
|
||||
}
|
||||
|
||||
// Bouquins contains application common resources: templates, database
|
||||
|
1
go.mod
1
go.mod
@ -9,4 +9,5 @@ require (
|
||||
golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac // indirect
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
|
||||
golang.org/x/tools v0.0.0-20190911022129-16c5e0f7d110 // indirect
|
||||
gopkg.in/yaml.v2 v2.2.2
|
||||
)
|
||||
|
4
go.sum
4
go.sum
@ -30,3 +30,7 @@ golang.org/x/tools v0.0.0-20190911022129-16c5e0f7d110 h1:6S6bidS7O4yAwA5ORRbRIjv
|
||||
golang.org/x/tools v0.0.0-20190911022129-16c5e0f7d110/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
6
main.go
6
main.go
@ -2,7 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"gopkg.in/yaml.v2"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -18,14 +18,14 @@ import (
|
||||
// ReadConfig loads configuration file and initialize default value
|
||||
func ReadConfig() (*bouquins.Conf, error) {
|
||||
conf := new(bouquins.Conf)
|
||||
confPath := "bouquins.json"
|
||||
confPath := "bouquins.yml"
|
||||
if len(os.Args) > 1 {
|
||||
confPath = os.Args[1]
|
||||
}
|
||||
confFile, err := os.Open(confPath)
|
||||
if err == nil {
|
||||
defer confFile.Close()
|
||||
err = json.NewDecoder(confFile).Decode(conf)
|
||||
err = yaml.NewDecoder(confFile).Decode(conf)
|
||||
} else {
|
||||
log.Println("no conf file, using defaults")
|
||||
err = nil
|
||||
|
Loading…
Reference in New Issue
Block a user