basic backend and frontend communication done

This commit is contained in:
2021-08-29 15:06:00 -04:00
parent b9ee7d0790
commit 542c6e32c8
11 changed files with 209 additions and 2658 deletions

View File

@@ -2,12 +2,31 @@ package main
import (
"os"
"path/filepath"
"time"
"github.com/kkyr/fig"
"github.com/rs/zerolog"
)
var defaultConfig = `# All values in this config file WILL BE overwritten by ENV variables (GI_SERVER_PORT for example) if they exist.
Server:
port: 3500
locationPhotoDir: "./app/photos/locations/"
Logger:
loglevel: "debug" # debug/info/warn/error
loggingFile: "./app/log/goInventorize.log"
Authentication:
BasicAuth: true
UserName: "admin"
Password: "password"
TZ: "America/New_York" # For goinventorize TZ, TZ in UNDERLYING docker image (scratch) is not set
Development: false
`
type Config struct {
Timezone string `fig:"tz" default:"America/New_York"`
Server struct {
@@ -29,10 +48,34 @@ type Config struct {
func LoadConfig(s *Server) error {
var cfg Config
err := fig.Load(&cfg, fig.File("config.yaml"), fig.Dirs("./app/config"), fig.UseEnv("GI")) // Load in config.yaml, then overwrite with ENV variables prefixed with GI
// Create our app folder structure in case it does not exist
err := os.MkdirAll("./app/config", 0755)
if err != nil {
return err
}
err = os.MkdirAll("./app/database", 0755)
if err != nil {
return err
}
// If config file not exist, create it
if _, err := os.Stat("./app/config/config.yaml"); os.IsNotExist(err) {
// Write our config to a file
err := os.WriteFile("./app/config/config.yaml", []byte(defaultConfig), 0755)
if err != nil {
return err
}
}
err = fig.Load(&cfg, fig.File("config.yaml"), fig.Dirs("./app/config"), fig.UseEnv("GI")) // Load in config.yaml, then overwrite with ENV variables prefixed with GI
if err != nil {
return err
}
// Create our logging dir
err = os.MkdirAll(filepath.Dir(cfg.Logger.LoggingFile), 0755)
if err != nil {
return err
}
// Create our logging file
logFile, err := os.OpenFile(cfg.Logger.LoggingFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) // Open/Create log file for writting to log
if err != nil {
return err