• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang mux.Mux类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/google/cadvisor/http/mux.Mux的典型用法代码示例。如果您正苦于以下问题:Golang Mux类的具体用法?Golang Mux怎么用?Golang Mux使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Mux类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: RegisterHandlers

func RegisterHandlers(mux httpMux.Mux, containerManager manager.Manager, httpAuthFile, httpAuthRealm, httpDigestFile, httpDigestRealm, prometheusEndpoint string) error {
	// Basic health handler.
	if err := healthz.RegisterHandler(mux); err != nil {
		return fmt.Errorf("failed to register healthz handler: %s", err)
	}

	// Validation/Debug handler.
	mux.HandleFunc(validate.ValidatePage, func(w http.ResponseWriter, r *http.Request) {
		err := validate.HandleRequest(w, containerManager)
		if err != nil {
			fmt.Fprintf(w, "%s", err)
		}
	})

	// Register API handler.
	if err := api.RegisterHandlers(mux, containerManager); err != nil {
		return fmt.Errorf("failed to register API handlers: %s", err)
	}

	// Redirect / to containers page.
	mux.Handle("/", http.RedirectHandler(pages.ContainersPage, http.StatusTemporaryRedirect))

	var authenticated bool = false

	// Setup the authenticator object
	if httpAuthFile != "" {
		glog.Infof("Using auth file %s", httpAuthFile)
		secrets := auth.HtpasswdFileProvider(httpAuthFile)
		authenticator := auth.NewBasicAuthenticator(httpAuthRealm, secrets)
		mux.HandleFunc(static.StaticResource, authenticator.Wrap(staticHandler))
		if err := pages.RegisterHandlersBasic(mux, containerManager, authenticator); err != nil {
			return fmt.Errorf("failed to register pages auth handlers: %s", err)
		}
		authenticated = true
	}
	if httpAuthFile == "" && httpDigestFile != "" {
		glog.Infof("Using digest file %s", httpDigestFile)
		secrets := auth.HtdigestFileProvider(httpDigestFile)
		authenticator := auth.NewDigestAuthenticator(httpDigestRealm, secrets)
		mux.HandleFunc(static.StaticResource, authenticator.Wrap(staticHandler))
		if err := pages.RegisterHandlersDigest(mux, containerManager, authenticator); err != nil {
			return fmt.Errorf("failed to register pages digest handlers: %s", err)
		}
		authenticated = true
	}

	// Change handler based on authenticator initalization
	if !authenticated {
		mux.HandleFunc(static.StaticResource, staticHandlerNoAuth)
		if err := pages.RegisterHandlersBasic(mux, containerManager, nil); err != nil {
			return fmt.Errorf("failed to register pages handlers: %s", err)
		}
	}

	collector := metrics.NewPrometheusCollector(containerManager)
	prometheus.MustRegister(collector)
	http.Handle(prometheusEndpoint, prometheus.Handler())

	return nil
}
开发者ID:alena1108,项目名称:kubernetes,代码行数:60,代码来源:handlers.go


示例2: RegisterHandlers

func RegisterHandlers(mux httpMux.Mux, m manager.Manager) error {
	apiVersions := getApiVersions()
	supportedApiVersions := make(map[string]ApiVersion, len(apiVersions))
	for _, v := range apiVersions {
		supportedApiVersions[v.Version()] = v
	}

	mux.HandleFunc(apiResource, func(w http.ResponseWriter, r *http.Request) {
		err := handleRequest(supportedApiVersions, m, w, r)
		if err != nil {
			http.Error(w, err.Error(), 500)
		}
	})
	return nil
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:15,代码来源:handler.go


示例3: RegisterHandlersBasic

func RegisterHandlersBasic(mux httpmux.Mux, containerManager manager.Manager, authenticator *auth.BasicAuth) error {
	// Register the handler for the containers and docker age.
	if authenticator != nil {
		mux.HandleFunc(ContainersPage, authenticator.Wrap(containerHandler(containerManager)))
		mux.HandleFunc(DockerPage, authenticator.Wrap(dockerHandler(containerManager)))
	} else {
		mux.HandleFunc(ContainersPage, containerHandlerNoAuth(containerManager))
		mux.HandleFunc(DockerPage, dockerHandlerNoAuth(containerManager))
	}
	return nil
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:11,代码来源:pages.go


示例4: RegisterPrometheusHandler

func RegisterPrometheusHandler(mux httpmux.Mux, containerManager manager.Manager, prometheusEndpoint string, containerNameToLabelsFunc metrics.ContainerNameToLabelsFunc) {
	collector := metrics.NewPrometheusCollector(containerManager, containerNameToLabelsFunc)
	prometheus.MustRegister(collector)
	mux.Handle(prometheusEndpoint, prometheus.Handler())
}
开发者ID:kaushikanurag,项目名称:cadvisor,代码行数:5,代码来源:handlers.go


示例5: RegisterHandler

// Register simple HTTP /healthz handler to return "ok".
func RegisterHandler(mux httpMux.Mux) error {
	mux.HandleFunc("/healthz", handleHealthz)
	return nil
}
开发者ID:johnmccawley,项目名称:origin,代码行数:5,代码来源:healthz.go



注:本文中的github.com/google/cadvisor/http/mux.Mux类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang info.ContainerInfoRequest类代码示例发布时间:2022-05-23
下一篇:
Golang http.RegisterPrometheusHandler函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap