[go: up one dir, main page]

Skip to content

πŸ”‘ Permission management made easy (Go port of NPM package perman)

License

Notifications You must be signed in to change notification settings

barbarbar338/perman

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

stars license supportServer forks issues

Logo

Perman.GO

πŸ”‘ Permission management made easy
Get support Β»

Report Bug Β· Request Feature Β· Webpage

πŸ”‘ Perman

Permission management made easy

πŸ“¦ Installation

  • Run go get github.com/barbarbar338/perman

πŸ€“ Usage

See API for all methods

package main

import (
	"fmt"

	"github.com/barbarbar338/perman"
)

func main() {
    p := perman.Factory([]string{"user", "verified", "admin"})

    user := p.Serialize([]string{"user"})
    verified := p.Serialize([]string{"user", "verified"})
    admin := p.Serialize([]string{"user", "admin"})

    p.Has(user, "user") // true
    p.Has(user, "admin") // false
    p.Has(verified, "verified") // true
    p.Has(verified, "admin") // false
    p.Has(admin, "admin") // true

    // add permissions
    p.Has(user, "verified") // false
    user = p.Add(user, "verified")
    p.Has(user, "verified") // true

    // remove permissions
    p.Has(verified, "verified") // true
    verified = p.Remove(verified, "verified")
    p.Has(verified, "verified") // false
}

πŸ“„ License

Copyright © 2022 Barış DEMİRCİ.

Distributed under the GPL-3.0 License. See LICENSE for more information.

🧦 Contributing

Fell free to use GitHub's features.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/my-feature)
  3. Commit your Changes (git commit -m 'my awesome feature my-feature')
  4. Push to the Branch (git push origin feature/my-feature)
  5. Open a Pull Request

πŸ”₯ Show your support

Give a ⭐️ if this project helped you!

πŸ“ž Contact

πŸ“œ API

Method Description Usage Output
Factory Creates a new Perman instance perman.Factory(flags []string{}) Perman
Keys Returns all flag names p.Keys() []string{}
Values Returns all flag values p.Values() []int64
Get Returns the numeric value of flag p.Get(flag string) int64
Serialize Serializes the flags p.Serialize(flags []string{}) int64
Deserialize Deserializes the permission p.Deserialize(permissions int64) []string{}
Match Matches permissions with flags, if permissions has all flags, returns true p.Match(permissions int64, flags []string{}) bool
MatchAll (alias of Match) Matches permissions with flags, if permissions has all flags, returns true p.MatchAll(permissions: int64, flags []string{}) bool
HasAll (alias of match) Matches permissions with flags, if permissions has all flags, returns true p.HasAll(permissions: int64, flags []string{}) bool
Some Matches permissions with flags, if permissions has at least one flag, returns true p.Some(permissions: int64, flags []string{}) bool
HasSome (alias of some) Matches permissions with flags, if permissions has at least one flag, returns true p.HasSome(permissions: int64, flags []string{}) bool
HasNone Matches permissions with flags, if permissions has at least one flag, returns false p.HasNone(permissions: int64, flags []string{}) bool
None (alias of hasNone) Matches permissions with flags, if permissions has at least one flag, returns false p.None(permissions: int64, flags []string{}) bool
Has Checks if the given permission is granted p.Has(permission int64, flag string) bool
Test (alias of has) Checks if the given permission is granted p.Test(permission int64, flag string) bool
Add Adds a new flag to given permission p.Add(permission int64, flag string) int64
Remove Removes a flag from given permission p.Remove(permission int64, flag string) int64
Full Creates a permission with all flags p.Full() int64

About

πŸ”‘ Permission management made easy (Go port of NPM package perman)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages