39 lines
598 B
Go
39 lines
598 B
Go
![]() |
package configserver
|
||
|
|
||
|
import (
|
||
|
"io"
|
||
|
"log"
|
||
|
"os"
|
||
|
|
||
|
"github.com/pelletier/go-toml/v2"
|
||
|
)
|
||
|
|
||
|
type AppConfig struct {
|
||
|
API struct {
|
||
|
Domain string
|
||
|
Port string
|
||
|
Https bool
|
||
|
}
|
||
|
OAuth struct {
|
||
|
ClientID string
|
||
|
ClientSecret string
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func ParseConfig(configPath string) AppConfig {
|
||
|
configFile, err := os.Open(configPath)
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
configFileContent, err := io.ReadAll(configFile)
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
var configObject AppConfig
|
||
|
err = toml.Unmarshal(configFileContent, &configObject)
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
return configObject
|
||
|
}
|