本文整理匯總了Golang中github.com/henyouqian/lwutil.CheckMathod函數的典型用法代碼示例。如果您正苦於以下問題:Golang CheckMathod函數的具體用法?Golang CheckMathod怎麽用?Golang CheckMathod使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CheckMathod函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: listGame
func listGame(w http.ResponseWriter, r *http.Request) {
lwutil.CheckMathod(r, "POST")
rc := redisPool.Get()
defer rc.Close()
session, err := findSession(w, r, rc)
lwutil.CheckError(err, "err_auth")
appid := session.Appid
if appid == 0 {
lwutil.SendError("err_auth", "Please login with app secret")
}
// get game data
gameValues, err := redis.Values(rc.Do("hgetall", fmt.Sprintf("games/%d", appid)))
lwutil.CheckError(err, "")
games := make([]interface{}, 0, len(gameValues)/2)
for i, v := range gameValues {
if i%2 == 0 {
continue
}
var game interface{}
err = json.Unmarshal(v.([]byte), &game)
lwutil.CheckError(err, "")
games = append(games, game)
}
//reply
lwutil.WriteResponse(w, games)
}
示例2: authRegister
func authRegister(w http.ResponseWriter, r *http.Request) {
lwutil.CheckMathod(r, "POST")
// in
var in struct {
Username string
Password string
CountryAlpha2 string
SignCode uint32
}
err := lwutil.DecodeRequestBody(r, &in)
lwutil.CheckError(err, "err_decode_body")
if in.Username == "" || in.Password == "" {
lwutil.SendError("err_input", "")
}
pwsha := lwutil.Sha224(in.Password + passwordSalt)
// insert into db
res, err := authDB.Exec("INSERT INTO user_accounts (username, password, countryAlpha2, signCode) VALUES (?, ?, ?, ?)",
in.Username, pwsha, in.CountryAlpha2, in.SignCode)
lwutil.CheckError(err, "err_account_exists")
id, err := res.LastInsertId()
lwutil.CheckError(err, "")
// reply
reply := struct {
Userid int64
}{id}
lwutil.WriteResponse(w, reply)
}
示例3: authNewApp
func authNewApp(w http.ResponseWriter, r *http.Request) {
lwutil.CheckMathod(r, "POST")
session, err := findSession(w, r, nil)
lwutil.CheckError(err, "err_auth")
checkAdmin(session)
// input
var input struct {
Name string
}
err = lwutil.DecodeRequestBody(r, &input)
lwutil.CheckError(err, "err_decode_body")
if input.Name == "" {
lwutil.SendError("err_input", "input.Name empty")
}
// db
stmt, err := authDB.Prepare("INSERT INTO apps (name, secret) VALUES (?, ?)")
lwutil.CheckError(err, "")
secret := lwutil.GenUUID()
_, err = stmt.Exec(input.Name, secret)
lwutil.CheckError(err, "err_name_exists")
// reply
reply := struct {
Name string
Secret string
}{input.Name, secret}
lwutil.WriteResponse(w, reply)
}
示例4: dig
func dig(w http.ResponseWriter, r *http.Request) {
lwutil.CheckMathod(r, "POST")
rc := redisPool.Get()
defer rc.Close()
session, err := findSession(w, r, rc)
lwutil.CheckError(err, "err_auth")
appid := session.Appid
if appid == 0 {
lwutil.SendError("err_auth", "Please login with app secret")
}
// in
var in struct {
MatchId uint32
}
err = lwutil.DecodeRequestBody(r, &in)
lwutil.CheckError(err, "err_decode_body")
// out
out := struct {
Rank int64
Score int64
}{1, 2}
lwutil.WriteResponse(w, out)
}
示例5: authListApp
func authListApp(w http.ResponseWriter, r *http.Request) {
lwutil.CheckMathod(r, "POST")
session, err := findSession(w, r, nil)
lwutil.CheckError(err, "err_auth")
checkAdmin(session)
// db
rows, err := authDB.Query("SELECT name, secret FROM apps")
lwutil.CheckError(err, "")
type App struct {
Name string
Secret string
}
apps := make([]App, 0, 16)
var app App
for rows.Next() {
err = rows.Scan(&app.Name, &app.Secret)
lwutil.CheckError(err, "")
apps = append(apps, app)
}
lwutil.WriteResponse(w, apps)
}
示例6: benchJson
func benchJson(w http.ResponseWriter, r *http.Request) {
lwutil.CheckMathod(r, "GET")
str := []byte(`
{
"Name": "aa",
"Gameid": 885,
"Begin": "2013/04/06 23:43:24",
"End": "2013/05/06 23:43:24",
"Sort": 0
}
`)
in := struct {
Name string
Gameid uint32
Begin string
End string
Sort uint8
}{}
err := json.Unmarshal(str, &in)
lwutil.CheckError(err, "")
lwutil.WriteResponse(w, in)
}
示例7: delGame
func delGame(w http.ResponseWriter, r *http.Request) {
lwutil.CheckMathod(r, "POST")
rc := redisPool.Get()
defer rc.Close()
session, err := findSession(w, r, rc)
lwutil.CheckError(err, "err_auth")
checkAdmin(session)
appid := session.Appid
if appid == 0 {
lwutil.SendError("err_auth", "Please login with app secret")
}
// input
gameIds := make([]int, 0, 8)
err = lwutil.DecodeRequestBody(r, &gameIds)
lwutil.CheckError(err, "err_decode_body")
// redis
args := make([]interface{}, 1, 8)
args[0] = fmt.Sprintf("games/%d", appid)
for _, gameId := range gameIds {
args = append(args, gameId)
}
delNum, err := redis.Int(rc.Do("hdel", args...))
lwutil.CheckError(err, "")
// reply
lwutil.WriteResponse(w, delNum)
}
示例8: authSetInfo
func authSetInfo(w http.ResponseWriter, r *http.Request) {
lwutil.CheckMathod(r, "POST")
session, err := findSession(w, r, nil)
lwutil.CheckError(err, "err_auth")
// in
var in struct {
CountryCode uint32
SignCode uint32
}
err = lwutil.DecodeRequestBody(r, &in)
lwutil.CheckError(err, "err_decode_body")
if in.CountryCode == 0 || in.SignCode == 0 {
lwutil.SendError("err_input", "")
}
// insert into db
_, err = authDB.Exec("UPDATE user_accounts SET countryCode=?, signCode=? WHERE id=?",
in.CountryCode, in.SignCode, session.Userid)
lwutil.CheckError(err, "")
//new session
newSession(w, session.Userid, session.Username, session.Appid, in.CountryCode, in.SignCode, nil)
// out
lwutil.WriteResponse(w, in)
}
示例9: benchDBSingleSelect
func benchDBSingleSelect(w http.ResponseWriter, r *http.Request) {
lwutil.CheckMathod(r, "GET")
row := authDB.QueryRow("SELECT id FROM user_accounts WHERE username=?", "admin")
var userid uint32
err := row.Scan(&userid)
lwutil.CheckError(err, "")
lwutil.WriteResponse(w, userid)
}
示例10: newGame
func newGame(w http.ResponseWriter, r *http.Request) {
lwutil.CheckMathod(r, "POST")
rc := redisPool.Get()
defer rc.Close()
session, err := findSession(w, r, rc)
lwutil.CheckError(err, "err_auth")
checkAdmin(session)
appid := session.Appid
if appid == 0 {
lwutil.SendError("err_auth", "Please login with app secret")
}
// input
input := struct {
Id uint32
Name string
Sort string
}{}
err = lwutil.DecodeRequestBody(r, &input)
lwutil.CheckError(err, "err_decode_body")
if input.Id == 0 || input.Name == "" {
lwutil.SendError("err_input", "Missing Id or Name")
}
if input.Sort != SORT_ASC && input.Sort != SORT_DESC {
lwutil.SendError("err_input", "Invalid Sort, must be ASC or DESC")
}
//
game := Game{
input.Id,
input.Name,
input.Sort,
}
gameJson, err := json.Marshal(game)
lwutil.CheckError(err, "")
key := fmt.Sprintf("games/%d", appid)
_, err = rc.Do("hset", key, input.Id, gameJson)
lwutil.CheckError(err, "")
// reply
lwutil.WriteResponse(w, game)
}
示例11: delMatch
func delMatch(w http.ResponseWriter, r *http.Request) {
lwutil.CheckMathod(r, "POST")
rc := redisPool.Get()
defer rc.Close()
session, err := findSession(w, r, rc)
lwutil.CheckError(err, "err_auth")
checkAdmin(session)
appid := session.Appid
if appid == 0 {
lwutil.SendError("err_auth", "Please login with app secret")
}
//input
matchIds := make([]int, 0, 8)
err = lwutil.DecodeRequestBody(r, &matchIds)
lwutil.CheckError(err, "err_decode_body")
//redis
key := fmt.Sprintf("matchesInApp/%d", appid)
params := make([]interface{}, 0, 8)
params = append(params, key)
matchIdsItf := make([]interface{}, len(matchIds))
for i, v := range matchIds {
matchIdsItf[i] = v
}
params = append(params, matchIdsItf...)
rc.Send("zrem", params...)
args := make([]interface{}, len(matchIds)+1)
args[0] = "matches"
for i, matchId := range matchIds {
key = fmt.Sprintf("%d+%d", appid, matchId)
args[i+1] = key
}
rc.Send("hdel", args...)
rc.Flush()
_, err = rc.Receive()
lwutil.CheckError(err, "")
delNum, err := rc.Receive()
lwutil.CheckError(err, "")
//reply
lwutil.WriteResponse(w, delNum)
}
示例12: benchJson2
func benchJson2(w http.ResponseWriter, r *http.Request) {
lwutil.CheckMathod(r, "GET")
str := []byte(`
{
"Name": "aa"
}
`)
in := struct {
Name string
}{}
err := json.Unmarshal(str, &in)
lwutil.CheckError(err, "")
lwutil.WriteResponse(w, in)
}
示例13: benchLogin
func benchLogin(w http.ResponseWriter, r *http.Request) {
lwutil.CheckMathod(r, "GET")
// input
in := struct {
Username string
Password string
Appsecret string
}{Username: "admin", Password: "admin"}
if in.Username == "" || in.Password == "" {
lwutil.SendError("err_input", "")
}
pwsha := lwutil.Sha224(in.Password + passwordSalt)
// get userid
row := authDB.QueryRow("SELECT id, countryCode, signCode FROM user_accounts WHERE username=? AND password=?", in.Username, pwsha)
var userid uint64
var countryCode, signCode uint32
err := row.Scan(&userid, &countryCode, &signCode)
lwutil.CheckError(err, "")
// get appid
appid := uint32(0)
if in.Appsecret != "" {
row = authDB.QueryRow("SELECT id FROM apps WHERE secret=?", in.Appsecret)
err = row.Scan(&appid)
lwutil.CheckError(err, "")
}
// new session
rc := redisPool.Get()
defer rc.Close()
usertoken, err := newSession(w, userid, in.Username, appid, 0, 0, rc)
lwutil.CheckError(err, "")
// reply
reply := struct {
Usertoken string
Appid uint32
}{usertoken, appid}
lwutil.WriteResponse(w, reply)
}
示例14: getMyRank
func getMyRank(w http.ResponseWriter, r *http.Request) {
lwutil.CheckMathod(r, "POST")
rc := redisPool.Get()
defer rc.Close()
session, err := findSession(w, r, rc)
lwutil.CheckError(err, "err_auth")
appid := session.Appid
if appid == 0 {
lwutil.SendError("err_auth", "Please login with app secret")
}
// in
var in struct {
MatchId uint32
}
err = lwutil.DecodeRequestBody(r, &in)
lwutil.CheckError(err, "err_decode_body")
keyLeaderboard := makeLeaderboardKey(in.MatchId)
rc.Send("zrank", keyLeaderboard, session.Userid)
rc.Send("zscore", keyLeaderboard, session.Userid)
rc.Flush()
rank, err := redis.Int64(rc.Receive())
score := int64(0)
if err == redis.ErrNil {
rank = 0
} else {
lwutil.CheckError(err, "")
if err == nil {
rank += 1
}
score, err = redis.Int64(rc.Receive())
lwutil.CheckError(err, "")
}
// out
out := struct {
Rank int64
Score int64
}{rank, score}
lwutil.WriteResponse(w, out)
}
示例15: benchRedisGet
func benchRedisGet(w http.ResponseWriter, r *http.Request) {
lwutil.CheckMathod(r, "GET")
rc := redisPool.Get()
defer rc.Close()
rc.Send("set", "foo", "yes")
rc.Send("get", "foo")
rc.Flush()
rc.Receive()
foo, err := redis.String(rc.Receive())
lwutil.CheckError(err, "")
// foo, err := redis.String(rc.Do("get", "foo"))
// lwutil.CheckError(err, "")
lwutil.WriteResponse(w, foo)
}