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


Golang db.StationDB類代碼示例

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


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

示例1: consolePageHandler

func consolePageHandler(sdb *db.StationDB, contactdb *db.ContactDB,
	mux *rpc.Client,
	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
	}

	station, err := sdb.Lookup(id)
	if err != nil {
		log.Printf("Error looking up station: %s", err.Error())
		http.Error(w, "", http.StatusInternalServerError)
		return
	}

	auth, _ := canOperateStation(sdb, id, user.Id)
	if !auth {
		http.Error(w, "Not authorized", http.StatusUnauthorized)
		return
	}

	var cv consoleViewContext
	cv.S = *station
	cv.Satellites = fillSatOptions()
	c := NewRenderContext(user, cv)
	err = consoleTemplate.Get().ExecuteTemplate(
		w, "station_console.html", c)
	if err != nil {
		log.Printf("Error rendering station console: %s", err.Error())
		http.Error(w, "", http.StatusInternalServerError)
		return
	}
}
開發者ID:tstranex,項目名稱:carpcomm,代碼行數:35,代碼來源:console.go

示例2: RestoreStationsTable

func RestoreStationsTable(input *db.RecordReader, output *db.StationDB) error {
	for {
		rec, err := input.ReadRecord()
		if err == io.EOF {
			break
		} else if err != nil {
			log.Printf("Error reading record: %s", err.Error())
			return err
		}

		s := &pb.Station{}
		err = proto.Unmarshal(rec, s)
		if err != nil {
			log.Printf("Error parsing record: %s", err.Error())
			return err
		}

		err = output.Store(s)
		if err != nil {
			log.Printf("Error writing record: %s", err.Error())
			return err
		}

		fmt.Printf(".")
	}
	fmt.Printf("\n")

	log.Printf("Stations table restored.")
	return nil
}
開發者ID:tstranex,項目名稱:carpcomm,代碼行數:30,代碼來源:dbtool.go

示例3: deleteStationHandler

func deleteStationHandler(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("Station DB lookup error: %s", err.Error())
		http.Error(w, "", http.StatusInternalServerError)
		return
	}

	if s == nil || *s.Userid != user.Id {
		http.NotFound(w, r)
		return
	}

	err = sdb.Delete(id)
	if err != nil {
		log.Printf("Station DB delete error: %s", err.Error())
		http.Error(w, "", http.StatusInternalServerError)
		return
	}

	// Success
	http.Redirect(w, r, "/home", http.StatusFound)
}
開發者ID:tstranex,項目名稱:carpcomm,代碼行數:31,代碼來源:stations.go

示例4: homeHandler

func homeHandler(stationdb *db.StationDB, m *rpc.Client,
	w http.ResponseWriter, r *http.Request, user userView) {
	log.Printf("userid: %s", user.Id)

	hc := homeContext{}

	n, err := stationdb.NumStations()
	if err != nil {
		n = -1
	}
	hc.NumStations = n

	hc.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.
	}

	var args mux.StationCountArgs
	var count mux.StationCountResult
	err = m.Call("Coordinator.StationCount", args, &count)
	if err != nil {
		count.Count = -1
	}
	hc.NumOnlineStations = count.Count

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

示例5: stationViewHandler

func stationViewHandler(sdb *db.StationDB, m *rpc.Client, userdb *db.UserDB,
	contactdb *db.ContactDB,
	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.Capabilities == nil {
		s.Capabilities = &pb.Capabilities{}
	}

	sc := GetStationContext(s, user.Id, m, userdb, contactdb)

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

示例6: editStationHandler

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

	log.Printf("method: %s", r.Method)

	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("Station DB lookup error: %s", err.Error())
		http.Error(w, "", http.StatusInternalServerError)
		return
	}
	if s == nil || *s.Userid != user.Id {
		http.NotFound(w, r)
		return
	}

	if s.Capabilities == nil {
		s.Capabilities = &pb.Capabilities{}
	}

	if r.Method == "POST" {
		editStationPOST(sdb, s, w, r, user)
	} else {
		editStationGET(s, w, r, user)
	}
}
開發者ID:tstranex,項目名稱:carpcomm,代碼行數:32,代碼來源:stations.go

示例7: canOperateStation

func canOperateStation(sdb *db.StationDB, station_id, userid string) (
	bool, error) {
	owner, err := sdb.GetStationUserId(station_id)
	if err != nil {
		log.Printf("Error looking up station: %s", err.Error())
		return false, err
	}
	return owner == userid, nil
}
開發者ID:tstranex,項目名稱:carpcomm,代碼行數:9,代碼來源:console.go

示例8: AuthenticateStation

func AuthenticateStation(sdb *db.StationDB, id, secret string) (bool, error) {
	s, err := sdb.Lookup(id)
	if err != nil {
		return false, err
	}
	if s == nil {
		return false, nil
	}
	return *s.Id == id && *s.Secret == secret, nil
}
開發者ID:tstranex,項目名稱:carpcomm,代碼行數:10,代碼來源:auth.go

示例9: renderUserProfile

func renderUserProfile(
	cdb *db.ContactDB, stationdb *db.StationDB,
	w http.ResponseWriter, r *http.Request, user userView, u *pb.User) {
	// TODO: It would be better if we could restrict to contacts which
	// have telemetry.
	contacts, err := cdb.SearchByUserId(*u.Id, 100)
	if err != nil {
		log.Printf("cdb.SearchByUserId error: %s", err.Error())
		// Continue since this isn't a critical error.
	}
	heard_satellite_ids := make(map[string]bool)
	for _, c := range contacts {
		if c.SatelliteId == nil {
			continue
		}
		for _, b := range c.Blob {
			if b.Format != nil &&
				*b.Format == pb.Contact_Blob_DATUM {
				heard_satellite_ids[*c.SatelliteId] = true
				break
			}
		}
	}

	var pv profileView
	pv.User = u
	pv.IsOwner = (*u.Id == user.Id)
	pv.HeardSatellites = make([]*pb.Satellite, 0)
	for satellite_id, _ := range heard_satellite_ids {
		pv.HeardSatellites = append(pv.HeardSatellites,
			db.GlobalSatelliteDB().Map[satellite_id])
	}

	stations, err := stationdb.UserStations(*u.Id)
	if err != nil {
		log.Printf("Error getting user stations: %s", err.Error())
		// Continue rendering since it's not a critial error.
	}
	pv.Stations = make([]*pb.Station, 0)
	for _, s := range stations {
		if s.Lat != nil && s.Lng != nil {
			pv.Stations = append(pv.Stations, s)
		}
	}

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

示例10: stationKMLHandler

func stationKMLHandler(sdb *db.StationDB,
	w http.ResponseWriter, r *http.Request) {
	stations, err := sdb.AllStations()
	if err != nil {
		log.Printf("Station DB AllStations error: %s", err.Error())
		http.Error(w, "", http.StatusInternalServerError)
		return
	}

	err = kmlTemplate.ExecuteTemplate(w, "stations.kml", stations)
	if err != nil {
		log.Printf("Error rendering station kml map: %s", err.Error())
		http.Error(w, "", http.StatusInternalServerError)
		return
	}
}
開發者ID:tstranex,項目名稱:carpcomm,代碼行數:16,代碼來源:stations.go

示例11: 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

示例12: addStationHandler

func addStationHandler(sdb *db.StationDB,
	w http.ResponseWriter, r *http.Request, user userView) {
	station, err := db.NewStation(user.Id)
	if err != nil {
		log.Printf("Station DB NewStation error: %s", err.Error())
		http.Error(w, "", http.StatusInternalServerError)
		return
	}

	if err = sdb.Store(station); err != nil {
		log.Printf("Station DB Store error: %s", err.Error())
		http.Error(w, "", http.StatusInternalServerError)
		return
	}

	redirect := stationUrl("/station/edit", *station.Id)
	http.Redirect(w, r, redirect, http.StatusFound)
}
開發者ID:tstranex,項目名稱:carpcomm,代碼行數:18,代碼來源:stations.go

示例13: StartNewConsoleContact

// satellite_id can be empty if unknown
func StartNewConsoleContact(stationdb *db.StationDB, contactdb *db.ContactDB,
	station_id, user_id, satellite_id string) (
	id string, err error) {

	station, err := stationdb.Lookup(station_id)
	if err != nil {
		return "", err
	}
	if station == nil {
		return "", errors.New(
			fmt.Sprintf("Unknown station: %s", station_id))
	}

	s, err := NewContact(station, user_id, &satellite_id)
	if err != nil {
		return "", err
	}

	if err = contactdb.Store(s); err != nil {
		return "", err
	}

	return *s.Id, nil
}
開發者ID:tstranex,項目名稱:carpcomm,代碼行數:25,代碼來源:populate.go

示例14: postPacketHandler

func postPacketHandler(
	sdb *db.StationDB, cdb *db.ContactDB,
	w http.ResponseWriter, r *http.Request) {
	data, err := ioutil.ReadAll(r.Body)
	r.Body.Close()
	if err != nil {
		log.Printf("postPacketHandler: Error reading post body: %s",
			err.Error())
		http.Error(w, "Error reading post body",
			http.StatusInternalServerError)
		return
	}

	var req PostPacketRequest
	if err := json.Unmarshal(data, &req); err != nil {
		log.Printf("postPacketHandler: JSON decode error: %s",
			err.Error())
		http.Error(w, "Error decoding JSON data.",
			http.StatusBadRequest)
		return
	}

	log.Printf("request: %v", req)

	frame, err := base64.StdEncoding.DecodeString(req.FrameBase64)
	if err != nil {
		log.Printf("postPacketHandler: base64 decode error: %s",
			err.Error())
		http.Error(w, "Error decoding base64 frame.",
			http.StatusBadRequest)
		return
	}

	if req.StationId == "" {
		http.Error(w, "Missing station_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.StatusInternalServerError)
		return
	}

	contact, poperr := contacts.PopulateContact(
		req.SatelliteId,
		req.Timestamp,
		req.Format,
		frame,
		"",
		req.StationSecret,
		station)
	if poperr != nil {
		poperr.HttpError(w)
		return
	}

	log.Printf("Storing contact: %s", contact)

	err = cdb.Store(contact)
	if err != nil {
		log.Printf("Error storing contact: %s", err.Error())
		http.Error(w, "", http.StatusInternalServerError)
		return
	}

	w.WriteHeader(http.StatusOK)
	// Do we need to set content-length?
}
開發者ID:tstranex,項目名稱:carpcomm,代碼行數:69,代碼來源:packets.go

示例15: 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)
	}
//.........這裏部分代碼省略.........
開發者ID:tstranex,項目名稱:carpcomm,代碼行數:101,代碼來源:packets.go


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