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"} }
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, "" }
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) }