如何指定环境,请看启动参数

  1. //新API创建 configuration := configuration.YAML("config")
  2. configuration := abstractions.NewConfigurationBuilder().AddYamlFile("config").Build()
  3. // 添加环境为Prod的配置文件 config_prod.yml
  4. YoyoGo.NewWebHostBuilder().
  5. UseConfiguration(configuration).
  6. Configure(func(app *YoyoGo.WebApplicationBuilder) {
  7. app.UseStaticAssets() //添加静态资源
  8. app.UseEndpoints(registerEndpointRouterConfig) //api 路由
  9. }).Build().Run()

config_prod.yml

  1. yoyogo:
  2. application:
  3. name: yoyogo_prod
  4. metadata: "develop"
  5. server:
  6. type: "fasthttp"
  7. address: ":8080"
  8. path: "app"
  9. max_request_size: 2096157
  10. session:
  11. name: "YOYOGO_SESSIONID"
  12. timeout: 3600
  13. tls:
  14. cert: ""
  15. key: ""
  16. mvc:
  17. template: "v1/{controller}/{action}"
  18. views:
  19. path: "./static/templates"
  20. includes: [ "","" ]
  21. static:
  22. patten: "/"
  23. webroot: "./static"
  24. jwt:
  25. header: "Authorization"
  26. secret: "12391JdeOW^%$#@"
  27. prefix: "Bearer"
  28. expires: 3
  29. enable: false
  30. skip_path: [
  31. "/info",
  32. "/v1/user/GetInfo",
  33. "/v1/user/GetSD"
  34. ]
  35. cors:
  36. allow_origins: ["*"]
  37. allow_methods: ["POST","GET","PUT", "PATCH"]
  38. allow_credentials: true
  39. cloud:
  40. apm:
  41. skyworking:
  42. address: localhost:11800
  43. discovery:
  44. cache:
  45. ttl: 30 # seconds 服务发现client缓存
  46. register-enable: false #是否注册自身
  47. type: "nacos"
  48. metadata:
  49. url: "120.53.133.30"
  50. port: 80
  51. namespace: "public"
  52. group_name: ""
  53. # clusters: [""]
  54. # type: "consul"
  55. # metadata:
  56. # address: "localhost:8500"
  57. # health_check: "/actuator/health"
  58. # tags: [""]
  59. # type: "eureka"
  60. # metadata:
  61. # address: "http://localhost:5000/eureka"
  62. datasource:
  63. mysql:
  64. name: db1
  65. url: tcp(127.0.0.1/yoyoBlog?charset=utf8&parseTime=True
  66. username: root
  67. password: 1234
  68. debug: true
  69. pool:
  70. init_cap: 2
  71. max_cap: 5
  72. idle_timeout : 5
  73. redis:
  74. name: reids1
  75. url: 127.0.0.1:31379
  76. password:
  77. db: 0
  78. pool:
  79. init_cap: 2
  80. max_cap: 5
  81. idle_timeout: 5