本文整理汇总了Golang中github.com/skynetservices/skydns/msg.Service.UUID方法的典型用法代码示例。如果您正苦于以下问题:Golang Service.UUID方法的具体用法?Golang Service.UUID怎么用?Golang Service.UUID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/skynetservices/skydns/msg.Service
的用法示例。
在下文中一共展示了Service.UUID方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: addServiceHTTPHandler
// Handle API add service requests
func (s *Server) addServiceHTTPHandler(w http.ResponseWriter, req *http.Request) {
addServiceCount.Inc(1)
vars := mux.Vars(req)
var uuid string
var ok bool
var secret string
//read the authorization header to get the secret.
secret = req.Header.Get("Authorization")
if err := s.authenticate(secret); err != nil {
http.Error(w, err.Error(), http.StatusForbidden)
return
}
if uuid, ok = vars["uuid"]; !ok {
http.Error(w, "UUID required", http.StatusBadRequest)
return
}
var serv msg.Service
if err := json.NewDecoder(req.Body).Decode(&serv); err != nil {
log.Println("Error: ", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if serv.Host == "" || serv.Port == 0 {
http.Error(w, "Host and Port required", http.StatusBadRequest)
return
}
serv.UUID = uuid
if _, err := s.raftServer.Do(NewAddServiceCommand(serv)); err != nil {
switch err {
case registry.ErrExists:
http.Error(w, err.Error(), http.StatusConflict)
case raft.NotLeaderError:
s.redirectToLeader(w, req)
default:
log.Println("Error: ", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
}
return
}
w.WriteHeader(http.StatusCreated)
}