Ejemplo n.º 1
0
func adminOnly(ctx *soggy.Context, name string) map[string]string {
	if name == "admin" {
		ctx.Next(nil)
		return nil
	}
	return map[string]string{"error": "Not admin"}
}
Ejemplo n.º 2
0
func passwordAuthenticate(ctx *soggy.Context) (int, string) {
	if config.Password != "" {
		headers := ctx.Req.Header
		if headers.Get("Authorization") != config.Password {
			return 403, "Invalid password"
		}
	}
	ctx.Next(nil)
	return -1, ""
}
Ejemplo n.º 3
0
func (middleware *MiddlewareExample) Execute(ctx *soggy.Context) {
	log.Println("I've hit the custom middleware")
	// Call the next middleware, if this isn't called the request will end
	ctx.Next(nil)
}