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.

57 lines
1.0 KiB

5 years ago
  1. package govue2
  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. ErrorPage404 string `json:"error_page_404"`
  11. Mode string `json:"mode"`
  12. Pool pool.Config `json:"pool"`
  13. }
  14. func GenerateConfig(path string) (err error) {
  15. if pathExists(path) {
  16. err = errors.New("配置文件已存在")
  17. return
  18. }
  19. config := Config{
  20. Addr: "0.0.0.0:8080",
  21. StaticDir: "static",
  22. UseJsFile: "static/use.js",
  23. Mode: "release",
  24. Pool: pool.Config{
  25. MaxIdle: 2000,
  26. MinIdle: 5,
  27. MaxTotal: 6000,
  28. },
  29. }
  30. jsonToFile(path, config)
  31. return
  32. }
  33. func GetConfig(path string) (c *Config, err error) {
  34. c = &Config{
  35. Addr: "0.0.0.0:8080",
  36. StaticDir: "static",
  37. UseJsFile: "static/use.js",
  38. Mode: "release",
  39. Pool: pool.Config{
  40. MaxIdle: 2000,
  41. MinIdle: 5,
  42. MaxTotal: 6000,
  43. },
  44. }
  45. if pathExists(path) {
  46. jsonByFile(path, c)
  47. }
  48. return
  49. }