开源:
https://gitee.com/ichub/gocenter.git
代码:
配置:
gateway: bypass: - path: /goauth/login - path: /goauth/logout routes: - path: /datadict serviceId: web.platform.com - path: /deptemp serviceId: web.platform.com - path: /gouser serviceId: web.platform.com - path: /goauth serviceId: web.platform.com - path: /gohrms serviceId: web.biz.com - path: /gopayment serviceId: web.biz.com - path: /goattend serviceId: web.biz.com
路由转换:
func (this *RouteParse) Get(ctx *gin.Context) *webclient.WebMsgProxyResp { var result = this.Filter(ctx) if !result.IsSuccess() { var res = webclient.NewWebMsgProxyResp() res.SetBody(result.ToBytes()) return res } var url, err = this.BuildRouteUrl() if err != nil { var res = webclient.NewWebMsgProxyResp() res.SetBody(result.ToBytes()) } var req = webclient.NewWebMsgProxy(url) return req.Get(ctx, this.WebClient) } // copyHeaders func (this *RouteParse) Post(ctx *gin.Context) *webclient.WebMsgProxyResp { var result = this.Filter(ctx) if !result.IsSuccess() { var res = webclient.NewWebMsgProxyResp() res.SetBody(result.ToBytes()) return res } var url, err = this.BuildRouteUrl() if err != nil { var res = webclient.NewWebMsgProxyResp() res.SetErr(err) res.SetBody(result.ToBytes()) return res } var req = webclient.NewWebMsgProxy(url) return req.Post(ctx, this.WebClient) } func (this *RouteParse) Delete(ctx *gin.Context) *webclient.WebMsgProxyResp { var result = this.Filter(ctx) if !result.IsSuccess() { var res = webclient.NewWebMsgProxyResp() res.SetBody(result.ToBytes()) return res } var url, err = this.BuildRouteUrl() if err != nil { var res = webclient.NewWebMsgProxyResp() res.SetBody(result.ToBytes()) } var req = webclient.NewWebMsgProxy(url) return req.Delete(ctx, this.WebClient) } func (this *RouteParse) Put(ctx *gin.Context) *webclient.WebMsgProxyResp { var result = this.Filter(ctx) if !result.IsSuccess() { var res = webclient.NewWebMsgProxyResp() res.SetBody(result.ToBytes()) } var url, err = this.BuildRouteUrl() if err != nil { var res = webclient.NewWebMsgProxyResp() res.SetErr(err) res.SetBody(result.ToBytes()) return res } var req = webclient.NewWebMsgProxy(url) return req.Put(ctx, this.WebClient) }
测试用例:
结果:
{
"code": 200,
"msg": "成功",
"page_size": 2,
"current": 1,
"total": 15,
"data": [
{
"parent_id": -1,
"dep_path": ".1",
"type": 0,
"mngr_id": 0,
"id": 1,
"code": "1",
"name": "股东会",
"enabled": 1,
"is_parent": 1
},
{
"name": "董事会",
"dep_path": ".1.4",
"is_parent": 1,
"mngr_id": 0,
"id": 4,
"code": "4",
"parent_id": -1,
"enabled": 1,
"type": 0
}
]
}
请求:
{
"page_size": 2,
"current": 1,
"order_by": [],
"fields": [],
}