Compare commits

..

2 Commits

Author SHA1 Message Date
fb2e8ff85f Merge branch 'feature/yaml' of meutel/go-bouquins into master
All checks were successful
continuous-integration/drone/push Build is passing
2019-09-12 12:43:31 +00:00
fc346dcfb5 Config yaml
All checks were successful
continuous-integration/drone/push Build is passing
2019-09-12 14:34:26 +02:00
5 changed files with 23 additions and 18 deletions

2
.gitignore vendored
View File

@ -2,7 +2,7 @@
*~ *~
go-bouquins go-bouquins
calibre.db calibre.db
bouquins.json bouquins.yml
Gopkg.lock Gopkg.lock
vendor/ vendor/
users.db users.db

View File

@ -70,24 +70,24 @@ var UnprotectedCalibreSuffix = [1]string{"jpg"}
// Conf App configuration // Conf App configuration
type Conf struct { type Conf struct {
BindAddress string `json:"bind-address"` BindAddress string `yaml:"bind-address"`
DbPath string `json:"db-path"` DbPath string `yaml:"db-path"`
CalibrePath string `json:"calibre-path"` CalibrePath string `yaml:"calibre-path"`
Prod bool `json:"prod"` Prod bool `yaml:"prod"`
UserDbPath string `json:"user-db-path"` UserDbPath string `yaml:"user-db-path"`
CookieSecret string `json:"cookie-secret"` CookieSecret string `yaml:"cookie-secret"`
ExternalURL string `json:"external-url"` ExternalURL string `yaml:"external-url"`
ProvidersConf []ProviderConf `json:"providers"` ProvidersConf []ProviderConf `yaml:"providers"`
} }
// ProviderConf OAuth2 provider configuration // ProviderConf OAuth2 provider configuration
type ProviderConf struct { type ProviderConf struct {
Name string `json:"name"` Name string `yaml:"name"`
ClientID string `json:"client-id"` ClientID string `yaml:"client-id"`
ClientSecret string `json:"client-secret"` ClientSecret string `yaml:"client-secret"`
AuthURL string `json:"auth-url"` AuthURL string `yaml:"auth-url"`
TokenURL string `json:"token-url"` TokenURL string `yaml:"token-url"`
ProfileURL string `json:"profile-url"` ProfileURL string `yaml:"profile-url"`
} }
// Bouquins contains application common resources: templates, database // Bouquins contains application common resources: templates, database

1
go.mod
View File

@ -9,4 +9,5 @@ require (
golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac // indirect golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac // indirect
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
golang.org/x/tools v0.0.0-20190911022129-16c5e0f7d110 // indirect golang.org/x/tools v0.0.0-20190911022129-16c5e0f7d110 // indirect
gopkg.in/yaml.v2 v2.2.2
) )

4
go.sum
View File

@ -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/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= 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= 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=

View File

@ -2,7 +2,7 @@ package main
import ( import (
"database/sql" "database/sql"
"encoding/json" "gopkg.in/yaml.v2"
"log" "log"
"net/http" "net/http"
"os" "os"
@ -18,14 +18,14 @@ import (
// ReadConfig loads configuration file and initialize default value // ReadConfig loads configuration file and initialize default value
func ReadConfig() (*bouquins.Conf, error) { func ReadConfig() (*bouquins.Conf, error) {
conf := new(bouquins.Conf) conf := new(bouquins.Conf)
confPath := "bouquins.json" confPath := "bouquins.yml"
if len(os.Args) > 1 { if len(os.Args) > 1 {
confPath = os.Args[1] confPath = os.Args[1]
} }
confFile, err := os.Open(confPath) confFile, err := os.Open(confPath)
if err == nil { if err == nil {
defer confFile.Close() defer confFile.Close()
err = json.NewDecoder(confFile).Decode(conf) err = yaml.NewDecoder(confFile).Decode(conf)
} else { } else {
log.Println("no conf file, using defaults") log.Println("no conf file, using defaults")
err = nil err = nil