config.go 770 B

123456789101112131415161718192021222324252627282930313233
  1. package config
  2. import (
  3. "gopkg.in/yaml.v3"
  4. "os"
  5. )
  6. func InitConf(path string, conf *ConfStruct) (err error) {
  7. fileContent, err := os.ReadFile(path)
  8. if err != nil {
  9. return
  10. }
  11. if err = yaml.Unmarshal(fileContent, &conf); err != nil {
  12. return
  13. }
  14. return
  15. }
  16. type ConfStruct struct {
  17. BasicListen string `yaml:"BasicListen"`
  18. HttpsServices HttpsConfig `yaml:"HttpsServices"`
  19. DefaultTimeOut int `yaml:"DefaultTimeOut"`
  20. CloseLog bool `yaml:"CloseLog"`
  21. CloseWebLog bool `yaml:"CloseWebLog"`
  22. }
  23. // HttpsConfig 代表HTTPS相关配置的结构体
  24. type HttpsConfig struct {
  25. IsEnable bool `yaml:"IsEnable"`
  26. HttpsListen string `yaml:"HttpsListen"`
  27. PemPath string `yaml:"PemPath"`
  28. KeyPath string `yaml:"KeyPath"`
  29. }