Example #1
0
func LogOne(res http.ResponseWriter, req *http.Request, c martini.Context, logger *log.Logger) {
	start := time.Now()
	c.Next()

	rw := res.(martini.ResponseWriter)
	status := rw.Status()
	if status != 200 && status != 304 && req.URL.Path != "/ws" {
		logThis(start, res, req, logger)
		return
	}

	host, _, err := net.SplitHostPort(req.RemoteAddr)
	if err != nil {
		host = req.RemoteAddr
	}
	logOneLock.Lock()
	if _, ok := logged[host]; ok {
		logOneLock.Unlock()
		return
	}
	logged[host] = true
	logOneLock.Unlock()

	logger.Printf("%s\tRequested from %s; subsequent successful requests will not be logged\n", time.Now().Format("15:04:05"), host)
}
Example #2
0
func Middleware(ctx martini.Context, r *http.Request, w http.ResponseWriter) {
	sessionId := ensureCookie(r, w)
	session := sessionStore.Get(sessionId)

	ctx.Map(session)

	ctx.Next()

	sessionStore.Set(session)
}
func AdminAuthentication(c martini.Context) {
	// TODO Need to fix this up
	c.Next()
}
// Martini Middleware to require authentication of anyone logging into
// the app
//
func Authentication(c martini.Context) {
	// TODO Need to authenticate
	c.Next()
}
Example #5
0
func CloseDatabase(martiniContext martini.Context, appContext *models.AppContext) {
	martiniContext.Next()
	appContext.DbContext.Dbmap.Db.Close()
}
Example #6
0
func LogAll(res http.ResponseWriter, req *http.Request, c martini.Context, logger *log.Logger) {
	start := time.Now()
	c.Next()
	logThis(start, res, req, logger)
}