Example #1
0
func AuthMiddleware(c *mv.Context) {
	log.Println("Simulate user authentication.")
	rand.Seed(time.Now().Unix())
	if rand.Int()%2 == 0 {
		c.Response.Write([]byte("User authenticated.\n"))
		c.Next()
	} else {
		c.Response.WriteHeader(http.StatusUnauthorized)
		c.Response.Write([]byte("Use not authenticated.\n"))
		c.Abort()
	}
}
Example #2
0
func (uae UserAgentExtractor) Handle(c *mv.Context) {
	ua := user_agent.New(c.Request.Header["User-Agent"][0])
	name, version := ua.Browser()
	browserEngine, browserEngineVersion := ua.Engine()
	browserInfo := BrowserInfo{
		verbose:       uae.verbose,
		Name:          name,
		Version:       version,
		OS:            ua.OS(),
		Engine:        browserEngine,
		EngineVersion: browserEngineVersion,
		Localization:  ua.Localization(),
		Platform:      ua.Platform(),
		Mobile:        ua.Mobile(),
	}
	c.WithValue(browserInfoKey, browserInfo)
	c.Next()
}
Example #3
0
func Middleware1(c *mv.Context) {
	c.Response.Write([]byte("Added in middleware 1 before calling Next\n"))
	c.Next()
	c.Response.Write([]byte("Added in middleware 1 after calling Next\n"))
}
Example #4
0
func LoggingMiddleware(c *mv.Context) {
	log.Println("Simluate real logging here")
	c.Next()
}