go-api-boilerplate: github.com/vardius/go-api-boilerplate/pkg/identity Index | Files

package identity

import "github.com/vardius/go-api-boilerplate/pkg/identity"

Package identity provides type that allows to authorize request


Package Files

context.go identity.go


var NullIdentity = Identity{}

NullIdentity represents empty Identity

func ContextWithIdentity Uses

func ContextWithIdentity(ctx context.Context, i Identity) context.Context

ContextWithIdentity returns a new Context that carries value i.

type Identity Uses

type Identity struct {
    ID    uuid.UUID `json:"id"`
    Token string    `json:"token"`
    Email string    `json:"email"`
    Roles Role      `json:"roles"`

Identity data to be encode in auth token

func FromContext Uses

func FromContext(ctx context.Context) (Identity, bool)

FromContext returns the Identity value stored in ctx, if any.

func New Uses

func New(id uuid.UUID, token, email string) Identity

New returns a new Identity

func (Identity) HasRole Uses

func (i Identity) HasRole(role Role) bool

HasRole returns true if identity has give role

func (Identity) RemoveRole Uses

func (i Identity) RemoveRole(role Role) Identity

RemoveRole removes role from identity

func (Identity) WithEmail Uses

func (i Identity) WithEmail(email string) Identity

WithEmail returns copy of an identity with given email value

func (Identity) WithRole Uses

func (i Identity) WithRole(role Role) Identity

WithRole adds role to identity roles

func (Identity) WithToken Uses

func (i Identity) WithToken(token string) Identity

WithToken returns copy of an identity with given oauth2 token

type Role Uses

type Role uint8

Role type

const (
    RoleUser Role = 1 << iota


func (Role) String Uses

func (r Role) String() string

Package identity imports 2 packages (graph) and is imported by 6 packages. Updated 2020-08-04. Refresh now. Tools for package owners.