package api import ( "github.com/kataras/iris/v12" "github.com/kataras/iris/v12/context" "go.uber.org/zap" "pet-house.com/business/models" "pet-house.com/business/utils" "pet-house.com/core/server/database" "pet-house.com/core/server/web/web_iris" "pet-house.com/core/server/zap_server" "strings" "time" ) var Root = "/pet-house" var ExcludeBase = "/static" var ExcludeBase1 = "/debug" var ExcludeBase2 = "/admin" var ExcludeBase3 = "/system" var ExcludeBase4 = "/payNotify" var frontExcludes = [...]string{ Root + AuthBase + "/login", } func ModuleInit() { utils.WechatInit() _err := database.Instance().AutoMigrate( //&models.User{}, //&models.Pet{}, //&models.PetBaseInfo{}, //&models.ServiceAddr{}, //&models.UserServiceAddr{}, //&models.Goods{}, //&models.PetGoods{}, //&models.SystemConfig{}, //&models.OrderMain{}, //&models.OrderSub{}, //&models.OrderDetail{}, //&models.ServiceCar{}, //&models.CarOrder{}, //&models.ServiceCarUser{}, //&models.ServiceUserMark{}, //&models.ServiceUserMarkRecord{}, //&models.ReserveTimeFilter{}, //&models.OrderServiceRecord{}, //&models.AddrServiceTime{}, //&models.UserAmountRecord{}, //&models.Coupons{}, //&models.UserCoupons{}, //&models.RechargeInfo{}, //&models.PayOrder{}, &models.ServiceUserMarkRecord{}, //&models.ServiceCarLocation{}, ) zap_server.ZAPLOG.Info("data init ", zap.Any("err", _err)) DataInit() DataCacheJob() } func FrontAuth(ctx *context.Context) { ctx.Values().Set("reqTime", time.Now()) if strings.Contains(ctx.Path(), ExcludeBase) { ctx.Next() return } if strings.Contains(ctx.Path(), ExcludeBase1) { ctx.Next() return } if strings.Contains(ctx.Path(), ExcludeBase2) { ctx.Next() return } if strings.Contains(ctx.Path(), ExcludeBase3) { ctx.Next() return } if strings.Contains(ctx.Path(), ExcludeBase4) { ctx.Next() return } frontExcludesStr := strings.Join(frontExcludes[:], ",") if strings.Contains(frontExcludesStr, ctx.Path()) { ctx.Next() return } token := ctx.GetHeader("X-Token") uid := ctx.GetHeader("X-U-Id") zap_server.ZAPLOG.Info("frontAuth", zap.Any("path", ctx.Path()), zap.Any("token", token), zap.Any("uid", uid)) if len(token) == 0 || len(uid) == 0 { IllegalError.Fail(ctx, nil) return } tokenToUid := GetTokenInfo(token) if len(tokenToUid) == 0 { TokenError.Fail(ctx, nil) return } if uid != tokenToUid { UserError.Fail(ctx, nil) return } ctx.Next() } func (p DefParty) index() web_iris.Party { return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) { index.Get("/", func(c *context.Context) { _, _ = c.WriteString("successful") }) }} }