environment-ize configuration

This commit is contained in:
2021-07-02 18:47:14 -04:00
parent 04506ed01f
commit ca618cc609
5 changed files with 36 additions and 4 deletions

View File

@@ -10,8 +10,17 @@ import (
"git.yetaga.in/alazyreader/library/book"
"git.yetaga.in/alazyreader/library/database"
"git.yetaga.in/alazyreader/library/frontend"
"github.com/kelseyhightower/envconfig"
)
type Config struct {
DBUser string
DBPass string
DBHost string
DBPort string
DBName string
}
type Library interface {
GetAllBooks(context.Context) ([]book.Book, error)
}
@@ -54,11 +63,19 @@ func StaticHandler(f fs.FS) http.Handler {
}
func main() {
var c Config
err := envconfig.Process("library", &c)
if err != nil {
log.Fatalln(err)
}
f, err := frontend.Root()
if err != nil {
log.Fatalln(err)
}
lib, err := database.NewMySQLConnection("root", "KigYBNCT9IU5XyB3ehzMLFWyI", "127.0.0.1", "3306", "library")
if c.DBUser == "" || c.DBPass == "" || c.DBHost == "" || c.DBPort == "" || c.DBName == "" {
log.Fatalf("vars: %+v", c)
}
lib, err := database.NewMySQLConnection(c.DBUser, c.DBPass, c.DBHost, c.DBPort, c.DBName)
if err != nil {
log.Fatalln(err)
}