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

Golang httplog.StatusIsNot函数代码示例

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

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



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

示例1: RecoverPanics

// RecoverPanics wraps an http Handler to recover and log panics.
func RecoverPanics(handler http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		defer func() {
			if x := recover(); x != nil {
				w.WriteHeader(http.StatusInternalServerError)
				fmt.Fprint(w, "apis panic. Look in log for details.")
				glog.Infof("APIServer panic'd on %v %v: %v\n%s\n", req.Method, req.RequestURI, x, debug.Stack())
			}
		}()
		defer httplog.NewLogged(req, &w).StacktraceWhen(
			httplog.StatusIsNot(
				http.StatusOK,
				http.StatusCreated,
				http.StatusAccepted,
				http.StatusMovedPermanently,
				http.StatusTemporaryRedirect,
				http.StatusConflict,
				http.StatusNotFound,
				StatusUnprocessableEntity,
			),
		).Log()

		// Dispatch to the internal handler
		handler.ServeHTTP(w, req)
	})
}
开发者ID:ericcapricorn,项目名称:kubernetes,代码行数:27,代码来源:handlers.go


示例2: ServeHTTP

// ServeHTTP responds to HTTP requests on the Kubelet
func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	defer httplog.NewLogged(req, &w).StacktraceWhen(
		httplog.StatusIsNot(
			http.StatusOK,
			http.StatusNotFound,
		),
	).Log()
	s.mux.ServeHTTP(w, req)
}
开发者ID:hvdb,项目名称:kubernetes,代码行数:10,代码来源:server.go


示例3: ServeHTTP

// ServeHTTP responds to HTTP requests on the Kubelet.
func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	defer httplog.NewLogged(req, &w).StacktraceWhen(
		httplog.StatusIsNot(
			http.StatusOK,
			http.StatusMovedPermanently,
			http.StatusTemporaryRedirect,
			http.StatusNotFound,
		),
	).Log()
	s.mux.ServeHTTP(w, req)
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:12,代码来源:server.go


示例4: ServeHTTP

// HTTP Handler interface
func (server *APIServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	defer func() {
		if x := recover(); x != nil {
			w.WriteHeader(http.StatusInternalServerError)
			fmt.Fprint(w, "apiserver panic. Look in log for details.")
			glog.Infof("APIServer panic'd on %v %v: %#v\n%s\n", req.Method, req.RequestURI, x, debug.Stack())
		}
	}()
	defer httplog.MakeLogged(req, &w).StacktraceWhen(
		httplog.StatusIsNot(
			http.StatusOK,
			http.StatusAccepted,
			http.StatusConflict,
		),
	).Log()

	// Dispatch via our mux.
	server.mux.ServeHTTP(w, req)
}
开发者ID:ryfow,项目名称:kubernetes,代码行数:20,代码来源:apiserver.go


示例5: ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	defer httplog.MakeLogged(req, &w).StacktraceWhen(
		httplog.StatusIsNot(
			http.StatusOK,
			http.StatusNotFound,
		),
	).Log()

	u, err := url.ParseRequestURI(req.RequestURI)
	if err != nil {
		s.error(w, err)
		return
	}
	// TODO: use an http.ServeMux instead of a switch.
	switch {
	case u.Path == "/container" || u.Path == "/containers":
		defer req.Body.Close()
		data, err := ioutil.ReadAll(req.Body)
		if err != nil {
			s.error(w, err)
			return
		}
		if u.Path == "/container" {
			// This is to provide backward compatibility. It only supports a single manifest
			var pod Pod
			err = yaml.Unmarshal(data, &pod.Manifest)
			if err != nil {
				s.error(w, err)
				return
			}
			//TODO: sha1 of manifest?
			pod.Name = "1"
			s.updates <- PodUpdate{[]Pod{pod}, SET}
		} else if u.Path == "/containers" {
			var manifests []api.ContainerManifest
			err = yaml.Unmarshal(data, &manifests)
			if err != nil {
				s.error(w, err)
				return
			}
			pods := make([]Pod, len(manifests))
			for i := range manifests {
				pods[i].Name = fmt.Sprintf("%d", i+1)
				pods[i].Manifest = manifests[i]
			}
			s.updates <- PodUpdate{pods, SET}
		}
	case u.Path == "/podInfo":
		podID := u.Query().Get("podID")
		if len(podID) == 0 {
			w.WriteHeader(http.StatusBadRequest)
			http.Error(w, "Missing 'podID=' query entry.", http.StatusBadRequest)
			return
		}
		// TODO: backwards compatibility with existing API, needs API change
		podFullName := GetPodFullName(&Pod{Name: podID, Namespace: "etcd"})
		info, err := s.host.GetPodInfo(podFullName)
		if err == ErrNoContainersInPod {
			http.Error(w, "Pod does not exist", http.StatusNotFound)
			return
		}
		if err != nil {
			s.error(w, err)
			return
		}
		data, err := json.Marshal(info)
		if err != nil {
			s.error(w, err)
			return
		}
		w.WriteHeader(http.StatusOK)
		w.Header().Add("Content-type", "application/json")
		w.Write(data)
	case strings.HasPrefix(u.Path, "/stats"):
		s.serveStats(w, req)
	case strings.HasPrefix(u.Path, "/spec"):
		info, err := s.host.GetMachineInfo()
		if err != nil {
			s.error(w, err)
			return
		}
		data, err := json.Marshal(info)
		if err != nil {
			s.error(w, err)
			return
		}
		w.Header().Add("Content-type", "application/json")
		w.Write(data)
	case strings.HasPrefix(u.Path, "/logs/"):
		s.host.ServeLogs(w, req)
	default:
		if s.handler != nil {
			s.handler.ServeHTTP(w, req)
		}
	}
}
开发者ID:GoogleButtPlatform,项目名称:kubernetes,代码行数:96,代码来源:server.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang httplog.Unlogged函数代码示例发布时间:2022-05-23
下一篇:
Golang httplog.NewLogged函数代码示例发布时间: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