lib/app/root.go

60 lines
1.6 KiB
Go
Raw Normal View History

2021-01-10 18:16:20 +00:00
// Package app is a utility package
package app
import (
"strings"
2021-01-18 03:13:54 +00:00
"time"
2021-01-10 18:16:20 +00:00
2021-01-18 03:13:54 +00:00
"code.tnxs.net/taxnexus/lib/api/auth0/auth0_client"
2021-01-10 18:16:20 +00:00
"code.tnxs.net/taxnexus/lib/app/logger"
"github.com/spf13/viper"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var sugar *zap.SugaredLogger
2021-01-10 21:23:12 +00:00
var config = Configuration{}
2021-01-10 18:16:20 +00:00
var appViper = viper.New()
2021-01-18 03:13:54 +00:00
var auth0Client = auth0_client.Default
var configured = false
2021-01-10 18:16:20 +00:00
2021-01-18 03:13:54 +00:00
const getTimeout = 6 * time.Minute
const postTimeout = 6 * time.Minute
const constNotFound = "not found"
2021-01-14 06:36:35 +00:00
const dateFormat = "2006-01-02"
const dateTimeFormat = "2006-01-02T15:04:05-0800"
const dateTimeFormatAlt = "2006-01-02 15:04:05"
const dateFormatAlt = "1/2/2006"
2021-01-10 18:16:20 +00:00
// InitConfig exports the config initialization func
func InitConfig(systemName string) {
if configured {
return
}
sugar = logger.New(zapcore.InfoLevel)
sugar.Info("app.InitConfig: 📥 %s", systemName)
appViper.SetConfigType("yaml")
appViper.SetConfigName(systemName)
appViper.AddConfigPath("/etc/taxnexus")
appViper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
appViper.SetEnvPrefix("taxnexus")
appViper.AutomaticEnv() // read in environment variables that match
err := appViper.ReadInConfig()
if err != nil {
sugar.Fatalf("app.InitConfig: 💣 ⛔ can't read system config: %w", err)
}
err = appViper.Unmarshal(&config)
if err != nil {
sugar.Fatalf("app.InitConfig: 💣 ⛔ can't unmarshal system config: %w", err)
}
sugar = logger.New(GetLogLevel())
sugar.Debugf("app.InitConfig: 👍 📤 serviceAccounts: %d", len(config.ServiceAccounts))
configured = true
}
2021-01-18 03:13:54 +00:00
// FirstClassObject is a struct
type FirstClassObject interface {
Marshal() interface{}
UnMarshal() interface{}
}