Advertisement
Guest User

Untitled

a guest
Nov 11th, 2015
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 2.23 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5. )
  6.  
  7. // UserAPI ~
  8. type UserAPI struct {
  9.     KeyID           int    `sql:"AUTO_INCREMENT"                gorm:"primary_key"`
  10.     APIKey          string `sql:"type:varchar(13)   ;not null"  gorm:"unique_index"`
  11.     APIAuthRedirekt string `sql:"type:varchar(100)  ;not null"`
  12.     Rights          int64
  13. }
  14.  
  15. //0 прав нет 1 права есть
  16. const (
  17.     rAuth = 1 << iota
  18.     rRegs
  19.     rBattlesInvasion
  20.     rBattlesSanctions
  21.     rBattlesGround
  22.     rMissionsLocation
  23.     rMissionsHq
  24.     rUnitsMarket
  25.     rBlackmarketMercenaries
  26.     rBlackmarketSaboteurs
  27.     rBlackmarketLaboratory
  28.     rBlackmarketContraband
  29.     rBlackmarketDocuments
  30.     rBlackmarketAuction
  31.     rManufacturingFactory
  32.     rManufacturingMines
  33.     rManufacturingRockets
  34.     rBuildingsProfitable
  35.     rBuildingsDefense
  36.     rBuildingsEnergy
  37.     rOfficersclubResling
  38.     rOfficersclubRoulette
  39.     rOfficersclubSpyInterrogation
  40.     rOfficersclubVeteransRiddle
  41.     rOfficersclubWallNewspaper
  42.     rProfileInfo
  43.     rProfileSkills
  44.     rProfileAchievements
  45.     rProfileProperty
  46.     rProfileBooty
  47.     rProfileGifts
  48.     rProfileVipMode
  49.     rProfileStatistic
  50.     rHalloffameRating
  51.     rHalloffameStatistic
  52.     rHalloffameHeroes
  53.     rHalloffameLegions
  54.     rAllianceIndex
  55.     rAllianceRequests
  56.     rAllianceReferrals
  57.     rAllianceReinforcement
  58.     rAllianceUnderDefense
  59.     rChatPublic
  60.     rChatAlliance
  61.     rChatLegions
  62.     rChatBootcamp
  63.     rBankStorage
  64.     rBankGold
  65.     rBankСredit
  66.     rBankExchanger
  67.     rMailIndex
  68.     rMailWrite
  69.     rMailContacts
  70.     rMailIgnore
  71.     rHospital
  72.     rNews
  73.     rNewsAddCommen
  74.     rDailyBonus
  75. )
  76.  
  77. func (u *UserAPI) checkRight(right int64) bool {
  78.     return u.Rights&right != 0
  79. }
  80.  
  81. func (u *UserAPI) setRight(right int64) {
  82.     u.Rights |= right
  83. }
  84.  
  85. func (u *UserAPI) unsetRight(right int64) {
  86.     u.Rights &^= right
  87. }
  88.  
  89. func main() {
  90.     u := UserAPI{KeyID: 1, APIKey: `xxxx`, Rights: (rBankGold | rMailWrite | rHospital)}
  91.  
  92.     fmt.Println(`rBankGold:`, u.checkRight(rBankGold))
  93.     fmt.Println(`rMailWrite:`, u.checkRight(rMailWrite))
  94.     fmt.Println(`rRegs:`, u.checkRight(rRegs))
  95.     fmt.Println(`rNews:`, u.checkRight(rNews))
  96.  
  97.     u.setRight(rNews)
  98.     fmt.Println(`rNews:`, u.checkRight(rNews))
  99.  
  100.     u.unsetRight(rNews)
  101.     fmt.Println(`rNews:`, u.checkRight(rNews))
  102.  
  103.     //  rBankGold: true
  104.     //  rMailWrite: true
  105.     //  rRegs: false
  106.     //  rNews: false
  107.     //  rNews: true
  108.     //  rNews: false
  109.  
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement