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.

56 lines
1002 B

5 years ago
  1. package govue
  2. import (
  3. "errors"
  4. "git.ouxuan.net/3136352472/go-service-template/pool"
  5. )
  6. type Config struct {
  7. Addr string `json:"addr"`
  8. StaticDir string `json:"static_dir"`
  9. UseJsFile string `json:"use_js_file"`
  10. Mode string `json:"mode"`
  11. Pool pool.Config `json:"pool"`
  12. }
  13. func GenerateConfig(path string) (err error) {
  14. if pathExists(path) {
  15. err = errors.New("配置文件已存在")
  16. return
  17. }
  18. config := Config{
  19. Addr: "0.0.0.0:8080",
  20. StaticDir: "static",
  21. UseJsFile: "static/use.js",
  22. Mode: "release",
  23. Pool: pool.Config{
  24. MaxIdle: 2000,
  25. MinIdle: 5,
  26. MaxTotal: 6000,
  27. },
  28. }
  29. jsonToFile(path, config)
  30. return
  31. }
  32. func GetConfig(path string) (c *Config, err error) {
  33. c = &Config{
  34. Addr: "0.0.0.0:8080",
  35. StaticDir: "static",
  36. UseJsFile: "static/use.js",
  37. Mode: "release",
  38. Pool: pool.Config{
  39. MaxIdle: 2000,
  40. MinIdle: 5,
  41. MaxTotal: 6000,
  42. },
  43. }
  44. if pathExists(path) {
  45. jsonByFile(path, c)
  46. }
  47. return
  48. }