Files
api-gateway/app/config/file.go
Björn Benouarets 31f5b4081a init: Initial commit
2026-02-05 18:37:35 +01:00

61 lines
1.1 KiB
Go

package config
import (
"os"
"go.yaml.in/yaml/v3"
)
type FileConfig struct {
filePath string
config *Configuration
}
func NewFileConfig(filePath string) (*FileConfig, error) {
c := &FileConfig{filePath: filePath, config: &Configuration{}}
if err := c.loadConfig(); err != nil {
return nil, err
}
return c, nil
}
func (c *FileConfig) loadConfig() error {
data, err := os.ReadFile(c.filePath)
if err != nil {
return err
}
return yaml.Unmarshal(data, c.config)
}
func (c *FileConfig) GetConfiguration() *Configuration {
return c.config
}
func (c *FileConfig) GetGatewayConfiguration() *GatewayConfiguration {
return &c.config.Gateway
}
func (c *FileConfig) GetRoutes() []RouteConfiguration {
return c.config.Routes
}
func (c *FileConfig) GetProxies() []ProxyConfiguration {
return c.config.Proxies
}
func (c *FileConfig) GetHost() string {
return c.config.Gateway.Host
}
func (c *FileConfig) GetPort() int {
return c.config.Gateway.Port
}
func (c *FileConfig) GetApis() []ApiConfiguration {
return c.config.Apis
}
func (c *FileConfig) GetFeatures() []string {
return c.config.Gateway.Features
}