Exemplo n.º 1
0
func init() {

	http.Handle("/apis", util.Chain(func(w http.ResponseWriter, r *http.Request) {
		util.RenderJSON(w, models.ListAPI(), nil)
	}))

}
Exemplo n.º 2
0
func init() {

	http.Handle("/crons", util.Chain(func(w http.ResponseWriter, r *http.Request) {
		entries := []*cron.Entry{}
		for _, c := range crons.Crons() {
			entries = append(entries, c.Entries()...)
		}
		next := []time.Time{}
		for _, entry := range entries {
			next = append(next, entry.Next)
		}
		util.RenderJSON(w, next, nil)
	}))

	http.Handle("/crons/results", util.Chain(func(w http.ResponseWriter, r *http.Request) {
		results, _, err := models.GetCronResults()
		util.RenderJSON(w, results, err)
	}))

}
Exemplo n.º 3
0
func init() {

	/**
	 * sessions
	 * @param string output [The formatting style for response body (html | json).]
	 * @param string q [Space seperated words to use in filtering the response data (for example, best practice).]
	 */
	http.Handle("/reinvent/sessions", util.Chain(func(w http.ResponseWriter, r *http.Request) {
		id, found := util.RequestGetParam(r, "id")
		if found {
			session, err := models.GetSession(id)
			if util.IsInvalid(w, err, "@aws.DynamoRecords") {
				return
			}
			util.RenderJSON(w, session, nil)
			return
		}
		output, found := util.RequestGetParam(r, "output")
		if found && (strings.ToLower(output) == "html") {
			token, _, _ := checkTwitterSession(w, r)
			util.RenderHTML(w, []string{"reinvent/index.tmpl"}, struct{ Token models.OAuthAuthorizedToken }{token}, nil)
			return
		}
		cron, err1 := models.GetCronResult("SyncReInventSessions")
		if util.IsInvalid(w, err1, "@aws.DynamoRecord") {
			return
		}
		// get sessions
		sessions, _, err2 := models.GetSessions()
		if util.IsInvalid(w, err2, "@aws.DynamoRecords") {
			return
		}
		// filter
		if q, found := util.RequestGetParam(r, "q"); found {
			splitted := strings.FieldsFunc(q, func(c rune) bool {
				return !unicode.IsLetter(c) && !unicode.IsNumber(c)
			})
			words := make([]string, len(splitted))
			for i, val := range splitted {
				words[i] = strings.ToUpper(val)
			}
			filtered := models.Sessions{}
			for _, session := range sessions {
				if session.Contains(words) {
					filtered = append(filtered, session)
				}
			}
			sessions = filtered
		}
		util.RenderJSON(w, struct {
			Count    int              `json:"count"`
			Sessions []models.Session `json:"sessions"`
			Sync     time.Time        `json:"sync"`
		}{
			Count:    len(sessions),
			Sessions: sessions,
			Sync:     cron.LastEndDate,
		}, nil)
	}))

	http.Handle("/refresh", util.Chain(func(w http.ResponseWriter, r *http.Request) {
		sessions, err := models.SyncReInventSessions(true)
		util.RenderJSON(w, sessions, err)
	}))

}