Skip to content

Commit

Permalink
dev: add option for setting host
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangxu19830126 committed Apr 4, 2019
1 parent f835ec9 commit 53db332
Show file tree
Hide file tree
Showing 7 changed files with 368 additions and 202 deletions.
4 changes: 4 additions & 0 deletions cmd/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func main() {
return c.String(http.StatusOK, c.Request().Header.Get(name))
})

server.GET("/host", func(c echo.Context) error {
return c.String(http.StatusOK, c.Request().Host)
})

server.GET("/error", func(c echo.Context) error {
return c.NoContent(http.StatusBadRequest)
})
Expand Down
22 changes: 22 additions & 0 deletions pkg/client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,28 @@ func (ab *APIBuilder) addRenderObject(nameInTemplate string, flatAttrs bool, nam
return ab
}

// AddDispatchNodeHost add host
func (ab *APIBuilder) AddDispatchNodeHost(cluster uint64, hostType metapb.HostType, custom string) *APIBuilder {
return ab.AddDispatchNodeHostWithIndex(cluster, 0, hostType, custom)
}

// AddDispatchNodeHostWithIndex add host
func (ab *APIBuilder) AddDispatchNodeHostWithIndex(cluster uint64, idx int, hostType metapb.HostType, custom string) *APIBuilder {
node := ab.getNode(cluster, idx)
if nil == node {
ab.value.Nodes = append(ab.value.Nodes, &metapb.DispatchNode{
ClusterID: cluster,
HostType: hostType,
CustemHost: custom,
})
} else {
node.HostType = hostType
node.CustemHost = custom
}

return ab
}

// AddTag add tag for api
func (ab *APIBuilder) AddTag(key, value string) *APIBuilder {
ab.value.Tags = append(ab.value.Tags, &metapb.PairValue{
Expand Down
Loading

0 comments on commit 53db332

Please sign in to comment.