entities

package
v0.0.0-...-f077983 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2015 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BasicEmailRegExp is a regular expression that matches 99% of the email
	// addresses in use today.
	BasicEmailRegExp = `(?i)[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}`

	// RFCEmailRegExp - practical implementation of RFC 2822 omitting the
	// syntax using double quotes (") and square brackets ([]), since not
	// all applications support the syntax using it.
	RFCEmailRegExp = `(?i)[A-Z0-9!#$%&'*+/=?^_{|}~-]+` +
		`(?:\.[A-Z0-9!#$%&'*+/=?^_{|}~-]+)*` +
		`@(?:[A-Z0-9](?:[A-Z0-9-]*[A-Z0-9])?\.)+` +
		`[A-Z0-9](?:[A-Z0-9-]*[A-Z0-9])?`
)

Variables

This section is empty.

Functions

func ValidBasicEmail

func ValidBasicEmail(email string) bool

ValidBasicEmail validates email using BasicEmailRegExp regexp

func ValidRFC2822Email

func ValidRFC2822Email(email string) bool

ValidRFC2822Email validates email using RFCEmailRegExp regexp

Types

type BasicDomain

type BasicDomain struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Enabled     bool   `json:"enabled"`
}

BasicDomain contains basic domain attributes

func NewBasicDomain

func NewBasicDomain(name, description string) *BasicDomain

NewBasicDomain - a constructor for Domain entities

func (*BasicDomain) IsValid

func (d *BasicDomain) IsValid() (bool, error)

IsValid checks if domain is valid

type BasicDomainCollection

type BasicDomainCollection struct {
	Domains   []BasicDomain `json:"domains"`
	Paginator Paginator     `json:"paginator"`
}

BasicDomainCollection is a paginated collection of Domain entities

type BasicPermission

type BasicPermission struct {
	Name           string `json:"name"`
	Description    string `json:"description"`
	EvaluationRule string `json:"evaluation_rule"`
	Enabled        bool   `json:"is_enabled"`
}

BasicPermission entity

func NewBasicPermission

func NewBasicPermission(name, description string) *BasicPermission

NewBasicPermission create a new BasicPermission entity

type BasicPermissionCollection

type BasicPermissionCollection struct {
	Permissions []BasicPermission `json:"permissions"`
	Paginator   Paginator         `json:"paginator"`
}

BasicPermissionCollection is a paginated collection of BasicPermission entities

type BasicRole

type BasicRole struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Enabled     bool   `json:"is_enabled"`
}

BasicRole entity

func NewBasicRole

func NewBasicRole(name, description string) *BasicRole

NewBasicRole create a new BasicRole entity

type BasicRoleCollection

type BasicRoleCollection struct {
	Roles     []BasicRole `json:"roles"`
	Paginator Paginator   `json:"paginator"`
}

BasicRoleCollection is a paginated collection of BasicRole entities

type BasicUser

type BasicUser struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Password string `json:"-"`
	Enabled  bool   `json:"enabled"`
}

BasicUser contains basic user attributes

func NewBasicUser

func NewBasicUser(name string) *BasicUser

NewBasicUser - a constructor for `User`

func (*BasicUser) IsPassword

func (u *BasicUser) IsPassword(clearTxt string) bool

IsPassword checks if a given clear text is user's password

func (*BasicUser) IsValid

func (u *BasicUser) IsValid() (bool, error)

IsValid checks if user is valid

func (*BasicUser) SetPassword

func (u *BasicUser) SetPassword(clearTxt string)

SetPassword hashes a given clearTxt and assigns it to password field

type BasicUserCollection

type BasicUserCollection struct {
	Users     []BasicUser `json:"users"`
	Paginator Paginator   `json:"paginator"`
}

BasicUserCollection is a paginated collection of User entities

type Domain

type Domain struct {
	BasicDomain
	UsersCount int64 `json:"-"`
}

Domain entities represent different tenants which contain User entities. A domain can be either a real domain (e.g myproject.com) or just a logical name of the user group you want to separate everyone into.

type DomainCollection

type DomainCollection struct {
	Domains   []Domain  `json:"domains"`
	Paginator Paginator `json:"paginator"`
}

DomainCollection is a paginated collection of Domain entities

type Pager

type Pager struct {
	Page    int `json:"page"`
	PerPage int `json:"per_page"`
}

Pager simply defines pagination request for collections

func (Pager) CreatePaginator

func (p Pager) CreatePaginator(resultsOnCurrentPage int, totalCount int64) *Paginator

CreatePaginator create paginator with Total and HasNextPage filled in

func (Pager) Offset

func (p Pager) Offset() int64

Offset calculate offset based on Page and PerPage attributes

type Paginator

type Paginator struct {
	Page        int   `json:"page"`
	Total       int64 `json:"total"`
	PerPage     int   `json:"per_page"`
	HasNextPage bool  `json:"-"`
}

Paginator describes pagination of a collection

func (Paginator) TotalPages

func (p Paginator) TotalPages() int64

TotalPages calculate total number of pages based on Page and PerPage attributes

type Session

type Session struct {
	ID         string       `json:"id"`
	Domain     *BasicDomain `json:"domain"`
	User       *BasicUser   `json:"user"`
	UserAgent  string       `json:"-"`
	RemoteAddr string       `json:"-"`
	CreatedOn  Time         `json:"created_on"`
	UpdatedOn  Time         `json:"updated_on"`
	ExpiresOn  Time         `json:"expires_on"`
}

Session structure represents user's time limited session

func NewSession

func NewSession(user BasicUser, domain BasicDomain, userAgent, remoteAddr string) *Session

NewSession create a new Session entity

func (*Session) IsExpired

func (s *Session) IsExpired() bool

IsExpired checks if the session is expired

func (*Session) IsValid

func (s *Session) IsValid() bool

IsValid checks if session has a non-empty Sid, non-null User's/Domain's Ids and a non-zero expiration time.

type SessionCollection

type SessionCollection struct {
	Sessions  []Session `json:"sessions"`
	Paginator Paginator `json:"paginator"`
}

SessionCollection is a paginated collection of Session entities

type Sorter

type Sorter struct {
	Field string `json:"field"`
	Asc   bool   `json:"asc"`
}

Sorter simply fines the soring options for collections

type Time

type Time struct {
	time.Time
}

Time is a type alias so we could override methods and add our own

func ParseTime

func ParseTime(s string) (Time, error)

ParseTime parses date string of RFC3339 format

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface. Time is formatted as RFC3339 instead of RFC3339Nano (original time.Time)

type User

type User struct {
	BasicUser
	DomainsCount int64 `json:"-"`
}

User entities represent users

type UserCollection

type UserCollection struct {
	Users     []User    `json:"users"`
	Paginator Paginator `json:"paginator"`
}

UserCollection is a paginated collection of User entities

Jump to

Keyboard shortcuts

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