enum_authCheck.go 856 B

123456789101112131415161718192021222324252627282930313233
  1. package enum
  2. var (
  3. notAuthCheck = NewEnum(0, "不需要认证") //0 -> 00000000
  4. needUserAuth = NewEnum(1, "需要用户认证") //1 -> 00000001
  5. needEntAuth = NewEnum(1<<1, "需要企业认证") //2 -> 00000010
  6. )
  7. type AuthCheck struct {
  8. *Enum
  9. }
  10. // NewAuthCheck 初始化权限校验对象
  11. func NewAuthCheck(code int64, desc ...string) *AuthCheck {
  12. return &AuthCheck{
  13. NewEnum(code, desc...),
  14. }
  15. }
  16. // NeedCheck 是否需要账户认证校验
  17. func (ac *AuthCheck) NeedCheck() bool {
  18. return ac.GetCode() != notAuthCheck.code
  19. }
  20. // CheckUserAuth 校验是否需要用户认证
  21. func (ac *AuthCheck) CheckUserAuth() bool {
  22. return needUserAuth.code == (ac.GetCode() & needUserAuth.code)
  23. }
  24. // CheckEntAuth 校验是否需要企业认证
  25. func (ac *AuthCheck) CheckEntAuth() bool {
  26. return needEntAuth.code == (ac.GetCode() & needEntAuth.code)
  27. }