init: Initial commit
This commit is contained in:
11
app/config/config.go
Normal file
11
app/config/config.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package config
|
||||
|
||||
type Config interface {
|
||||
GetConfiguration() *Configuration
|
||||
GetGatewayConfiguration() *GatewayConfiguration
|
||||
GetFeatures() []string
|
||||
GetRoutes() []RouteConfiguration
|
||||
GetApis() []ApiConfiguration
|
||||
GetHost() string
|
||||
GetPort() int
|
||||
}
|
||||
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
|
||||
}
|
||||
57
app/config/types.go
Normal file
57
app/config/types.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package config
|
||||
|
||||
type Configuration struct {
|
||||
Gateway GatewayConfiguration `yaml:"gateway"`
|
||||
Apis []ApiConfiguration `yaml:"apis"`
|
||||
Routes []RouteConfiguration `yaml:"routes"`
|
||||
Proxies []ProxyConfiguration `yaml:"proxies"`
|
||||
}
|
||||
|
||||
type GatewayConfiguration struct {
|
||||
Host string `yaml:"host"`
|
||||
Port int `yaml:"port"`
|
||||
Features []string `yaml:"features"`
|
||||
}
|
||||
|
||||
type RouteConfiguration struct {
|
||||
ID string `yaml:"id"`
|
||||
Path string `yaml:"path"`
|
||||
StripPrefix struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Prefix string `yaml:"prefix"`
|
||||
} `yaml:"strip_prefix"`
|
||||
Security SecurityConfiguration `yaml:"security"`
|
||||
}
|
||||
|
||||
type SecurityConfiguration struct {
|
||||
Auth AuthConfiguration `yaml:"auth"`
|
||||
WAF WAFConfiguration `yaml:"waf"`
|
||||
}
|
||||
|
||||
type WAFConfiguration struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Methods []string `yaml:"methods"`
|
||||
}
|
||||
|
||||
type AuthConfiguration struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Type string `yaml:"type"`
|
||||
Header string `yaml:"header"`
|
||||
Path AuthPathConfiguration `yaml:"path"`
|
||||
}
|
||||
|
||||
type AuthPathConfiguration struct {
|
||||
Include []string `yaml:"include"`
|
||||
Exclude []string `yaml:"exclude"`
|
||||
}
|
||||
|
||||
type ProxyConfiguration struct {
|
||||
ID string `yaml:"id"`
|
||||
Host string `yaml:"host"`
|
||||
Target string `yaml:"target"`
|
||||
}
|
||||
|
||||
type ApiConfiguration struct {
|
||||
ID string `yaml:"id"`
|
||||
Target string `yaml:"target"`
|
||||
}
|
||||
Reference in New Issue
Block a user