本文整理汇总了Golang中github.com/m4rw3r/uuid.FromString函数的典型用法代码示例。如果您正苦于以下问题:Golang FromString函数的具体用法?Golang FromString怎么用?Golang FromString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FromString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: settlePlayerDebt
func settlePlayerDebt(c web.C, w http.ResponseWriter, r *http.Request) *appError {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
pUUID, err := uuid.FromString(c.URLParams["uuid"])
dUUID, err := uuid.FromString(c.URLParams["debtuuid"])
player, err := players.PlayerByUUID(pUUID)
if err != nil {
return &appError{err, "Cant find player", 404}
}
debt, err := player.DebtByUUID(dUUID)
if err != nil {
return &appError{err, "Cant find debt for player", 404}
}
if !c.Env["authIsAdmin"].(bool) && c.Env["authPlayer"].(uuid.UUID) != debt.Creditor {
return &appError{errors.New("Unauthorized"), "Must be creditor or admin to settle debt", 403}
}
err = player.SettleDebt(dUUID)
if err != nil {
return &appError{err, "Failed to settle debt", 500}
}
w.Header().Set("Location", "/players/"+pUUID.String()+"/debts")
w.WriteHeader(204)
return nil
}
示例2: updateCateringVote
func updateCateringVote(c web.C, w http.ResponseWriter, r *http.Request) *appError {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
cateringuuid, err := uuid.FromString(c.URLParams["uuid"])
playeruuid, err := uuid.FromString(c.URLParams["playeruuid"])
catering, err := caterings.CateringByUUID(cateringuuid)
if err != nil {
return &appError{err, "Cant find catering", 404}
}
tempInfo := new(caterings.Vote)
decoder := json.NewDecoder(r.Body)
if err := decoder.Decode(tempInfo); err != nil {
return &appError{err, "Invalid JSON", 400}
}
if err := catering.RemoveVote(playeruuid); err != nil {
return &appError{err, "Failed to remove old catering vote when updating", 500}
}
if err := catering.AddVote(playeruuid, tempInfo.Score); err != nil {
return &appError{err, "Failed to add updated catering vote", 500}
}
w.WriteHeader(204)
return nil
}
示例3: updatePlayer
func updatePlayer(c web.C, w http.ResponseWriter, r *http.Request) *appError {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
uuid, err := uuid.FromString(c.URLParams["uuid"])
player, err := players.PlayerByUUID(uuid)
if err != nil {
return &appError{err, "Cant find player", 404}
}
tempPlayer := new(players.Player)
decoder := json.NewDecoder(r.Body)
if err := decoder.Decode(tempPlayer); err != nil {
return &appError{err, "Invalid JSON", 400}
}
if err := player.SetActive(tempPlayer.Active); err != nil {
return &appError{err, "Failed to set active status", 500}
}
if err := player.SetNick(tempPlayer.Nick); err != nil {
return &appError{err, "Failed to set nick", 500}
}
if err := player.SetProfile(tempPlayer.Profile); err != nil {
return &appError{err, "Failed to set player profile", 500}
}
w.WriteHeader(204)
return nil
}
示例4: addPlayerQuote
func addPlayerQuote(c web.C, w http.ResponseWriter, r *http.Request) *appError {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
pUUID, err := uuid.FromString(c.URLParams["uuid"])
player, err := players.PlayerByUUID(pUUID)
if err != nil {
return &appError{err, "Cant find player", 404}
}
var q string
decoder := json.NewDecoder(r.Body)
if err := decoder.Decode(&q); err != nil {
return &appError{err, "Invalid JSON", 400}
}
if !c.Env["authIsAdmin"].(bool) && c.Env["authPlayer"].(uuid.UUID) == pUUID {
return &appError{errors.New("Unauthorized"), "Must be other player or admin to add quote", 403}
}
err = player.AddQuote(q)
if err != nil {
return &appError{err, "Failed to add quote", 500}
}
w.Header().Set("Location", "/players/"+pUUID.String())
w.WriteHeader(201)
return nil
}
示例5: setUserPassword
func setUserPassword(c web.C, w http.ResponseWriter, r *http.Request) *appError {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
pUUID, err := uuid.FromString(c.URLParams["uuid"])
if !c.Env["authIsAdmin"].(bool) && c.Env["authPlayer"].(uuid.UUID) != pUUID {
return &appError{errors.New("Unauthorized"), "Must be correct user or admin to set password", 403}
}
player, err := players.PlayerByUUID(pUUID)
if err != nil {
return &appError{err, "Cant find player", 404}
}
type PWUpdate struct {
Password string
}
pwupdate := new(PWUpdate)
decoder := json.NewDecoder(r.Body)
if err := decoder.Decode(pwupdate); err != nil {
return &appError{err, "Invalid JSON", 400}
}
if err := player.SetUserPassword(pwupdate.Password); err != nil {
return &appError{err, "Failed to set password for player", 500}
}
w.WriteHeader(204)
return nil
}
示例6: setUserForPlayer
func setUserForPlayer(c web.C, w http.ResponseWriter, r *http.Request) *appError {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
if !c.Env["authIsAdmin"].(bool) {
return &appError{errors.New("Unauthorized"), "Admins only", 403}
}
uuid, err := uuid.FromString(c.URLParams["uuid"])
player, err := players.PlayerByUUID(uuid)
if err != nil {
return &appError{err, "Cant find player", 404}
}
tempUser := new(players.User)
decoder := json.NewDecoder(r.Body)
if err := decoder.Decode(tempUser); err != nil {
return &appError{err, "Invalid JSON", 400}
}
user, err := players.UserByName(tempUser.Username)
if err != nil {
return &appError{err, "Cant find user", 400}
}
if err := player.SetUser(*user); err != nil {
return &appError{err, "Failed to set user for player", 500}
}
w.WriteHeader(204)
return nil
}
示例7: addPlayerDebt
func addPlayerDebt(c web.C, w http.ResponseWriter, r *http.Request) *appError {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
pUUID, err := uuid.FromString(c.URLParams["uuid"])
player, err := players.PlayerByUUID(pUUID)
if err != nil {
return &appError{err, "Cant find player", 404}
}
nDebt := new(players.Debt)
decoder := json.NewDecoder(r.Body)
if err := decoder.Decode(nDebt); err != nil {
return &appError{err, "Invalid JSON", 400}
}
if !c.Env["authIsAdmin"].(bool) &&
(c.Env["authPlayer"].(uuid.UUID) == pUUID ||
c.Env["authPlayer"].(uuid.UUID) != nDebt.Creditor) {
return &appError{errors.New("Unauthorized"), "Must be creditor or admin to add debt", 403}
}
err = player.AddDebt(*nDebt)
if err != nil {
return &appError{err, "Failed to add debt", 500}
}
w.Header().Set("Location", "/players/"+pUUID.String()+"/debts")
w.WriteHeader(201)
return nil
}
示例8: setUserAdmin
func setUserAdmin(c web.C, w http.ResponseWriter, r *http.Request) *appError {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
pUUID, err := uuid.FromString(c.URLParams["uuid"])
if !c.Env["authIsAdmin"].(bool) {
return &appError{errors.New("Unauthorized"), "Must be admin to set admin status", 403}
}
player, err := players.PlayerByUUID(pUUID)
if err != nil {
return &appError{err, "Cant find player", 404}
}
var adminState bool
decoder := json.NewDecoder(r.Body)
if err := decoder.Decode(&adminState); err != nil {
return &appError{err, "Invalid JSON", 400}
}
if err := player.SetUserAdmin(adminState); err != nil {
return &appError{err, "Failed to change settings for user", 500}
}
w.WriteHeader(204)
return nil
}
示例9: thoughtsGetHandler
// Handles the fetch of a particular thought from the map for now.
func thoughtsGetHandler(rw http.ResponseWriter, r *http.Request) {
log.Info("Received a call to fetch the thoughts")
vars := mux.Vars(r)
idString := vars["id"]
id, err := uuid.FromString(idString)
if err != nil {
log.WithFields(log.Fields{
"error": err,
}).Error("Invalid url param.")
httpError(rw, http.StatusBadRequest, err)
return
}
thought, err := tp.ThoughtStorage.GetThought(ThoughtsID{id})
if err != nil {
switch err {
case ErrNoRecordFound:
httpError(rw, http.StatusNotFound, err)
default:
httpError(rw, http.StatusInternalServerError, err)
}
return
}
resp, _ := json.Marshal(thought)
rw.Header().Set("Content-Type", "application/json")
rw.WriteHeader(http.StatusOK)
rw.Write(resp)
return
}
示例10: setPlayerGossip
func setPlayerGossip(c web.C, w http.ResponseWriter, r *http.Request) *appError {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
pUUID, err := uuid.FromString(c.URLParams["uuid"])
player, err := players.PlayerByUUID(pUUID)
if err != nil {
return &appError{err, "Cant find player", 404}
}
nGossip := make(map[string]string)
decoder := json.NewDecoder(r.Body)
if err := decoder.Decode(&nGossip); err != nil {
return &appError{err, "Invalid JSON", 400}
}
if !c.Env["authIsAdmin"].(bool) && c.Env["authPlayer"].(uuid.UUID) != pUUID {
return &appError{errors.New("Unauthorized"), "Must be player or admin to set gossip", 403}
}
err = player.SetGossip(nGossip)
if err != nil {
return &appError{err, "Failed to set gossip", 500}
}
w.WriteHeader(204)
return nil
}
示例11: getNewsItem
func getNewsItem(c web.C, w http.ResponseWriter, r *http.Request) *appError {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
uuid, err := uuid.FromString(c.URLParams["uuid"])
newsItem, err := news.NewsItemByUUID(uuid)
if err != nil {
return &appError{err, "Cant find the NewsItem", 404}
}
encoder := json.NewEncoder(w)
encoder.Encode(newsItem)
return nil
}
示例12: getTournament
func getTournament(c web.C, w http.ResponseWriter, r *http.Request) *appError {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
uuid, err := uuid.FromString(c.URLParams["uuid"])
tournament, err := tournaments.TournamentByUUID(uuid)
if err != nil {
return &appError{err, "Cant find tournament", 404}
}
encoder := json.NewEncoder(w)
encoder.Encode(tournament)
return nil
}
示例13: removeTournamentNoShow
func removeTournamentNoShow(c web.C, w http.ResponseWriter, r *http.Request) *appError {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
tID, err := uuid.FromString(c.URLParams["uuid"])
tournament, err := tournaments.TournamentByUUID(tID)
if err != nil {
return &appError{err, "Cant find tournament", 404}
}
pID, err := uuid.FromString(c.URLParams["playeruuid"])
if !c.Env["authIsAdmin"].(bool) && pID != c.Env["authPlayer"].(uuid.UUID) {
return &appError{errors.New("Unauthorized"), "Must be given player or admin to remove absentee", 403}
}
if err := tournament.RemoveNoShow(pID); err != nil {
return &appError{err, "Failed to remove absentee for tournament", 500}
}
w.WriteHeader(204)
return nil
}
示例14: getPlayerProfile
func getPlayerProfile(c web.C, w http.ResponseWriter, r *http.Request) *appError {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
uuid, err := uuid.FromString(c.URLParams["uuid"])
player, err := players.PlayerByUUID(uuid)
if err != nil {
return &appError{err, "Cant find player", 404}
}
encoder := json.NewEncoder(w)
encoder.Encode(player.Profile)
return nil
}
示例15: showPlayerDebt
func showPlayerDebt(c web.C, w http.ResponseWriter, r *http.Request) *appError {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
pUUID, err := uuid.FromString(c.URLParams["uuid"])
if !c.Env["authIsAdmin"].(bool) && c.Env["authPlayer"].(uuid.UUID) != pUUID {
return &appError{errors.New("Unauthorized"), "Must be player or admin to show debt", 403}
}
player, err := players.PlayerByUUID(pUUID)
if err != nil {
return &appError{err, "Cant find player", 404}
}
encoder := json.NewEncoder(w)
encoder.Encode(player.Debts)
return nil
}