/* helper method */ func PreHandle(ctx *ink.Context) { // auth check path := ctx.Req.URL.Path if path != "/user/login" && path != "/user/check_token" && path != "/article/get" && path != "/user/register" && path != "/user/page" { userId := ctx.TokenGet("id") if userId == nil { returnRet(ctx, false, "权限验证失败") ctx.Stop() return } } // parse request json data if path != "/article/upload" { decoder := json.NewDecoder(ctx.Req.Body) data := make(Map) err := decoder.Decode(&data) if err != nil { returnRet(ctx, false, "json parse error") ctx.Stop() return } ctx.Ware["data"] = data } }