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


Golang LocalDB.GetAPISkills方法代碼示例

本文整理匯總了Golang中github.com/backerman/eveindy/pkg/db.LocalDB.GetAPISkills方法的典型用法代碼示例。如果您正苦於以下問題:Golang LocalDB.GetAPISkills方法的具體用法?Golang LocalDB.GetAPISkills怎麽用?Golang LocalDB.GetAPISkills使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/backerman/eveindy/pkg/db.LocalDB的用法示例。


在下文中一共展示了LocalDB.GetAPISkills方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: XMLAPIKeysHandlers

// XMLAPIKeysHandlers returns web handler functions that provide information on
// the user's API keys that have been registered with this application.
func XMLAPIKeysHandlers(localdb db.LocalDB, sess server.Sessionizer) (list, delete, add, refresh web.HandlerFunc) {
	// charRefresh refreshes the characters associated with an API key and returns
	// the current list of characters via the passed responseWriter.
	charRefresh := func(s *db.Session, key *db.XMLAPIKey, w http.ResponseWriter) {
		toons, err := localdb.GetAPICharacters(s.User, *key)
		if err != nil {
			http.Error(w, `{"status": "Error", "error": "Database connection error (add characters)"}`,
				http.StatusInternalServerError)
			return
		}
		for _, toon := range toons {
			// Update skills for this character.
			err = localdb.GetAPISkills(*key, toon.ID)
			if err != nil {
				http.Error(w, `{"status": "Error", "error": "Database connection error (add skills)"}`,
					http.StatusInternalServerError)
				return
			}

			// Update standings.
			err = localdb.GetAPIStandings(*key, toon.ID)
			if err != nil {
				http.Error(w, `{"status": "Error", "error": "Database connection error (add standings)"}`,
					http.StatusInternalServerError)
				return
			}

			// Update assets and blueprints.
			err = localdb.GetAssetsBlueprints(*key, toon.ID)
			if err != nil {
				http.Error(w, `{"status": "Error", "error": "Database connection error (add assets)"}`,
					http.StatusInternalServerError)
				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.
//.........這裏部分代碼省略.........
開發者ID:backerman,項目名稱:eveindy,代碼行數:101,代碼來源:user.go


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