github.com/christoph-karpowicz/db_mediator@v0.0.0-20210207102849-61a28a1071d8/internal/server/cfg/synch_cfg.go (about)

     1  package cfg
     2  
     3  import (
     4  	"fmt"
     5  
     6  	validationUtil "github.com/christoph-karpowicz/db_mediator/internal/util/validation"
     7  )
     8  
     9  var synchNullableFields = []string{}
    10  
    11  const (
    12  	DB_INSERT = "INSERT"
    13  	DB_UPDATE = "UPDATE"
    14  )
    15  
    16  // SynchConfig holds raw data from the YAML config file.
    17  type SynchConfig struct {
    18  	Name  string       `yaml:"name"`
    19  	Nodes []NodeConfig `yaml:"nodes"`
    20  	Map   []string     `yaml:"map"`
    21  	Link  []string     `yaml:"link"`
    22  	Match Match        `yaml:"match"`
    23  	Do    []string     `yaml:"do"`
    24  }
    25  
    26  // Validate data from the YAML file.
    27  func (s *SynchConfig) Validate() {
    28  	validationUtil.YAMLStruct(*s, synchNullableFields)
    29  
    30  	for _, node := range s.Nodes {
    31  		validationUtil.YAMLStruct(node, synchNullableFields)
    32  	}
    33  }
    34  
    35  // GetSynchConfigs loads configs from the synchs directory.
    36  func GetSynchConfigs() []Config {
    37  	fmt.Println("Synchs:")
    38  	return ImportYAMLDir(SYNCH_DIR)
    39  }