赛思维服务调研
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
851 B

  1. package conf
  2. import (
  3. "gopkg.in/yaml.v2"
  4. "os"
  5. )
  6. type EnvConfig struct {
  7. DbType string `yaml:"dbtype"`
  8. Server string `yaml:"server"`
  9. Ip string `yaml:"ip"`
  10. User string `yaml:"user"`
  11. Password string `yaml:"password"`
  12. DbName string `yaml:"dbname"`
  13. Port int `yaml:"port"`
  14. TemplatePath string `yaml:"templatepath"`
  15. ReadTaskInterval int `yaml:"readtaskinterval"`
  16. PrinterType string `yaml:"printertype"`
  17. Finr int `yaml:"finr"`
  18. Inbox string `yaml:"inbox"`
  19. Outbox string `yaml:"outbox"`
  20. Log string `yaml:"log"`
  21. }
  22. //read yaml config
  23. //注:path为yaml或yml文件的路径
  24. func ReadYamlConfig(path string) (*EnvConfig,error){
  25. conf := &EnvConfig{}
  26. f, err := os.Open(path)
  27. if err != nil {
  28. return nil,err
  29. } else {
  30. yaml.NewDecoder(f).Decode(conf)
  31. }
  32. defer f.Close()
  33. return conf,nil
  34. }