本文整理汇总了Golang中github.com/backerman/eveindy/pkg/db.LocalDB.AddAPIKey方法的典型用法代码示例。如果您正苦于以下问题:Golang LocalDB.AddAPIKey方法的具体用法?Golang LocalDB.AddAPIKey怎么用?Golang LocalDB.AddAPIKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/backerman/eveindy/pkg/db.LocalDB
的用法示例。
在下文中一共展示了LocalDB.AddAPIKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: XMLAPIKeysHandlers
//.........这里部分代码省略.........
log.Printf("Got error in GetAssets: %v", err)
return
}
}
response := struct {
Status string `json:"status"`
Characters []evego.Character `json:"characters"`
}{
Status: "OK",
Characters: toons,
}
responseJSON, err := json.Marshal(response)
w.Write(responseJSON)
return
}
list = func(c web.C, w http.ResponseWriter, r *http.Request) {
s := sess.GetSession(&c, w, r)
userKeys, err := localdb.APIKeys(s.User)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
w.Write([]byte(`{"status": "Error"}`))
return
}
userKeysJSON, err := json.Marshal(userKeys)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
w.Write([]byte(`{"status": "Error"}`))
return
}
w.Write(userKeysJSON)
}
delete = func(c web.C, w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
http.Error(w, "This function must be called with the POST method",
http.StatusMethodNotAllowed)
w.Write([]byte(`{"status": "Error"}`))
return
}
s := sess.GetSession(&c, w, r)
keyID, _ := strconv.Atoi(c.URLParams["keyid"])
err := localdb.DeleteAPIKey(s.User, keyID)
if err != nil {
http.Error(w, "Database connection error", http.StatusInternalServerError)
w.Write([]byte(`{"status": "Error"}`))
return
}
w.Write([]byte(`{"status": "OK"}`))
return
}
add = func(c web.C, w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
http.Error(w, "This function must be called with the POST method",
http.StatusMethodNotAllowed)
w.Write([]byte(`{"status": "Error"}`))
return
}
s := sess.GetSession(&c, w, r)
key, err := unmarshalKey(r, w)
if err != nil {
return
}
// Ensure that this key is added under the session's user's account.
key.User = s.User
err = localdb.AddAPIKey(*key)
if err != nil {
http.Error(w, "Database connection error (add key)", http.StatusInternalServerError)
w.Write([]byte(`{"status": "Error"}`))
return
}
charRefresh(s, key, w)
return
}
refresh = func(c web.C, w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
http.Error(w, "This function must be called with the POST method",
http.StatusMethodNotAllowed)
w.Write([]byte(`{"status": "Error"}`))
return
}
s := sess.GetSession(&c, w, r)
key, err := unmarshalKey(r, w)
if err != nil {
return
}
// Ensure that this key is added under the session's user's account.
key.User = s.User
charRefresh(s, key, w)
return
}
return
}