identity

package
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2020 License: MIT Imports: 2 Imported by: 0

README

identity GoDoc

Package identity provides type that allows to authorize request

Download:

go get -u github.com/vardius/go-api-boilerplate/pkg/identity

Package identity provides type that allows to authorize request

Documentation

Overview

Package identity provides type that allows to authorize request

Index

Constants

This section is empty.

Variables

View Source
var NullIdentity = Identity{}

NullIdentity represents empty Identity

Functions

func ContextWithIdentity

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

ContextWithIdentity returns a new Context that carries value i.

Types

type Identity

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

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

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

func New

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

New returns a new Identity

func (Identity) HasRole

func (i Identity) HasRole(role Role) bool

HasRole returns true if identity has give role

func (Identity) RemoveRole

func (i Identity) RemoveRole(role Role) Identity

RemoveRole removes role from identity

func (Identity) WithEmail

func (i Identity) WithEmail(email string) Identity

WithEmail returns copy of an identity with given email value

func (Identity) WithRole

func (i Identity) WithRole(role Role) Identity

WithRole adds role to identity roles

func (Identity) WithToken

func (i Identity) WithToken(token string) Identity

WithToken returns copy of an identity with given oauth2 token

type Role

type Role uint8

Role type

const (
	// @TODO: MANAGE YOUR ROLES HERE
	RoleUser Role = 1 << iota
	RoleAdmin
)

Roles

func (Role) String

func (r Role) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL