Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- )
- // UserAPI ~
- type UserAPI struct {
- KeyID int `sql:"AUTO_INCREMENT" gorm:"primary_key"`
- APIKey string `sql:"type:varchar(13) ;not null" gorm:"unique_index"`
- APIAuthRedirekt string `sql:"type:varchar(100) ;not null"`
- Rights int64
- }
- //0 прав нет 1 права есть
- const (
- rAuth = 1 << iota
- rRegs
- rBattlesInvasion
- rBattlesSanctions
- rBattlesGround
- rMissionsLocation
- rMissionsHq
- rUnitsMarket
- rBlackmarketMercenaries
- rBlackmarketSaboteurs
- rBlackmarketLaboratory
- rBlackmarketContraband
- rBlackmarketDocuments
- rBlackmarketAuction
- rManufacturingFactory
- rManufacturingMines
- rManufacturingRockets
- rBuildingsProfitable
- rBuildingsDefense
- rBuildingsEnergy
- rOfficersclubResling
- rOfficersclubRoulette
- rOfficersclubSpyInterrogation
- rOfficersclubVeteransRiddle
- rOfficersclubWallNewspaper
- rProfileInfo
- rProfileSkills
- rProfileAchievements
- rProfileProperty
- rProfileBooty
- rProfileGifts
- rProfileVipMode
- rProfileStatistic
- rHalloffameRating
- rHalloffameStatistic
- rHalloffameHeroes
- rHalloffameLegions
- rAllianceIndex
- rAllianceRequests
- rAllianceReferrals
- rAllianceReinforcement
- rAllianceUnderDefense
- rChatPublic
- rChatAlliance
- rChatLegions
- rChatBootcamp
- rBankStorage
- rBankGold
- rBankСredit
- rBankExchanger
- rMailIndex
- rMailWrite
- rMailContacts
- rMailIgnore
- rHospital
- rNews
- rNewsAddCommen
- rDailyBonus
- )
- func (u *UserAPI) checkRight(right int64) bool {
- return u.Rights&right != 0
- }
- func (u *UserAPI) setRight(right int64) {
- u.Rights |= right
- }
- func (u *UserAPI) unsetRight(right int64) {
- u.Rights &^= right
- }
- func main() {
- u := UserAPI{KeyID: 1, APIKey: `xxxx`, Rights: (rBankGold | rMailWrite | rHospital)}
- fmt.Println(`rBankGold:`, u.checkRight(rBankGold))
- fmt.Println(`rMailWrite:`, u.checkRight(rMailWrite))
- fmt.Println(`rRegs:`, u.checkRight(rRegs))
- fmt.Println(`rNews:`, u.checkRight(rNews))
- u.setRight(rNews)
- fmt.Println(`rNews:`, u.checkRight(rNews))
- u.unsetRight(rNews)
- fmt.Println(`rNews:`, u.checkRight(rNews))
- // rBankGold: true
- // rMailWrite: true
- // rRegs: false
- // rNews: false
- // rNews: true
- // rNews: false
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement