user

package
v0.0.0-...-4347b6b Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2017 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const TargetType = "tg_user"

TargetType is the identifier used for events targeting a User.

Variables

View Source
var (
	ErrInvalidUser = errors.New("invalid user")
	ErrNotFound    = errors.New("user not found")
)

Common errors for User service implementations and validations.

Functions

func IsInvalidUser

func IsInvalidUser(err error) bool

IsInvalidUser indicates if err is ErrInvalidUser.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound indicates if err is ErrNotFound.

Types

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error wraps common User errors.

func (Error) Error

func (e Error) Error() string

type Image

type Image struct {
	URL    string `json:"url"`
	Type   string `json:"type"`
	Height int    `json:"height"`
	Width  int    `json:"width"`
}

Image represents a user image asset.

type List

type List []*User

List is a collection of users.

func ListFromIDs

func ListFromIDs(s Service, ns string, ids ...uint64) (List, error)

ListFromIDs gathers a user collection from the Service for the given ids.

func (List) Len

func (l List) Len() int

func (List) Less

func (l List) Less(i, j int) bool

func (List) Swap

func (l List) Swap(i, j int)

func (List) ToMap

func (l List) ToMap() Map

ToMap transforms the list to a Map.

type Map

type Map map[uint64]*User

Map is a user collection with their id as index.

func MapFromIDs

func MapFromIDs(s Service, ns string, ids ...uint64) (Map, error)

MapFromIDs return a populated user map for the given list of ids.

func (Map) Merge

func (m Map) Merge(x Map) Map

Merge combines two Maps.

func (Map) ToList

func (m Map) ToList() List

ToList returns the Map as an ordered List.

type Metadata

type Metadata map[string]interface{}

Metadata is a bucket to provide additional user information.

type Private

type Private struct {
	Type     string `json:"type,omitempty"`
	Verified bool   `json:"verified"`
}

Private is the bucket for protected fields on a User.

type QueryOptions

type QueryOptions struct {
	Before     uint64
	CustomIDs  []string
	Deleted    *bool
	Emails     []string
	Firstnames []string
	Enabled    *bool
	IDs        []uint64
	Lastnames  []string
	Limit      int
	Offset     uint
	Query      string
	SocialIDs  map[string][]string
	Usernames  []string
}

QueryOptions is used to narrow-down user queries.

type Service

type Service interface {
	service.Lifecycle

	Count(namespace string, opts QueryOptions) (int, error)
	Put(namespace string, user *User) (*User, error)
	PutLastRead(namespace string, userID uint64, lastRead time.Time) error
	Query(namespace string, opts QueryOptions) (List, error)
	Search(namespace string, opts QueryOptions) (List, error)
}

Service for user interactions.

func MemService

func MemService() Service

MemService returns a memory based Service implementation.

func PostgresService

func PostgresService(db *sqlx.DB) Service

PostgresService returns a Postgres based Service implementation.

type ServiceMiddleware

type ServiceMiddleware func(Service) Service

ServiceMiddleware is a chainable behaviour modifier for Service.

func InstrumentMiddleware

func InstrumentMiddleware(
	component, store string,
	errCount kitmetrics.Counter,
	opCount kitmetrics.Counter,
	opLatency *prometheus.HistogramVec,
) ServiceMiddleware

InstrumentMiddleware observes key apsects of Service operations and exposes Prometheus metrics.

func LogMiddleware

func LogMiddleware(logger log.Logger, store string) ServiceMiddleware

LogMiddleware gien a Logger wraps the next Service with logging capabilities.

type User

type User struct {
	About          string            `json:"about"`
	CustomID       string            `json:"custom_id,omitempty"`
	Deleted        bool              `json:"deleted"`
	Enabled        bool              `json:"enabled"`
	Email          string            `json:"email,omitempty"`
	Firstname      string            `json:"first_name"`
	FollowerCount  int               `json:"-"`
	FollowingCount int               `json:"-"`
	FriendCount    int               `json:"-"`
	ID             uint64            `json:"id"`
	Images         map[string]Image  `json:"images,omitempty"`
	IsFollower     bool              `json:"-"`
	IsFollowing    bool              `json:"-"`
	IsFriend       bool              `json:"-"`
	Lastname       string            `json:"last_name"`
	LastRead       time.Time         `json:"-"`
	Metadata       Metadata          `json:"metadata"`
	Password       string            `json:"password"`
	Private        *Private          `json:"private,omitempty"`
	SessionToken   string            `json:"-"`
	SocialIDs      map[string]string `json:"social_ids,omitempty"`
	URL            string            `json:"url,omitempty"`
	Username       string            `json:"user_name,omitempty"`
	CreatedAt      time.Time         `json:"created_at"`
	UpdatedAt      time.Time         `json:"updated_at"`
}

User is the representation of a customer of an app.

func (*User) Validate

func (u *User) Validate() error

Validate performs semantic checks on the passed User values for correctness.

Jump to

Keyboard shortcuts

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