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


Golang ContactDB.SearchByStationId方法代碼示例

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


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

示例1: stationContactsHandler

func stationContactsHandler(
	cdb *db.ContactDB, sdb *db.StationDB,
	w http.ResponseWriter, r *http.Request, user userView) {

	id := r.URL.Query().Get("id")
	if id == "" {
		http.Error(w, "'id' param missing", http.StatusBadRequest)
		return
	}

	s, err := sdb.Lookup(id)
	if err != nil {
		log.Printf("Sation DB lookup error: %s", err.Error())
		http.Error(w, "", http.StatusInternalServerError)
		return
	}
	if s == nil {
		http.NotFound(w, r)
		return
	}

	if s.Userid == nil || user.Id != *s.Userid {
		http.Error(w, "Unauthorized", http.StatusUnauthorized)
		return
	}

	contacts, err := cdb.SearchByStationId(id, 100)
	if err != nil {
		log.Printf("SearchByStationId error: %s", err.Error())
		http.Error(w, "", http.StatusInternalServerError)
		return
	}

	var cv contactsView
	cv.Title = *s.Name
	cv.C = contacts

	c := NewRenderContext(user, cv)
	err = contactsTemplate.Get().ExecuteTemplate(w, "contacts.html", c)
	if err != nil {
		log.Printf("Error rendering contacts view: %s", err.Error())
		http.Error(w, "", http.StatusInternalServerError)
		return
	}
}
開發者ID:tstranex,項目名稱:carpcomm,代碼行數:45,代碼來源:contacts.go

示例2: GetStationContext

func GetStationContext(s *pb.Station, userid string,
	m *rpc.Client, userdb *db.UserDB, cdb *db.ContactDB) (
	sc stationContext) {
	sc.S = s
	sc.IsOwner = (userid == *s.Userid)

	var args mux.StationStatusArgs
	args.StationId = *s.Id
	var status mux.StationStatusResult
	err := m.Call("Coordinator.StationStatus", args, &status)
	if err != nil {
		sc.IsOnline = false
	} else {
		sc.IsOnline = status.IsConnected
	}

	sc.CurrentTime = time.Now().UTC().Format(TimeFormat)
	passes, _ := scheduler.PassPredictions(s)
	passViews := make([]predictionView, 0)
	for _, pass := range passes {
		var pv predictionView
		FillPredictionView(pass, &pv)
		// Don't display different modes of the same satellite.
		if len(passViews) == 0 || passViews[len(passViews)-1] != pv {
			passViews = append(passViews, pv)
		}
	}
	sc.NextPasses = passViews

	sc.Operator = LookupUserView(userdb, *s.Userid)

	if sc.IsOwner {
		c, err := cdb.SearchByStationId(*s.Id, 5)
		if err != nil {
			log.Printf("SearchByStationId error: %s", err.Error())
			// This is not a fatal error.
		}
		sc.Contacts = c
	}

	return sc
}
開發者ID:tstranex,項目名稱:carpcomm,代碼行數:42,代碼來源:stations.go


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