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

Golang pat.PatternServeMux类代码示例

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

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



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

示例1: Handler

func (peer *Peer) Handler(m *pat.PatternServeMux) {
	m.Get("/stats", http.HandlerFunc(func(w http.ResponseWriter, request *http.Request) {
		stats := httpclient.JsonData{
			"ring":       peer.ring.GetNodes(),
			"vnodeCount": peer.node.VnodeCount(),
			"vnodeSize":  peer.node.VnodeSize(),
			"vnodeStart": peer.node.VnodeStart(),
		}

		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(200)
		io.WriteString(w, stats.Encode())
	}))

	m.Put("/ring", http.HandlerFunc(func(w http.ResponseWriter, request *http.Request) {
		body, _ := ioutil.ReadAll(request.Body)
		data := map[string][]string{}
		json.Unmarshal(body, &data)

		peer.ring.SetNodes(data["ring"])
		peer.node = peer.ring.Get(peer.url)

		w.WriteHeader(201)
	}))

	m.Put("/peers", http.HandlerFunc(func(w http.ResponseWriter, request *http.Request) {
		body, _ := ioutil.ReadAll(request.Body)
		newPeerURL := string(body)

		if peer.peerExists(newPeerURL) {
			w.WriteHeader(409)
		} else {
			peer.addPeer(newPeerURL)
			w.WriteHeader(201)
		}
	}))

	m.Put("/peers/join", http.HandlerFunc(func(w http.ResponseWriter, request *http.Request) {
		body, _ := ioutil.ReadAll(request.Body)
		newPeerURL := string(body)

		if peer.peerExists(newPeerURL) {
			w.WriteHeader(409)
		} else {
			peer.join(newPeerURL)
			w.WriteHeader(201)
		}
	}))

	m.Get("/peers", http.HandlerFunc(func(w http.ResponseWriter, request *http.Request) {
		if peer.HasPeer() {
			w.Header().Set("Content-Type", "application/json")
			w.WriteHeader(200)
			io.WriteString(w, httpclient.JsonData{"peers": peer.Peers}.Encode())
		} else {
			w.WriteHeader(404)
		}
	}))
}
开发者ID:benmills,项目名称:goak,代码行数:59,代码来源:peer.go


示例2: registerEndpoint

func (self *HttpServer) registerEndpoint(p *pat.PatternServeMux, method string, pattern string, f libhttp.HandlerFunc) {
	switch method {
	case "get":
		p.Get(pattern, CorsHeaderHandler(f))
	case "post":
		p.Post(pattern, CorsHeaderHandler(f))
	case "del":
		p.Del(pattern, CorsHeaderHandler(f))
	}
	p.Options(pattern, CorsHeaderHandler(self.sendCrossOriginHeader))
}
开发者ID:kennylixi,项目名称:influxdb,代码行数:11,代码来源:api.go


示例3: registerEndpoint

func (self *HttpServer) registerEndpoint(p *pat.PatternServeMux, method string, pattern string, f libhttp.HandlerFunc) {
	version := self.clusterConfig.GetLocalConfiguration().Version
	switch method {
	case "get":
		p.Get(pattern, HeaderHandler(f, version))
	case "post":
		p.Post(pattern, HeaderHandler(f, version))
	case "del":
		p.Del(pattern, HeaderHandler(f, version))
	}
	p.Options(pattern, HeaderHandler(self.sendCrossOriginHeader, version))
}
开发者ID:peekeri,项目名称:influxdb,代码行数:12,代码来源:api.go


示例4: registerEndpoint

func registerEndpoint(ep apihttp.Endpoint, mux *pat.PatternServeMux) {
	switch ep.Method {
	case "GET":
		mux.Get(ep.Pattern, ep.Handler)
	case "POST":
		mux.Post(ep.Pattern, ep.Handler)
	case "HEAD":
		mux.Head(ep.Pattern, ep.Handler)
	case "PUT":
		mux.Put(ep.Pattern, ep.Handler)
	case "DEL":
		mux.Del(ep.Pattern, ep.Handler)
	case "OPTIONS":
		mux.Options(ep.Pattern, ep.Handler)
	}
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:16,代码来源:apiserver.go


示例5: registerEndpoint

func registerEndpoint(ep apihttp.Endpoint, mux *pat.PatternServeMux) {
	mux.Add(ep.Method, ep.Pattern, ep.Handler)
	if ep.Method == "GET" {
		mux.Add("HEAD", ep.Pattern, ep.Handler)
	}
}
开发者ID:kat-co,项目名称:juju,代码行数:6,代码来源:apiserver.go


示例6: BindReading

func BindReading(m *pat.PatternServeMux) {
	m.Get(readingInfo, http.HandlerFunc(infoReading))
}
开发者ID:weebook-org,项目名称:core,代码行数:3,代码来源:reading.go


示例7: handleAll

func handleAll(mux *pat.PatternServeMux, pattern string, handler http.Handler) {
	mux.Get(pattern, handler)
	mux.Post(pattern, handler)
	mux.Head(pattern, handler)
	mux.Put(pattern, handler)
	mux.Del(pattern, handler)
	mux.Options(pattern, handler)
}
开发者ID:snailwalker,项目名称:juju,代码行数:8,代码来源:apiserver.go


示例8: BindSubmission

func BindSubmission(p *pat.PatternServeMux) {
	p.Get(submissionInfo, http.HandlerFunc(infoSubmission))
	p.Get(subGetOne, http.HandlerFunc(getOneSub))
}
开发者ID:weebook-org,项目名称:core,代码行数:4,代码来源:submission.go


示例9: BindComments

func BindComments(p *pat.PatternServeMux) {
	p.Get(commentsInfo, http.HandlerFunc(infoComments))
}
开发者ID:weebook-org,项目名称:core,代码行数:3,代码来源:comments.go


示例10: AddHandlers

func AddHandlers(m *pat.PatternServeMux, base string) {

	// Movies
	m.Get(base+"/movies", JsonHandler(MovieList))
	m.Get(base+"/movies/:id", JsonHandler(MovieShow))
	m.Put(base+"/movies", JsonHandler(MovieCreate))
	m.Del(base+"/movies/:id", JsonHandler(MovieDelete))

	// Libraries
	m.Get(base+"/libraries", JsonHandler(LibraryList))
	m.Get(base+"/libraries/:id", JsonHandler(LibraryShow))
	m.Put(base+"/libraries", JsonHandler(LibraryCreate))
	m.Del(base+"/libraries/:id", JsonHandler(LibraryDelete))
	m.Get(base+"/libraries/:id/process", JsonHandler(LibraryProcess))

	// Series
	m.Get(base+"/series", JsonHandler(SeriesList))
	m.Get(base+"/series/:id", JsonHandler(SeriesShow))
	m.Put(base+"/series", JsonHandler(SeriesCreate))
	m.Del(base+"/series/:id", JsonHandler(SeriesDelete))

	// Series season
	m.Get(base+"/series/:id/seasons", JsonHandler(SeasonsList))

	// Series Episodes
	m.Get(base+"/series/:series_id/seasons/:season_num/episodes", JsonHandler(EpisodeList))

	// Episode
	m.Get(base+"/episodes/:id", JsonHandler(EpisodeShow))
	m.Put(base+"/episodes", JsonHandler(EpisodeCreate))
	m.Del(base+"/episodes/:id", JsonHandler(EpisodeDelete))
	m.Get(base+"/series/:id/episodes", JsonHandler(SeriesEpisodeList))
}
开发者ID:rharter,项目名称:mediaman,代码行数:33,代码来源:api.go


示例11: BindVote

func BindVote(m *pat.PatternServeMux) {
	m.Get(voteInfo, http.HandlerFunc(infoVote))
}
开发者ID:weebook-org,项目名称:core,代码行数:3,代码来源:vote.go


示例12: AddRoutes

func (blueprint *apiBlueprint) AddRoutes(p *pat.PatternServeMux) {
	p.Get(blueprint.base, http.HandlerFunc(blueprint.handleGet))
}
开发者ID:ngerakines,项目名称:tram,代码行数:3,代码来源:api.go


示例13: Handler

func (peer *Peer) Handler(m *pat.PatternServeMux) {
	m.Get("/stats", http.HandlerFunc(func(w http.ResponseWriter, request *http.Request) {
		stats := httpclient.JsonData{
			"ring":       peer.ring.GetNodes(),
			"vnodeCount": peer.node.VnodeCount(),
			"vnodeSize":  peer.node.VnodeSize(),
			"vnodeStart": peer.node.VnodeStart(),
			"nValue":     peer.ring.GetNValue(),
		}

		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(200)
		io.WriteString(w, stats.Encode())
	}))

	m.Put("/ring", http.HandlerFunc(func(w http.ResponseWriter, request *http.Request) {
		body, _ := ioutil.ReadAll(request.Body)
		data := map[string][]string{}
		json.Unmarshal(body, &data)

		peer.ring.SetNodes(data["ring"])
		peer.node = peer.ring.Get(peer.url)

		peer.evaluateKeyOwnership()

		w.WriteHeader(201)
	}))

	m.Put("/settings/set/n", http.HandlerFunc(func(w http.ResponseWriter, request *http.Request) {
		body, _ := ioutil.ReadAll(request.Body)
		n, err := strconv.Atoi(string(body))

		if err == nil {
			peer.ring.SetNValue(n)
			w.WriteHeader(201)
		} else {
			w.WriteHeader(422)
		}
	}))

	m.Put("/settings/n", http.HandlerFunc(func(w http.ResponseWriter, request *http.Request) {
		body, _ := ioutil.ReadAll(request.Body)
		n, err := strconv.Atoi(string(body))

		if err == nil && n < peer.peerCount() {
			peer.ring.SetNValue(n)
			for _, p := range peer.Peers {
				httpclient.Put(p+"/settings/set/n", string(body))
			}
			w.WriteHeader(201)
		} else {
			w.WriteHeader(422)
		}
	}))

	m.Put("/peers", http.HandlerFunc(func(w http.ResponseWriter, request *http.Request) {
		body, _ := ioutil.ReadAll(request.Body)
		newPeerURL := string(body)

		if peer.peerExists(newPeerURL) {
			w.WriteHeader(409)
		} else {
			peer.addPeer(newPeerURL)
			w.WriteHeader(201)
		}
	}))

	m.Put("/peers/join", http.HandlerFunc(func(w http.ResponseWriter, request *http.Request) {
		body, _ := ioutil.ReadAll(request.Body)
		newPeerURL := string(body)

		peer.logger.Printf("%s requesting to join", newPeerURL)

		if peer.peerExists(newPeerURL) {
			w.WriteHeader(409)
		} else {
			peer.join(newPeerURL)
			w.WriteHeader(201)
		}
	}))

	m.Get("/peers", http.HandlerFunc(func(w http.ResponseWriter, request *http.Request) {
		if peer.HasPeer() {
			w.Header().Set("Content-Type", "application/json")
			w.WriteHeader(200)
			io.WriteString(w, httpclient.JsonData{"peers": peer.Peers}.Encode())
		} else {
			w.WriteHeader(404)
		}
	}))
}
开发者ID:benmills,项目名称:library,代码行数:91,代码来源:peer.go


示例14: AddRoutes

func (blueprint *adminBlueprint) AddRoutes(p *pat.PatternServeMux) {
	p.Get(blueprint.base+"/config", http.HandlerFunc(blueprint.configHandler))
	p.Get(blueprint.base+"/errors", http.HandlerFunc(blueprint.errorsHandler))
	p.Get(blueprint.base+"/metrics", http.HandlerFunc(blueprint.metricsHandler))
}
开发者ID:ngerakines,项目名称:tram,代码行数:5,代码来源:admin.go


示例15: AddHandlers

func AddHandlers(m *pat.PatternServeMux, base string) {

	// Movies
	m.Get(base+"/movies", JsonHandler(MovieList))
	m.Get(base+"/movies/:id", JsonHandler(MovieShow))
	m.Put(base+"/movies", JsonHandler(MovieCreate))
	m.Del(base+"/movies/:id", JsonHandler(MovieDelete))

	// Libraries
	m.Get(base+"/libraries", JsonHandler(LibraryList))
	m.Get(base+"/libraries/:id", JsonHandler(LibraryShow))
	m.Put(base+"/libraries", JsonHandler(LibraryCreate))
	m.Del(base+"/libraries/:id", JsonHandler(LibraryDelete))
}
开发者ID:jerrellmardis,项目名称:mediaman,代码行数:14,代码来源:api.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang quantile.NewTargeted函数代码示例发布时间:2022-05-24
下一篇:
Golang pat.New函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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