代码拉取完成,页面将自动刷新
The router plugin is a HTTP handler plugin for the Micro API which enables you to define routes via go-os/config. This is dynamic configuration that can then be leveraged via anything that implements the go-os/config interface e.g file, etcd, consul or the config service.
Register the plugin before building Micro
package main
import (
"github.com/micro/micro/plugin"
"github.com/micro/go-plugins/micro/router"
)
func init() {
plugin.Register(router.NewRouter())
}
Configuring the router is done via a go-os/Config source. Here's an example using the File source.
// Create Config Source
f := file.NewSource(
// Use routes.json file
config.SourceName("routes.json"),
)
// Create Config
c := config.NewConfig(
// With Source
config.WithSource(f),
)
// Create Router
r := router.NewRouter(
// With Config
router.Config(c),
)
Routes are used to config request to match and the response to return. Here's an example.
{
"api": {
"routes": [
{
"request": {
"method": "GET",
"host": "127.0.0.1:10001",
"path": "/"
},
"response": {
"status_code": 302,
"header": {
"location": "http://example.com"
}
},
"weight": 1.0
},
{
"request": {
"method": "POST",
"host": "127.0.0.1:10001",
"path": "/foo"
},
"response": {
"status_code": 301,
"header": {
"location": "http://foo.bar.com"
}
},
"weight": 1.0
}
]
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。