feat(docker): Add Dockerfile and compose file
This commit is contained in:
75
app/config/yaml.go
Normal file
75
app/config/yaml.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"github.com/goccy/go-yaml"
|
||||
)
|
||||
|
||||
type YAMLConfig struct {
|
||||
Server Server `yaml:"server"`
|
||||
Database Database `yaml:"database"`
|
||||
Targets []Target `yaml:"targets"`
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
Port int `yaml:"port" env:"SERVER_PORT"`
|
||||
}
|
||||
|
||||
type Database struct {
|
||||
Host string `yaml:"host" env:"DB_HOST"`
|
||||
Port string `yaml:"port" env:"DB_PORT"`
|
||||
User string `yaml:"user" env:"DB_USER"`
|
||||
Password string `yaml:"password" env:"DB_PASSWORD"`
|
||||
Database string `yaml:"database" env:"DB_DATABASE"`
|
||||
}
|
||||
|
||||
type Target struct {
|
||||
Name string `yaml:"name"`
|
||||
Group *string `yaml:"group"`
|
||||
Records []Record `yaml:"records"`
|
||||
}
|
||||
|
||||
type Record struct {
|
||||
Record string `yaml:"record"`
|
||||
Endpoints []Endpoint `yaml:"endpoints"`
|
||||
}
|
||||
|
||||
type Endpoint struct {
|
||||
Name string `yaml:"name"`
|
||||
Path string `yaml:"path"`
|
||||
URL string `yaml:"url"`
|
||||
}
|
||||
|
||||
func LoadYAMLConfig(path string) (*YAMLConfig, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var config YAMLConfig
|
||||
if err := yaml.Unmarshal(data, &config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &config, nil
|
||||
}
|
||||
|
||||
func (c *YAMLConfig) JSON() string {
|
||||
json, err := json.Marshal(c)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return string(json)
|
||||
}
|
||||
|
||||
func (c *YAMLConfig) Map() *map[string]interface{} {
|
||||
jsonData, err := json.Marshal(c)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
var mapData map[string]interface{}
|
||||
if err := json.Unmarshal(jsonData, &mapData); err != nil {
|
||||
return nil
|
||||
}
|
||||
return &mapData
|
||||
}
|
||||
Reference in New Issue
Block a user