Jobs & Workflows https://armen.surge.sh
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

67 lines
1.6 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### config ####### Copyright (c) 2021 mls-361 ################################################## MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package config
import (
"forge.chapril.org/mls-361/failure"
"forge.chapril.org/armen/armen/internal/components"
"forge.chapril.org/armen/armen/internal/config/data"
"forge.chapril.org/armen/armen/internal/config/json"
)
type config struct {
data *data.Data
}
func newConfig() *config {
return &config{
data: new(data.Data),
}
}
// Load AFAIRE.
func Load(app components.Application) (*config, error) {
cc := newConfig()
config, ok := app.LookupEnv("CONFIG")
if !ok {
cc.data.Default()
} else {
switch config {
case "json":
if err := json.LoadConfig(app, cc.data); err != nil {
return nil, err
}
default:
return nil, failure.New( ///////////////////////////////////////////////////////////////////////////////////
"this configuration mode is not valid",
"mode", config,
)
}
if err := cc.data.Validate(); err != nil {
return nil, err
}
}
return cc, nil
}
// Logger AFAIRE.
func (cc *config) Logger() *data.Logger {
return cc.data.Logger
}
// Server AFAIRE.
func (cc *config) Server() *data.Server {
return cc.data.Server
}
/*
######################################################################################################## @(°_°)@ #######
*/