genofire/hs_monolith
genofire
/
hs_monolith
Archived
1
0
Fork 0
This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
hs_monolith/models/config.go

68 lines
2.1 KiB
Go
Raw Normal View History

2017-05-03 07:30:18 +02:00
// Package with the mostly static content (models) of this microservice
2017-03-25 16:09:17 +01:00
package models
import (
"io/ioutil"
"github.com/BurntSushi/toml"
2017-03-30 16:09:44 +02:00
"github.com/genofire/hs_master-kss-monolith/lib/database"
2017-03-30 17:02:20 +02:00
"github.com/genofire/hs_master-kss-monolith/lib/log"
2017-03-25 16:09:17 +01:00
)
2017-05-15 10:22:24 +02:00
// Config file for this daemon (more information at the config_example.conf in this git repository)
2017-03-25 16:09:17 +01:00
type Config struct {
2017-05-03 07:30:18 +02:00
// address under which the api and static content of the webserver runs
WebserverBind string `toml:"webserver_bind"`
2017-04-28 10:27:36 +02:00
// path to deliver static content
Webroot string `toml:"webroot"`
2017-04-28 10:27:36 +02:00
Database database.Config `toml:"database"`
GoodRelease GoodReleaseConfig `toml:"good_release"`
CacheClean CacheWorkerConfig `toml:"cache_clean"`
2017-04-28 10:27:36 +02:00
// path to the SVG image templates to show the availability and freshness
2017-05-15 10:22:24 +02:00
// of a given good with a traffic light food labeling system
GoodAvailabilityTemplate string `toml:"good_availablity_template"`
GoodFreshnessTemplate string `toml:"good_freshness_template"`
2017-04-28 10:27:36 +02:00
FouledDeleter Duration `toml:"fouled_deleted"`
2017-05-18 23:42:00 +02:00
// URLs to other microservices, which this service uses
MicroserviceDependencies struct {
Product string `toml:"product"`
Permission string `toml:"permission"`
} `toml:"microservice_dependencies"`
2017-03-25 16:09:17 +01:00
}
2017-05-03 07:30:18 +02:00
// Configuration of the Worker to clean the cache from values of other microservice
type CacheWorkerConfig struct {
2017-05-03 07:30:18 +02:00
// Run Worker every Duration
Every Duration
2017-05-03 07:30:18 +02:00
// Remove cache, which is not used since Duration
After Duration
}
2017-05-03 07:30:18 +02:00
// Configuration of the Worker to release locked goods after a time period
type GoodReleaseConfig struct {
2017-05-03 07:30:18 +02:00
// Run worker every Duration
Every Duration `toml:"every"`
// Unlock those, which are not used since Duration
2017-04-28 10:27:36 +02:00
After Duration `toml:"after"`
}
2017-05-15 10:22:24 +02:00
// Function that reads a config model from a given path of a .yml file
2017-03-25 16:09:17 +01:00
func ReadConfigFile(path string) *Config {
config := &Config{}
file, err := ioutil.ReadFile(path)
if err != nil {
2017-03-30 16:09:44 +02:00
log.Log.Panic(err)
2017-03-25 16:09:17 +01:00
}
if err := toml.Unmarshal(file, config); err != nil {
2017-03-30 16:09:44 +02:00
log.Log.Panic(err)
2017-03-25 16:09:17 +01:00
}
return config
}