44
src/internal/app/config/config.go
Normal file
44
src/internal/app/config/config.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"waterservice/internal/app/storage"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
Influx struct {
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
Token string `json:"token"`
|
||||
Org string `json:"org"`
|
||||
Bucket string `json:"bucket"`
|
||||
} `json:"influx"`
|
||||
}
|
||||
|
||||
var (
|
||||
logger log.Logger = *log.Default()
|
||||
store storage.Storage
|
||||
config_cache config
|
||||
)
|
||||
|
||||
func init() {
|
||||
logger.SetFlags(log.Llongfile | log.Ltime)
|
||||
}
|
||||
|
||||
func SetConfigFilePath(path string) {
|
||||
store.Path = path
|
||||
res, err := store.Read()
|
||||
if err != nil {
|
||||
logger.Print("unable to read config")
|
||||
return
|
||||
}
|
||||
err = json.Unmarshal(res, &config_cache)
|
||||
if err != nil {
|
||||
logger.Print("unable to unmarshal json to object")
|
||||
}
|
||||
}
|
||||
|
||||
func GetConfig() config {
|
||||
return config_cache
|
||||
}
|
Reference in New Issue
Block a user