From 699e1edf05207f906583659fb250269ad5ec1f36 Mon Sep 17 00:00:00 2001 From: Alexander Kavon Date: Mon, 13 Nov 2023 23:30:18 -0500 Subject: scaffolding --- src/conf/conf.go | 35 +++++++++++++++++++++++++++++++++++ src/main.go | 19 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/conf/conf.go create mode 100644 src/main.go (limited to 'src') diff --git a/src/conf/conf.go b/src/conf/conf.go new file mode 100644 index 0000000..d135fcb --- /dev/null +++ b/src/conf/conf.go @@ -0,0 +1,35 @@ +package conf + +import ( + "log" + "os" + "github.com/BurntSushi/toml" +) + +type Conf struct { + DbAdapter string `toml:"DB_ADAPTER"` + DbUser string `toml:"DB_USER"` + DbPassword string `toml:"DB_PASS"` +} + +func Load() *Conf { + + filepath := os.Getenv("NEWSSTAND_CONFIG_PATH") + if filepath == "" { + workingdir, err := os.Getwd() + if err != nil { + log.Fatal(err) + } + filepath = workingdir + "/.newsstandrc.toml" + } + log.Printf("Config file path: %s", filepath) + + var c Conf + _, err := toml.DecodeFile(filepath, &c) + if err != nil { + log.Fatalln(err) + } + log.Println(c.DbAdapter) + + return &c +} diff --git a/src/main.go b/src/main.go new file mode 100644 index 0000000..3c2fe5e --- /dev/null +++ b/src/main.go @@ -0,0 +1,19 @@ +package main + +import ( + "net/http" + "gitlab.com/alexkavon/newsstand/conf" + "github.com/go-chi/chi/v5" + "github.com/go-chi/chi/v5/middleware" +) + +func main() { + // load config + conf.Load() + r := chi.NewRouter() + r.Use(middleware.Logger) + r.Get("/", func(w http.ResponseWriter, r *http.Request) { + w.Write([]byte("Yello There!")) + }) + http.ListenAndServe(":8080", r) +} -- cgit v1.2.3