本文整理匯總了Golang中carpcomm/db.ContactDB.SearchBySatelliteId方法的典型用法代碼示例。如果您正苦於以下問題:Golang ContactDB.SearchBySatelliteId方法的具體用法?Golang ContactDB.SearchBySatelliteId怎麽用?Golang ContactDB.SearchBySatelliteId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類carpcomm/db.ContactDB
的用法示例。
在下文中一共展示了ContactDB.SearchBySatelliteId方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getLatestIQDataHandler
func getLatestIQDataHandler(
sdb *db.StationDB, cdb *db.ContactDB,
w http.ResponseWriter, r *http.Request) {
log.Printf("Request: %s", r.URL.String())
req, err := parseGetLatestIQDataRequest(r.URL.Query())
if err != nil {
log.Printf("getLatestIQDataHandler: "+
"parse request error: %s", err.Error())
http.Error(w, "Error parsing request.",
http.StatusBadRequest)
return
}
sat := db.GlobalSatelliteDB().Map[req.SatelliteId]
if sat == nil {
http.Error(w, "Unknown satellite_id.", http.StatusBadRequest)
return
}
station, err := sdb.Lookup(req.StationId)
if err != nil {
log.Printf("Error looking up station: %s", err.Error())
http.Error(w, "", http.StatusUnauthorized)
return
}
if station == nil {
log.Printf("Error looking up station.")
http.Error(w, "", http.StatusUnauthorized)
return
}
// Authenticate the station.
if station.Secret == nil || *station.Secret != req.StationSecret {
log.Printf("Authentication failed.")
http.Error(w, "", http.StatusUnauthorized)
return
}
// Make sure that the user is authorized for the satellite.
found_good_id := false
for _, station_id := range sat.AuthorizedStationId {
if station_id == *station.Id {
found_good_id = true
}
}
if !found_good_id {
log.Printf("Authentication failed.")
http.Error(w, "", http.StatusUnauthorized)
return
}
contacts, err := cdb.SearchBySatelliteId(req.SatelliteId, req.Limit)
if err != nil {
log.Printf("getLatestIQDataHandler: "+
"SearchBySatelliteId error: %s", err.Error())
http.Error(w, "", http.StatusInternalServerError)
return
}
packets := make(GetLatestIQDataResponse, 0)
for _, c := range contacts {
if c.StartTimestamp == nil {
continue
}
timestamp := *c.StartTimestamp
for _, b := range c.Blob {
if len(packets) >= req.Limit {
continue
}
if b.Format == nil ||
*b.Format != pb.Contact_Blob_IQ {
continue
}
var p IQLink
p.Timestamp = timestamp
p.URL = scheduler.GetStreamURL(*c.Id)
if b.IqParams != nil {
if b.IqParams.Type != nil {
p.Type = b.IqParams.Type.String()
}
if b.IqParams.SampleRate != nil {
p.SampleRate = int(
*b.IqParams.SampleRate)
}
}
packets = append(packets, p)
}
}
json_body, err := json.Marshal(packets)
if err != nil {
log.Printf("json Marshal error: %s", err.Error())
http.Error(w, "", http.StatusInternalServerError)
}
//.........這裏部分代碼省略.........
示例2: satelliteViewHandler
func satelliteViewHandler(
cdb *db.ContactDB, userdb *db.UserDB, stationdb *db.StationDB,
commentdb *db.CommentDB,
w http.ResponseWriter, r *http.Request, user userView) {
if len(r.URL.Path) < len(satelliteURLPrefix) {
http.Error(w, "Invalid path", http.StatusBadRequest)
return
}
id := r.URL.Path[len(satelliteURLPrefix):]
sat := db.GlobalSatelliteDB().Map[id]
if sat == nil {
http.NotFound(w, r)
return
}
// TODO: It would be better if we could restrict to contacts which
// have telemetry.
contacts, err := cdb.SearchBySatelliteId(id, 100)
if err != nil {
log.Printf("cdb.SearchBySatelliteId error: %s", err.Error())
// Continue since this isn't a critical error.
}
t := make([]pb.TelemetryDatum, 0)
var latest_contact *contactView
for _, c := range contacts {
for _, b := range c.Blob {
if b.Format != nil &&
*b.Format == pb.Contact_Blob_DATUM {
t = append(t, *b.Datum)
if latest_contact == nil {
latest_contact = fillContactView(
*c, userdb)
}
}
}
}
sv := satelliteViewContext{}
sv.S = sat
if sat.Schema != nil {
t := fe_telemetry.RenderTelemetry(*sat.Schema, t, "en")
if len(t) > 0 {
sv.TelemetryHead = t[0]
}
if len(t) > 1 {
sv.TelemetryTail = t[1:]
}
}
sv.LatestContact = latest_contact
sv.Comments, _ = LoadCommentsByObjectId(
satelliteObjectId(id), commentdb, userdb)
sv.Stations, err = stationdb.UserStations(user.Id)
if err != nil {
log.Printf("Error getting user stations: %s", err.Error())
// Continue rendering since it's not a critial error.
}
c := NewRenderContext(user, &sv)
err = satelliteViewTemplate.Get().ExecuteTemplate(
w, "satellite.html", c)
if err != nil {
log.Printf("Error rendering satellite view: %s", err.Error())
http.Error(w, "", http.StatusInternalServerError)
return
}
}