go-api-boilerplate: github.com/vardius/go-api-boilerplate/cmd/auth/internal/domain/token Index | Files

package token

import "github.com/vardius/go-api-boilerplate/cmd/auth/internal/domain/token"

Package token holds token domain logic


Package Files

commands.go events.go repository.go token.go


const (
    // RemoveAuthToken command bus contract
    RemoveAuthToken = "remove-auth-token"


var StreamName = fmt.Sprintf("%T", Token{})

StreamName for token domain

func NewCommandFromPayload Uses

func NewCommandFromPayload(contract string, payload []byte) (domain.Command, error)

NewCommandFromPayload builds command by contract from json payload

func OnRemove Uses

func OnRemove(repository Repository) commandbus.CommandHandler

OnRemove creates command handler

type Remove Uses

type Remove struct {
    ID uuid.UUID

Remove command

func (Remove) GetName Uses

func (c Remove) GetName() string

GetName returns command name

type Repository Uses

type Repository interface {
    Save(ctx context.Context, t Token) error
    Get(ctx context.Context, id uuid.UUID) (Token, error)

    // Block and returns after event handlers are finished
    SaveAndAcknowledge(ctx context.Context, t Token) error

Repository allows to get/save events from/to event store

type Token Uses

type Token struct {
    // contains filtered or unexported fields

Token aggregate root

func FromHistory Uses

func FromHistory(ctx context.Context, events []domain.Event) (Token, error)

FromHistory loads current aggregate root state by applying all events in order

func New Uses

func New() Token

New creates an Token

func (Token) Changes Uses

func (t Token) Changes() []domain.Event

Changes returns all new applied events

func (*Token) Create Uses

func (t *Token) Create(
    ctx context.Context,
    id uuid.UUID,
    clientID uuid.UUID,
    userID uuid.UUID,
    info oauth2.TokenInfo,
    userAgent string,

) error

Create alters current token state and append changes to aggregate root

func (Token) ID Uses

func (t Token) ID() uuid.UUID

ID returns aggregate root id

func (*Token) Remove Uses

func (t *Token) Remove(ctx context.Context) error

Remove alters current token state and append changes to aggregate root

func (Token) Version Uses

func (t Token) Version() int

Version returns current aggregate root version

type WasCreated Uses

type WasCreated struct {
    ID        uuid.UUID       `json:"id"`
    ClientID  uuid.UUID       `json:"client_id"`
    UserID    uuid.UUID       `json:"user_id"`
    Data      json.RawMessage `json:"data"`
    UserAgent string          `json:"user_agent"`

WasCreated event

func (WasCreated) GetData Uses

func (e WasCreated) GetData() json.RawMessage

func (WasCreated) GetID Uses

func (e WasCreated) GetID() string

GetID the id

func (WasCreated) GetType Uses

func (e WasCreated) GetType() string

GetType returns event type

func (WasCreated) GetUserAgent Uses

func (e WasCreated) GetUserAgent() string

func (WasCreated) TokenInfo Uses

func (e WasCreated) TokenInfo() (oauth2.TokenInfo, error)

type WasRemoved Uses

type WasRemoved struct {
    ID uuid.UUID `json:"id"`

WasRemoved event

func (WasRemoved) GetType Uses

func (e WasRemoved) GetType() string

GetType returns event type

Package token imports 14 packages (graph) and is imported by 4 packages. Updated 2020-11-26. Refresh now. Tools for package owners.