Onyx-API/internal/config/config.go

33 lines
535 B
Go
Raw Normal View History

2023-09-15 18:21:04 +02:00
package config
import (
"github.com/joho/godotenv"
"github.com/mitchellh/mapstructure"
)
type Config struct {
AppPortListen string `mapstructure:"APP_PORT"`
JwtKey []byte
}
func LoadConfig(filename ...string) (*Config, error) {
var myenv map[string]string
var err error
var c Config
if len(filename) == 0 {
myenv, err = godotenv.Read()
} else {
myenv, err = godotenv.Read(filename[0])
}
if err != nil {
return nil, err
}
mapstructure.Decode(myenv, &c)
c.JwtKey = []byte(c.StringKey)
return &c, nil
}