init: Initial commit
This commit is contained in:
60
app/config/file.go
Normal file
60
app/config/file.go
Normal file
@@ -0,0 +1,60 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user