當前位置: 首頁>>代碼示例>>Golang>>正文


Golang uuid.FromString函數代碼示例

本文整理匯總了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
}
開發者ID:ckpt,項目名稱:backend-services,代碼行數:27,代碼來源:player_handlers.go

示例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
}
開發者ID:ckpt,項目名稱:backend-services,代碼行數:25,代碼來源:catering_handlers.go

示例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
}
開發者ID:ckpt,項目名稱:backend-services,代碼行數:25,代碼來源:player_handlers.go

示例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
}
開發者ID:ckpt,項目名稱:backend-services,代碼行數:27,代碼來源:player_handlers.go

示例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
}
開發者ID:ckpt,項目名稱:backend-services,代碼行數:29,代碼來源:player_handlers.go

示例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
}
開發者ID:ckpt,項目名稱:backend-services,代碼行數:26,代碼來源:player_handlers.go

示例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
}
開發者ID:ckpt,項目名稱:backend-services,代碼行數:29,代碼來源:player_handlers.go

示例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
}
開發者ID:ckpt,項目名稱:backend-services,代碼行數:25,代碼來源:player_handlers.go

示例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
}
開發者ID:babbarshaer,項目名稱:scatter-brain,代碼行數:36,代碼來源:server.go

示例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
}
開發者ID:ckpt,項目名稱:backend-services,代碼行數:26,代碼來源:player_handlers.go

示例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
}
開發者ID:ckpt,項目名稱:backend-services,代碼行數:11,代碼來源:news_handlers.go

示例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
}
開發者ID:ckpt,項目名稱:backend-services,代碼行數:11,代碼來源:tournament_handlers.go

示例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
}
開發者ID:ckpt,項目名稱:backend-services,代碼行數:20,代碼來源:tournament_handlers.go

示例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
}
開發者ID:ckpt,項目名稱:backend-services,代碼行數:11,代碼來源:player_handlers.go

示例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
}
開發者ID:ckpt,項目名稱:backend-services,代碼行數:17,代碼來源:player_handlers.go


注:本文中的github.com/m4rw3r/uuid.FromString函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。