2025-04-24 13:58:05 -05:00
|
|
|
package configserver
|
|
|
|
|
|
|
|
import (
|
2025-04-27 23:14:37 -05:00
|
|
|
"fmt"
|
2025-04-24 13:58:05 -05:00
|
|
|
"io"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/pelletier/go-toml/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AppConfig struct {
|
|
|
|
API struct {
|
|
|
|
Domain string
|
|
|
|
Port string
|
|
|
|
Https bool
|
|
|
|
}
|
2025-04-27 23:14:37 -05:00
|
|
|
Frontend struct {
|
|
|
|
Domain string
|
|
|
|
Port string
|
|
|
|
Https bool
|
|
|
|
}
|
2025-04-24 13:58:05 -05:00
|
|
|
OAuth struct {
|
|
|
|
ClientID string
|
|
|
|
ClientSecret string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-04-27 23:14:37 -05:00
|
|
|
func (config AppConfig) GetAPIRootDomain() string {
|
|
|
|
protocol := "http://"
|
|
|
|
if config.API.Https {
|
|
|
|
protocol = "https://"
|
|
|
|
}
|
|
|
|
log.Println(config.API)
|
|
|
|
return fmt.Sprintf("%s%s:%s/", protocol, config.API.Domain, config.API.Port)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (config AppConfig) GetFrontendRootDomain() string {
|
|
|
|
protocol := "http://"
|
|
|
|
if config.Frontend.Https {
|
|
|
|
protocol = "https://"
|
|
|
|
}
|
|
|
|
log.Println(config.Frontend)
|
|
|
|
return fmt.Sprintf("%s%s:%s/", protocol, config.Frontend.Domain, config.Frontend.Port)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (config *AppConfig) ParseConfig(configPath string) {
|
2025-04-24 13:58:05 -05:00
|
|
|
configFile, err := os.Open(configPath)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
configFileContent, err := io.ReadAll(configFile)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2025-04-27 23:14:37 -05:00
|
|
|
err = toml.Unmarshal(configFileContent, &config)
|
2025-04-24 13:58:05 -05:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|