docker 路由框架 源码分析
tags: docker,container,源码分析
docker 路由框架 源码分析
https://github.com/moby/moby/blob/v20.10.14/api/server/server.go#L175
func (s *Server) createMux() *mux.Router {
m := mux.NewRouter()
...
for _, apiRouter := range s.routers {
for _, r := range apiRouter.Routes() {
f := s.makeHTTPHandler(r.Handler())
...
m.Path(versionMatcher + r.Path()).Methods(r.Method()).Handler(f)
m.Path(r.Path()).Methods(r.Method()).Handler(f)
}
}
...
}
https://github.com/docker/cli/blob/v20.10.14/vendor/github.com/docker/docker/client/client.go#L188
func (cli *Client) getAPIPath(ctx context.Context, p string, query url.Values) string {
...
if cli.version != "" {
v := strings.TrimPrefix(cli.version, "v")
apiPath = path.Join(cli.basePath, "/v"+v, p)
} else {
apiPath = path.Join(cli.basePath, p)
}
...
}