如何指定环境,请看启动参数
//新API创建 configuration := configuration.YAML("config")
configuration := abstractions.NewConfigurationBuilder().AddYamlFile("config").Build()
// 添加环境为Prod的配置文件 config_prod.yml
YoyoGo.NewWebHostBuilder().
UseConfiguration(configuration).
Configure(func(app *YoyoGo.WebApplicationBuilder) {
app.UseStaticAssets() //添加静态资源
app.UseEndpoints(registerEndpointRouterConfig) //api 路由
}).Build().Run()
# config_prod.yml
yoyogo:
application:
name: yoyogo_prod
metadata: "develop"
server:
type: "fasthttp"
address: ":8080"
path: "app"
max_request_size: 2096157
session:
name: "YOYOGO_SESSIONID"
timeout: 3600
tls:
cert: ""
key: ""
mvc:
template: "v1/{controller}/{action}"
views:
path: "./static/templates"
includes: [ "","" ]
static:
patten: "/"
webroot: "./static"
jwt:
header: "Authorization"
secret: "12391JdeOW^%$#@"
prefix: "Bearer"
expires: 3
enable: false
skip_path: [
"/info",
"/v1/user/GetInfo",
"/v1/user/GetSD"
]
cors:
allow_origins: ["*"]
allow_methods: ["POST","GET","PUT", "PATCH"]
allow_credentials: true
cloud:
apm:
skyworking:
address: localhost:11800
discovery:
cache:
ttl: 30 # seconds 服务发现client缓存
register-enable: false #是否注册自身
type: "nacos"
metadata:
url: "120.53.133.30"
port: 80
namespace: "public"
group_name: ""
# clusters: [""]
# type: "consul"
# metadata:
# address: "localhost:8500"
# health_check: "/actuator/health"
# tags: [""]
# type: "eureka"
# metadata:
# address: "http://localhost:5000/eureka"
datasource:
mysql:
name: db1
url: tcp(127.0.0.1/yoyoBlog?charset=utf8&parseTime=True
username: root
password: 1234
debug: true
pool:
init_cap: 2
max_cap: 5
idle_timeout : 5
redis:
name: reids1
url: 127.0.0.1:31379
password:
db: 0
pool:
init_cap: 2
max_cap: 5
idle_timeout: 5