MCPcopy Create free account
hub / github.com/kataras/iris / HandleServer

Method HandleServer

core/router/api_builder.go:1586–1623  ·  view source on GitHub ↗

HandleServer registers a route for all HTTP methods which forwards the requests to the given server. Usage: app.HandleServer("/api/identity/{first:string}/orgs/{second:string}/{p:path}", otherApp) OR app.HandleServer("/api/identity", otherApp)

(path string, server ServerHandler)

Source from the content-addressed store, hash-verified

1584//
1585// app.HandleServer("/api/identity", otherApp)
1586func (api *APIBuilder) HandleServer(path string, server ServerHandler) {
1587 if server == nil {
1588 return
1589 }
1590
1591 if app, ok := server.(serverBuilder); ok {
1592 // Do an extra check for Build() error at any case
1593 // the end-developer didn't call Build before.
1594 if err := app.Build(); err != nil {
1595 panic(err)
1596 }
1597 }
1598
1599 pathParameterName := ""
1600
1601 // Check and get the last parameter name if it's a wildcard one by the end-developer.
1602 parsedPath, err := macro.Parse(path, *api.macros)
1603 if err != nil {
1604 panic(err)
1605 }
1606
1607 if n := len(parsedPath.Params); n > 0 {
1608 lastParam := parsedPath.Params[n-1]
1609 if lastParam.IsMacro(macro.Path) {
1610 pathParameterName = lastParam.Name
1611 // path remains as it was defined by the end-developer.
1612 }
1613 }
1614 //
1615
1616 if pathParameterName == "" {
1617 pathParameterName = fmt.Sprintf("iris_wildcard_path_parameter%d", len(api.routes.routes))
1618 path = fmt.Sprintf("%s/{%s:path}", path, pathParameterName)
1619 }
1620
1621 handler := makeServerHandler(pathParameterName, server.ServeHTTPC)
1622 api.Any(path, handler)
1623}
1624
1625func makeServerHandler(givenPathParameter string, handler context.Handler) context.Handler {
1626 return func(ctx *context.Context) {

Callers

nothing calls this directly

Calls 5

AnyMethod · 0.95
ParseFunction · 0.92
makeServerHandlerFunction · 0.85
IsMacroMethod · 0.80
BuildMethod · 0.65

Tested by

no test coverage detected