本文整理汇总了Golang中github.com/bmizerany/pat.PatternServeMux.Put方法的典型用法代码示例。如果您正苦于以下问题:Golang PatternServeMux.Put方法的具体用法?Golang PatternServeMux.Put怎么用?Golang PatternServeMux.Put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/bmizerany/pat.PatternServeMux
的用法示例。
在下文中一共展示了PatternServeMux.Put方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
}
示例2: 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))
}
示例3: 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))
}
示例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)
}
}
示例5: 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)
}
}))
}
示例6: 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)
}
}))
}