Skip to content

Commit

Permalink
#9 Add database to the config
Browse files Browse the repository at this point in the history
  • Loading branch information
thegodenage committed May 6, 2024
1 parent 796cf69 commit b04a951
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 7 additions & 1 deletion cmd/proxy/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ rules:
- name: "request payload must contain at least one character and should contain at least one header"
predicate: "p => LEN(p.payload) > 0 && LEN(p.headers) > 0"
- name: "payload must be a json"
predicate: "p => FORMAT(p.payload) == 'json'"
predicate: "p => FORMAT(p.payload) == 'json'"

# For now it will be here but it should be moved to env variables
database:
# Its docker compose based connection string
connectionString: "dns:root@tcp(127.0.0.1:3306)/dns"

11 changes: 9 additions & 2 deletions internal/config/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
)

type YamlConfig struct {
DNS []*Dns `yaml:"dns"`
Rules Rules `yaml:"rules"`
DNS []*Dns `yaml:"dns"`
Rules Rules `yaml:"rules"`
Database Database `yaml:"database"`
}

type Dns struct {
Expand All @@ -27,6 +28,12 @@ type CustomRule struct {
Predicate string `yaml:"predicate"`
}

// Database represents database config.
// Its temp as it should be moved to environment variables
type Database struct {
ConnectionString string `yaml:"connectionString"`
}

func NewYamlConfig(yamlBytes []byte) (*YamlConfig, error) {
var yamlCfg YamlConfig
if err := yaml.Unmarshal(yamlBytes, &yamlCfg); err != nil {
Expand Down

0 comments on commit b04a951

Please sign in to comment.