First commit, nothing here really
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"gopkg.in/yaml.v2"
|
||||
"log"
|
||||
"os"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Configuration struct {
|
||||
AssetsDir string `yaml:"assets"`
|
||||
}
|
||||
|
||||
var (
|
||||
instance *Configuration
|
||||
once sync.Once
|
||||
confPath string
|
||||
)
|
||||
|
||||
func GetInstance() *Configuration {
|
||||
once.Do(func() {
|
||||
instance = &Configuration{}
|
||||
instance.loadConfiguration()
|
||||
})
|
||||
|
||||
return instance
|
||||
}
|
||||
|
||||
func SetConfig(path string) {
|
||||
confPath = path
|
||||
}
|
||||
|
||||
func (c *Configuration) loadConfiguration() {
|
||||
file, err := os.ReadFile(confPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to open configuration file [%s]: %s", confPath,
|
||||
err.Error())
|
||||
}
|
||||
|
||||
err = yaml.Unmarshal(file, &instance)
|
||||
if err != nil {
|
||||
log.Fatalf("Error parsing JSON: %s", err.Error())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user