本文整理汇总了Golang中github.com/m4rw3r/uuid.FromString函数的典型用法代码示例。如果您正苦于以下问题:Golang FromString函数的具体用法?Golang FromString怎么用?Golang FromString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FromString函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: LoadAll
func (rls *RedisLocationStorage) LoadAll() ([]*Location, error) {
var locations []*Location
conn := rls.pool.Get()
defer conn.Close()
b, err := redigo.Strings(conn.Do("SMEMBERS", "locations"))
if err != nil {
return nil, err
}
for _, location := range b {
uuid, _ := uuid.FromString(location)
l, err := rls.Load(uuid)
if err != nil {
return nil, err
}
locations = append(locations, l)
}
return locations, nil
}
开发者ID:ckpt,项目名称:backend-services,代码行数:18,代码来源:redisstorage.go
示例17: LoadBySeason
func (rts *RedisTournamentStorage) LoadBySeason(season int) (Tournaments, error) {
var tournaments Tournaments
conn := rts.pool.Get()
defer conn.Close()
b, err := redigo.Strings(conn.Do("SMEMBERS", fmt.Sprintf("season:%d:tournaments", season)))
if err != nil {
return nil, err
}
for _, tournament := range b {
uuid, _ := uuid.FromString(tournament)
t, err := rts.Load(uuid)
if err != nil {
return nil, err
}
tournaments = append(tournaments, t)
}
return tournaments, nil
}
开发者ID:ckpt,项目名称:backend-services,代码行数:18,代码来源:redisstorage.go
示例18: updateTournamentInfo
func updateTournamentInfo(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}
}
tempInfo := new(tournaments.Info)
decoder := json.NewDecoder(r.Body)
if err := decoder.Decode(tempInfo); err != nil {
return &appError{err, "Invalid JSON", 400}
}
if err := tournament.UpdateInfo(*tempInfo); err != nil {
return &appError{err, "Failed to update tournament info", 500}
}
w.WriteHeader(204)
return nil
}
开发者ID:ckpt,项目名称:backend-services,代码行数:19,代码来源:tournament_handlers.go
示例19: LoadUser
func (rps *RedisPlayerStorage) LoadUser(username string) (*User, error) {
conn := rps.pool.Get()
defer conn.Close()
player, err := redigo.String(conn.Do("GET", fmt.Sprintf("user:%s:player", username)))
if err != nil {
return nil, err
}
pwhash, err := redigo.String(conn.Do("GET", fmt.Sprintf("user:%s:pwhash", username)))
if err != nil {
return nil, err
}
uuid, _ := uuid.FromString(player)
p, err := rps.Load(uuid)
if err != nil {
return nil, err
}
p.User.password = pwhash
return &p.User, nil
}
开发者ID:ckpt,项目名称:backend-services,代码行数:20,代码来源:redisstorage.go
示例20: resetPlayerGossip
func resetPlayerGossip(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}
}
if !c.Env["authIsAdmin"].(bool) && c.Env["authPlayer"].(uuid.UUID) != pUUID {
return &appError{errors.New("Unauthorized"), "Must be admin or player to reset gossip", 403}
}
err = player.ResetGossip()
if err != nil {
return &appError{err, "Failed to reset gossip", 500}
}
w.WriteHeader(204)
return nil
}
开发者ID:ckpt,项目名称:backend-services,代码行数:20,代码来源:player_handlers.go
注:本文中的github.com/m4rw3r/uuid.FromString函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论