Exemplo n.º 1
0
// topics
func GetTopics(rw http.ResponseWriter, req *http.Request) {
	token := req.FormValue("token")
	callback := req.FormValue("callback")

	output, err := SvcSns.ListTopics(&sns.ListTopicsInput{NextToken: aws.String(token)})
	if err != nil {
		midutil.LogAWSRequestErr(rw, req, err)
		return
	}

	if !midutil.IsNullOrEmpty(&callback) {
		Render.JSONP(rw, http.StatusOK, callback, output)
	} else {
		Render.JSON(rw, http.StatusOK, output)
	}

}
Exemplo n.º 2
0
// by time range: play/{topic}?start=12345&end=67890
func Playback(rw http.ResponseWriter, req *http.Request) {
	vars := mux.Vars(req)
	callback := req.FormValue("callback")

	// query db for playback list
	topic := vars["topic"]
	startTime := req.FormValue("start")
	endTime := req.FormValue("end")

	var queryInput *dynamodb.QueryInput
	lastKey := map[string]*dynamodb.AttributeValue{}

	lastKey = nil
	for {
		log.Println("topic:", topic)
		log.Println("startTime:", startTime)
		log.Println("endTime:", endTime)
		queryInput = prepareQuery(&topic, &startTime, &endTime, &lastKey)

		resp, err := SvcDynamo.Query(queryInput)

		if err != nil {
			midutil.LogAWSRequestErr(rw, req, err)
			return
		}

		processResponse(resp)
		lastKey = resp.LastEvaluatedKey

		if lastKey == nil {
			if !midutil.IsNullOrEmpty(&callback) {
				Render.JSONP(rw, http.StatusOK, callback, resp)
			} else {
				Render.JSON(rw, http.StatusOK, resp)
			}
			break
		} else {
			log.Info("***Paging", lastKey)
		}
	}

	log.Println("playback suceeded!")
}
Exemplo n.º 3
0
// by time range: notifications/{topic}?start=12345&end=67890
func GetNotifications(rw http.ResponseWriter, req *http.Request) {
	vars := mux.Vars(req)
	callback := req.FormValue("callback")

	// query db for playback list
	topic := vars["topic"]
	startTime := req.FormValue("start")
	endTime := req.FormValue("end")

	var queryInput *dynamodb.QueryInput
	lastKey := map[string]*dynamodb.AttributeValue{}

	lastKey = nil

	queryInput = prepareQuery(&topic, &startTime, &endTime, &lastKey)

	resp, err := SvcDynamo.Query(queryInput)

	if err != nil {
		midutil.LogAWSRequestErr(rw, req, err)
		return
	}

	if lastKey == nil {
		log.Println("lastKey is nil")
	} else {
		log.Println("lastKey is NOT nil")
	}
	//	convertNotification(resp)
	if !midutil.IsNullOrEmpty(&callback) {
		Render.JSONP(rw, http.StatusOK, callback, resp)
	} else {
		Render.JSON(rw, http.StatusOK, resp)
	}

}