db

package
v0.0.0-...-fd752eb Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrCodeNotFound not found in database
	ErrCodeNotFound int = iota + 1
	// ErrCodeNotInitialized not intialized
	ErrCodeNotInitialized
	// ErrCodeNotConnected not connected
	ErrCodeNotConnected
	// ErrCodeDuplicateEntry ...
	ErrCodeDuplicateEntry
	// ErrCodeInvalidID ...
	ErrCodeInvalidID
)

Variables

View Source
var (
	// DefaultAppName default app name
	DefaultAppName = "Default"
	// DefaultAppDescription default app description
	DefaultAppDescription = "Default App created automatically"
)
View Source
var (
	// ErrNotInitialized ...
	ErrNotInitialized = MakeError(ErrCodeNotInitialized, nil, nil, nil, "not initialized")
	// ErrNotConnected not connected
	ErrNotConnected = MakeError(ErrCodeNotConnected, nil, nil, nil, "not connected")

	// Now Current Time
	Now = utc
)
View Source
var (
	// ErrDuplicateIndexer diplicate indexer
	ErrDuplicateIndexer = errors.New("Duplicate indexer")
	// ErrIndexingLocked indexing already started or done
	ErrIndexingLocked = errors.New("Indexing is locked")
)
View Source
var (
	// DefaultListLimit ...
	DefaultListLimit = 10
	// MaxListLimit ...
	MaxListLimit = 100
)
View Source
var (
	// SecretLength ...
	SecretLength = 128
	// PasswordMin ...
	PasswordMin = 8
	// PasswordMax ...
	PasswordMax = 64
)

Functions

func Close

func Close(ctx context.Context) error

Close close database connection

func Connect

func Connect(ctx context.Context) error

Connect connect

func Connected

func Connected() bool

Connected ...

func Create

func Create(ctx context.Context, model Model) error

Create create model

func Delete

func Delete(ctx context.Context, model Model) error

Delete ...

func DisableCache

func DisableCache()

DisableCache ...

func EnableCache

func EnableCache()

EnableCache ...

func ErrDuplicateEntry

func ErrDuplicateEntry(model Model, value interface{}, wrapped error) error

ErrDuplicateEntry ...

func ErrInvalidID

func ErrInvalidID(value interface{}, wrapped error) error

ErrInvalidID ...

func ErrNotFound

func ErrNotFound(model Model, id interface{}, wrapped error) error

ErrNotFound ...

func FindStr

func FindStr(slice []string, val string) int

FindStr ...

func ForEachModel

func ForEachModel(handle func(Model))

ForEachModel ...

func GeneratePassword

func GeneratePassword() (string, error)

GeneratePassword ...

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateRandomString

func GenerateRandomString(min, max int) (string, error)

GenerateRandomString returns a URL-safe, base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateSecret

func GenerateSecret() (string, error)

GenerateSecret ...

func Get

func Get(ctx context.Context, id string, model Model) error

Get ...

func GetAppSearchKey

func GetAppSearchKey(app, name string) string

GetAppSearchKey ...

func GetByID

func GetByID(ctx context.Context, id interface{}, model CollectionModel) error

GetByID get model by ID

func GetRoomSearchKey

func GetRoomSearchKey(customer, name string) string

GetRoomSearchKey ...

func Init

func Init(config *Config)

Init ...

func Initialized

func Initialized() bool

Initialized ...

func IsDuplicate

func IsDuplicate(err error) bool

IsDuplicate Check if duplicate

func MakeError

func MakeError(code int, model Model, data interface{}, wrapped error, format string, v ...interface{}) error

MakeError ...

func ModelEvent

func ModelEvent(model Model, name string) event.Event

ModelEvent ...

func ModelEventHandler

func ModelEventHandler(handler func(Event, Model)) event.Handler

ModelEventHandler ...

func Ping

func Ping(ctx context.Context) bool

Ping ping database

func Ready

func Ready() bool

Ready check if ready

func Save

func Save(ctx context.Context, model Model) error

Save save model

func Set

func Set(ctx context.Context, model Model, insert bool) error

Set ...

func ValidateID

func ValidateID(id string) error

ValidateID ...

func Wait

func Wait()

Wait for database connection setup

Types

type App

type App struct {
	ID          primitive.ObjectID `bson:"_id,omitempty"`
	CustomerID  primitive.ObjectID `bson:"customer_id,omitempty"`
	UserID      primitive.ObjectID `bson:"user_id,omitempty"`
	Key         string             `bson:"key,omitempty"`
	Name        string             `bson:"name"`
	Active      bool               `bson:"active"`
	Description string             `bson:"description,omitempty"`
	CreatedAt   time.Time          `bson:"created_at,omitempty"`
	UpdatedAt   time.Time          `bson:"updated_at,omitempty"`
	Customer    *Customer          `bson:"-"`
}

App app info

func (*App) Cache

func (app *App) Cache(status bool)

Cache app object

func (*App) CacheKey

func (app *App) CacheKey() string

CacheKey ...

func (*App) Cached

func (app *App) Cached(id string) bool

Cached get cached value of app

func (*App) Collection

func (app *App) Collection() string

Collection model collection

func (*App) Create

func (app *App) Create(ctx context.Context) error

Create ...

func (*App) Decode

func (app *App) Decode(data []byte) error

Decode app object

func (*App) Delete

func (app *App) Delete(ctx context.Context) error

Delete ...

func (*App) Encode

func (app *App) Encode() ([]byte, error)

Encode app object

func (*App) Get

func (app *App) Get(ctx context.Context, id string) error

Get ...

func (*App) GetByName

func (app *App) GetByName(ctx context.Context, customer, name string) error

GetByName ...

func (*App) GetCustomer

func (app *App) GetCustomer(ctx context.Context) (*Customer, error)

GetCustomer Get auth app

func (*App) GetCustomerID

func (app *App) GetCustomerID() string

GetCustomerID ...

func (*App) GetID

func (app *App) GetID() string

GetID get id

func (*App) GetKey

func (app *App) GetKey() string

GetKey ...

func (*App) GetUserID

func (app *App) GetUserID() string

GetUserID ...

func (*App) Init

func (app *App) Init()

Init init new element

func (*App) List

func (app *App) List() ModelList

List ...

func (*App) New

func (app *App) New() Model

New ...

func (*App) ObjectID

func (app *App) ObjectID() interface{}

ObjectID ...

func (*App) OnCreate

func (app *App) OnCreate(ctx context.Context) error

OnCreate create event handler

func (*App) OnDelete

func (app *App) OnDelete(ctx context.Context) error

OnDelete delete event handler

func (*App) OnUpdate

func (app *App) OnUpdate(ctx context.Context) error

OnUpdate update event handler

func (*App) SetCustomerID

func (app *App) SetCustomerID(id string) error

SetCustomerID set id

func (*App) SetID

func (app *App) SetID(id string) error

SetID set id

func (*App) String

func (app *App) String() string

func (*App) Type

func (app *App) Type() string

Type ...

func (*App) Update

func (app *App) Update(ctx context.Context) error

Update ...

type AppList

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

AppList ...

func (*AppList) All

func (apps *AppList) All() []*App

All ...

func (*AppList) Collection

func (apps *AppList) Collection() string

Collection ...

func (*AppList) Get

func (apps *AppList) Get(ctx context.Context, start string, limit int) error

Get get all

func (*AppList) GetByCustomer

func (apps *AppList) GetByCustomer(ctx context.Context, id string, active bool) error

GetByCustomer get apps by customer

func (*AppList) GetByUser

func (apps *AppList) GetByUser(ctx context.Context, user, start string, limit int) error

GetByUser ...

func (*AppList) Index

func (apps *AppList) Index(index int) Model

Index ...

func (*AppList) Length

func (apps *AppList) Length() int

Length ...

func (*AppList) New

func (apps *AppList) New() Model

New ...

type Auth

type Auth struct {
	ID         primitive.ObjectID ` bson:"_id,omitempty"`
	UserID     primitive.ObjectID `bson:"user_id,omitempty"`
	CustomerID primitive.ObjectID `bson:"customer_id,omitempty"`
	AppID      primitive.ObjectID `bson:"app_id,omitempty"`
	Active     bool               `bson:"active,omitempty"`
	Admin      bool               `bson:"admin,omitempty"`
	Secret     string             `bson:"secret,omitempty"`
	Revoked    []string           `bson:"revoked,omitempty"`
	CreatedAt  time.Time          `bson:"created_at,omitempty"`
	UpdatedAt  time.Time          `bson:"updated_at,omitempty"`
	User       *User              `bson:"-"`
	App        *App               `bson:"-"`
	Customer   *Customer          `bson:"-"`
}

Auth auth info

func (*Auth) AccessKey

func (auth *Auth) AccessKey() string

AccessKey get access key

func (*Auth) Cache

func (auth *Auth) Cache(status bool)

Cache auth object

func (*Auth) CacheKey

func (auth *Auth) CacheKey() string

CacheKey ...

func (*Auth) Cached

func (auth *Auth) Cached(accessKey string) bool

Cached get cached value of auth

func (*Auth) CanCreate

func (auth *Auth) CanCreate(model Model) bool

CanCreate ...

func (*Auth) CanDelete

func (auth *Auth) CanDelete(model Model) bool

CanDelete ...

func (*Auth) CanGet

func (auth *Auth) CanGet(model Model) bool

CanGet ...

func (*Auth) CanList

func (auth *Auth) CanList(model Model) bool

CanList ...

func (*Auth) CanUpdate

func (auth *Auth) CanUpdate(model Model) bool

CanUpdate ...

func (*Auth) Collection

func (auth *Auth) Collection() string

Collection model collection

func (*Auth) Create

func (auth *Auth) Create(ctx context.Context) error

Create ...

func (*Auth) CreateSecret

func (auth *Auth) CreateSecret() error

CreateSecret create new secret for auth

func (*Auth) Decode

func (auth *Auth) Decode(data []byte) error

Decode app object

func (*Auth) Delete

func (auth *Auth) Delete(ctx context.Context) error

Delete ...

func (*Auth) Encode

func (auth *Auth) Encode() ([]byte, error)

Encode app object

func (*Auth) Get

func (auth *Auth) Get(ctx context.Context, id string) error

Get ...

func (*Auth) GetApp

func (auth *Auth) GetApp(ctx context.Context) (*App, error)

GetApp Get auth app

func (*Auth) GetAppID

func (auth *Auth) GetAppID() string

GetAppID ...

func (*Auth) GetCustomer

func (auth *Auth) GetCustomer(ctx context.Context) (*Customer, error)

GetCustomer Get auth app

func (*Auth) GetCustomerID

func (auth *Auth) GetCustomerID() string

GetCustomerID ...

func (*Auth) GetID

func (auth *Auth) GetID() string

GetID get id

func (*Auth) GetSecret

func (auth *Auth) GetSecret() string

GetSecret get secret key

func (*Auth) GetUser

func (auth *Auth) GetUser(ctx context.Context) (*User, error)

GetUser Get auth user

func (*Auth) GetUserID

func (auth *Auth) GetUserID() string

GetUserID ...

func (*Auth) Init

func (auth *Auth) Init()

Init init new element

func (*Auth) IsAdmin

func (auth *Auth) IsAdmin() bool

IsAdmin ...

func (*Auth) IsAppAuth

func (auth *Auth) IsAppAuth() bool

IsAppAuth ...

func (*Auth) IsCustomerAuth

func (auth *Auth) IsCustomerAuth() bool

IsCustomerAuth ...

func (*Auth) IsOwner

func (auth *Auth) IsOwner(model Model) bool

IsOwner check if auth is owner of model

func (*Auth) IsRevoked

func (auth *Auth) IsRevoked(id string) bool

IsRevoked chceck if token is revoked

func (*Auth) List

func (auth *Auth) List() ModelList

List ...

func (*Auth) New

func (auth *Auth) New() Model

New ...

func (*Auth) ObjectID

func (auth *Auth) ObjectID() interface{}

ObjectID ...

func (*Auth) OnCreate

func (auth *Auth) OnCreate(ctx context.Context) error

OnCreate create event handler

func (*Auth) OnDelete

func (auth *Auth) OnDelete(ctx context.Context) error

OnDelete delete event handler

func (*Auth) OnUpdate

func (auth *Auth) OnUpdate(ctx context.Context) error

OnUpdate update event handler

func (*Auth) Revoke

func (auth *Auth) Revoke(id string) bool

Revoke chceck if token is revoked

func (*Auth) SetAppID

func (auth *Auth) SetAppID(id string) error

SetAppID set id

func (*Auth) SetCustomerID

func (auth *Auth) SetCustomerID(id string) error

SetCustomerID set id

func (*Auth) SetID

func (auth *Auth) SetID(id string) error

SetID set id

func (*Auth) SetUserID

func (auth *Auth) SetUserID(id string) error

SetUserID set id

func (*Auth) String

func (auth *Auth) String() string

func (*Auth) Type

func (auth *Auth) Type() string

Type ...

func (*Auth) Update

func (auth *Auth) Update(ctx context.Context) error

Update ...

type AuthList

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

AuthList ...

func (*AuthList) All

func (auths *AuthList) All() []*Auth

All ...

func (*AuthList) Collection

func (auths *AuthList) Collection() string

Collection ...

func (*AuthList) Find

func (auths *AuthList) Find(ctx context.Context, user, customer, app string, active bool) error

Find find auths

func (*AuthList) Get

func (auths *AuthList) Get(ctx context.Context, start string, limit int) error

Get ...

func (*AuthList) GetByUser

func (auths *AuthList) GetByUser(ctx context.Context, user, start string, limit int) error

GetByUser get all

func (*AuthList) Index

func (auths *AuthList) Index(index int) Model

Index ...

func (*AuthList) Length

func (auths *AuthList) Length() int

Length ...

func (*AuthList) New

func (auths *AuthList) New() Model

New new auth

type AuthProvider

type AuthProvider interface {
	GetUserID() string
}

AuthProvider ...

type Cache

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

Cache ...

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete ...

func (*Cache) Disable

func (c *Cache) Disable()

Disable ...

func (*Cache) Enable

func (c *Cache) Enable()

Enable ...

func (*Cache) Expiration

func (c *Cache) Expiration(duration time.Duration)

Expiration ...

func (*Cache) Get

func (c *Cache) Get(key string) Model

Get Get element from cache

func (*Cache) GetKey

func (c *Cache) GetKey(collection, id string) string

GetKey ...

func (*Cache) Reset

func (c *Cache) Reset()

Reset ...

func (*Cache) Save

func (c *Cache) Save(key string, model Model)

Save ...

func (*Cache) SaveNoExpire

func (c *Cache) SaveNoExpire(key string, model Model)

SaveNoExpire ...

func (*Cache) SaveWithExpiration

func (c *Cache) SaveWithExpiration(key string, model Model, duration time.Duration)

SaveWithExpiration ...

type CollectionModel

type CollectionModel interface {
	Collection() string
}

CollectionModel collection Model

type Config

type Config struct {
	URL      string `mapstructure:"url"`
	Database string `mapstructure:"database"`

	ConnectTimeout int  `mapstructure:"connect_timeout,omitempty"`
	SocketTimeout  int  `mapstructure:"socket_timeout,omitempty"`
	Monitoring     bool `mapstructure:"monitor,omitempty"`
	Caching        bool `mapstructure:"cache,omitempty"`
	// contains filtered or unexported fields
}

Config database config

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig config with default values

func GetConfig

func GetConfig() *Config

GetConfig ...

type Counter

type Counter struct {
	ID           primitive.ObjectID `bson:"_id,omitempty"`
	Subscription int64              `bson:"subscription,omitempty"`
	Bandwidth    int64              `bson:"bandwidth,omitempty"`
	Customer     *Customer
}

Counter ...

func (*Counter) Cache

func (counter *Counter) Cache(status bool)

Cache counter object

func (*Counter) Cached

func (counter *Counter) Cached(id string) bool

Cached counter

func (*Counter) Collection

func (counter *Counter) Collection() string

Collection get collection

func (*Counter) Create

func (counter *Counter) Create(ctx context.Context) error

Create ...

func (*Counter) CustomerID

func (counter *Counter) CustomerID() primitive.ObjectID

CustomerID ...

func (*Counter) Decode

func (counter *Counter) Decode(data []byte) error

Decode app object

func (*Counter) Delete

func (counter *Counter) Delete(ctx context.Context) error

Delete ...

func (*Counter) Encode

func (counter *Counter) Encode() ([]byte, error)

Encode app object

func (*Counter) Get

func (counter *Counter) Get(ctx context.Context, id string) error

Get ...

func (*Counter) GetCustomer

func (counter *Counter) GetCustomer(ctx context.Context) (*Customer, error)

GetCustomer Get auth app

func (*Counter) GetID

func (counter *Counter) GetID() string

GetID ...

func (*Counter) List

func (counter *Counter) List() ModelList

List ...

func (*Counter) New

func (counter *Counter) New() Model

New create model

func (*Counter) ObjectID

func (counter *Counter) ObjectID() interface{}

ObjectID ...

func (*Counter) OnCreate

func (counter *Counter) OnCreate(ctx context.Context) error

OnCreate create event handler

func (*Counter) OnDelete

func (counter *Counter) OnDelete(ctx context.Context) error

OnDelete delete event handler

func (*Counter) OnUpdate

func (counter *Counter) OnUpdate(ctx context.Context) error

OnUpdate update event handler

func (*Counter) Reset

func (counter *Counter) Reset(ctx context.Context) error

Reset ...

func (*Counter) SetID

func (counter *Counter) SetID(id string) error

SetID set id

func (*Counter) String

func (counter *Counter) String() string

func (*Counter) Type

func (counter *Counter) Type() string

Type ...

func (*Counter) Update

func (counter *Counter) Update(ctx context.Context) error

Update ...

func (*Counter) UpdateBandwidth

func (counter *Counter) UpdateBandwidth(ctx context.Context, value int64) error

UpdateBandwidth add subscription

func (*Counter) UpdateSubscription

func (counter *Counter) UpdateSubscription(ctx context.Context, value int64) error

UpdateSubscription add subscription

type Credentials

type Credentials struct {
	Key    string `bson:"key,omitempty"`
	Secret string `bson:"secret,omitempty"`
}

Credentials for upload

type Customer

type Customer struct {
	ID        primitive.ObjectID `bson:"_id,omitempty"`
	UserID    primitive.ObjectID `bson:"user_id,omitempty"`
	Active    bool               `bson:"active,omitempty"`
	Plan      *Plan              `bson:"plan,omitempty"`
	Webhook   *Webhook           `bson:"webhook,omitempty"`
	CreatedAt time.Time          `bson:"created_at,omitempty"`
	UpdatedAt time.Time          `bson:"updated_at,omitempty"`
	User      *User              `bson:"-"`
	Counter   *Counter           `bson:"-"`
}

Customer Customer Info

func (*Customer) Cache

func (customer *Customer) Cache(status bool)

Cache app object

func (*Customer) CacheKey

func (customer *Customer) CacheKey() string

CacheKey ...

func (*Customer) Cached

func (customer *Customer) Cached(id string) bool

Cached get cached value of app

func (*Customer) Collection

func (customer *Customer) Collection() string

Collection model collection

func (*Customer) Create

func (customer *Customer) Create(ctx context.Context) error

Create ...

func (*Customer) CreateCounter

func (customer *Customer) CreateCounter(ctx context.Context) error

CreateCounter ...

func (*Customer) Decode

func (customer *Customer) Decode(data []byte) error

Decode app object

func (*Customer) Delete

func (customer *Customer) Delete(ctx context.Context) error

Delete ...

func (*Customer) Encode

func (customer *Customer) Encode() ([]byte, error)

Encode app object

func (*Customer) Get

func (customer *Customer) Get(ctx context.Context, id string) error

Get ...

func (*Customer) GetByUserID

func (customer *Customer) GetByUserID(ctx context.Context, user string) error

GetByUserID ...

func (*Customer) GetCounters

func (customer *Customer) GetCounters(ctx context.Context) (*Counter, error)

GetCounters get counters

func (*Customer) GetID

func (customer *Customer) GetID() string

GetID get id

func (*Customer) GetUser

func (customer *Customer) GetUser(ctx context.Context) (*User, error)

GetUser Get auth user

func (*Customer) GetUserID

func (customer *Customer) GetUserID() string

GetUserID ...

func (*Customer) Init

func (customer *Customer) Init()

Init init new element

func (*Customer) List

func (customer *Customer) List() ModelList

List ...

func (*Customer) New

func (customer *Customer) New() Model

New ...

func (*Customer) ObjectID

func (customer *Customer) ObjectID() interface{}

ObjectID ...

func (*Customer) OnCreate

func (customer *Customer) OnCreate(ctx context.Context) error

OnCreate create event handler

func (*Customer) OnDelete

func (customer *Customer) OnDelete(ctx context.Context) error

OnDelete delete event handler

func (*Customer) OnUpdate

func (customer *Customer) OnUpdate(ctx context.Context) error

OnUpdate update event handler

func (*Customer) SetID

func (customer *Customer) SetID(id string) error

SetID set id

func (*Customer) SetUserID

func (customer *Customer) SetUserID(id string) error

SetUserID set user id

func (*Customer) String

func (customer *Customer) String() string

func (*Customer) Type

func (customer *Customer) Type() string

Type ...

func (*Customer) Update

func (customer *Customer) Update(ctx context.Context) error

Update ...

func (*Customer) UpdatePlan

func (customer *Customer) UpdatePlan(subs, bw, rsize, rcount, pcount int64)

UpdatePlan ...

func (*Customer) UpdateWebhook

func (customer *Customer) UpdateWebhook(url string, headers map[string]string)

UpdateWebhook ...

type CustomerList

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

CustomerList ...

func (*CustomerList) All

func (customers *CustomerList) All() []*Customer

All ...

func (*CustomerList) Collection

func (customers *CustomerList) Collection() string

Collection ...

func (*CustomerList) Get

func (customers *CustomerList) Get(ctx context.Context, start string, limit int) error

Get get all

func (*CustomerList) GetByUser

func (customers *CustomerList) GetByUser(ctx context.Context, user, start string, limit int) error

GetByUser ...

func (*CustomerList) Index

func (customers *CustomerList) Index(index int) Model

Index ...

func (*CustomerList) Length

func (customers *CustomerList) Length() int

Length ...

func (*CustomerList) New

func (customers *CustomerList) New() Model

New ...

type Database

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

Database ...

func (*Database) Collection

func (db *Database) Collection(model CollectionModel) *mongo.Collection

Collection get collection from db

func (*Database) Monitor

func (db *Database) Monitor()

Monitor start monitoring

func (*Database) WithTimeout

func (db *Database) WithTimeout(ctx context.Context) (context.Context, context.CancelFunc)

WithTimeout ...

type Error

type Error struct {
	Code     int
	Message  string
	Data     interface{}
	Line     int
	Model    Model
	Function string
	File     string
	Wrapped  error
}

Error ...

func (*Error) Error

func (err *Error) Error() string

Error ...

func (*Error) String

func (err *Error) String() string

String ...

func (*Error) Unwrap

func (err *Error) Unwrap() error

Unwrap ...

type Event

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

Event ...

func (Event) Handler

func (m Event) Handler(handler func(Event, Model)) event.Handler

Handler ...

func (Event) Model

func (m Event) Model() Model

Model ...

func (Event) String

func (m Event) String() string

func (Event) Type

func (m Event) Type() event.Type

Type ...

type EventHandler

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

EventHandler ...

func (EventHandler) Publish

func (m EventHandler) Publish(event event.Event, data event.Data)

Publish ...

type Indexer

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

Indexer database Indexer

func NewIndexer

func NewIndexer() *Indexer

NewIndexer ...

func (*Indexer) Add

func (index *Indexer) Add(model Model, handler func(context.Context, Model)) error

Add add indexer on model

func (*Indexer) Done

func (index *Indexer) Done() bool

Done ...

func (*Indexer) Start

func (index *Indexer) Start(monitor *Monitor) error

Start ...

func (*Indexer) Status

func (index *Indexer) Status() bool

Status ...

type Model

type Model interface {
	CollectionModel
	List() ModelList
	Type() string
	New() Model
	ObjectID() interface{}
	GetID() string
	SetID(string) error
	OnCreate(ctx context.Context) error
	OnUpdate(ctx context.Context) error
	OnDelete(ctx context.Context) error

	Get(ctx context.Context, id string) error
	Create(ctx context.Context) error
	Delete(ctx context.Context) error
	Update(ctx context.Context) error

	// Binary encoder decoder used by caching
	Encode() ([]byte, error)
	Decode([]byte) error

	// Caching
	Cache(status bool)
	Cached(id string) bool
}

Model interface for database model

type ModelList

type ModelList interface {
	CollectionModel
	Length() int
	New() Model
	Index(int) Model
	Get(ctx context.Context, start string, limit int) error
}

ModelList ...

type Monitor

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

Monitor db Monitor

func NewMonitor

func NewMonitor(d time.Duration) *Monitor

NewMonitor ...

func (*Monitor) Interval

func (m *Monitor) Interval() time.Duration

Interval ...

func (*Monitor) Reset

func (m *Monitor) Reset()

Reset ...

func (*Monitor) Running

func (m *Monitor) Running() bool

Running ...

func (*Monitor) SetInterval

func (m *Monitor) SetInterval(d time.Duration)

SetInterval ...

func (*Monitor) Start

func (m *Monitor) Start()

Start ...

func (*Monitor) Status

func (m *Monitor) Status() bool

Status ...

func (*Monitor) Stop

func (m *Monitor) Stop()

Stop stop monitoring

type Plan

type Plan struct {
	Subscription int64 `bson:"subscription,omitempty"`
	Bandwidth    int64 `bson:"bandwidth,omitempty"`
	RoomSize     int64 `bson:"room_size,omitempty"`
	RoomCount    int64 `bson:"room_count,omitempty"`
	PeerCount    int64 `bson:"peer_count,omitempty"`
}

Plan customer Plan

func (*Plan) Update

func (plan *Plan) Update(subs, bw, rsize, rcount, pcount int64)

Update update plan data

type Request

type Request interface {
	Decode([]byte) error
}

Request ...

type Response

type Response interface {
	Encode() ([]byte, error)
}

Response ...

type Room

type Room struct {
	ID          primitive.ObjectID              `bson:"_id,omitempty"`
	CustomerID  primitive.ObjectID              `bson:"customer_id,omitempty"`
	UserID      primitive.ObjectID              `bson:"user_id,omitempty"`
	Key         string                          `bson:"key,omitempty"`
	Name        string                          `bson:"name,omitempty"`
	Active      bool                            `bson:"active,omitempty"`
	Description string                          `bson:"description,omitempty"`
	Roles       []string                        `bson:"roles,omitempty"`
	Size        int                             `bson:"size,omitempty"`
	Locked      bool                            `bson:"locked,omitempty"`
	Waiting     bool                            `bson:"waiting,omitempty"`
	Template    string                          `bson:"template,omitempty"`
	Recording   *RoomRecording                  `bson:"recording,omitempty"`
	Permissions map[string]*RoomPermissionEntry `bson:"permissions,omitempty"`
	CreatedAt   time.Time                       `bson:"created_at,omitempty"`
	UpdatedAt   time.Time                       `bson:"updated_at,omitempty"`
	Customer    *Customer                       `bson:"-"`
	User        *User                           `bson:"-"`
}

Room ...

func (*Room) Cache

func (room *Room) Cache(status bool)

Cache room object

func (*Room) CacheKey

func (room *Room) CacheKey() string

CacheKey ...

func (*Room) Cached

func (room *Room) Cached(id string) bool

Cached get cached value of room

func (*Room) Collection

func (room *Room) Collection() string

Collection model collection

func (*Room) Create

func (room *Room) Create(ctx context.Context) error

Create ...

func (*Room) Decode

func (room *Room) Decode(data []byte) error

Decode room object

func (*Room) Delete

func (room *Room) Delete(ctx context.Context) error

Delete ...

func (*Room) Encode

func (room *Room) Encode() ([]byte, error)

Encode room object

func (*Room) Get

func (room *Room) Get(ctx context.Context, id string) error

Get ...

func (*Room) GetByName

func (room *Room) GetByName(ctx context.Context, customer, name string) error

GetByName ...

func (*Room) GetCustomer

func (room *Room) GetCustomer(ctx context.Context) (*Customer, error)

GetCustomer Get auth room

func (*Room) GetCustomerID

func (room *Room) GetCustomerID() string

GetCustomerID ...

func (*Room) GetID

func (room *Room) GetID() string

GetID get id

func (*Room) GetKey

func (room *Room) GetKey() string

GetKey ...

func (*Room) GetUserID

func (room *Room) GetUserID() string

GetUserID ...

func (*Room) Init

func (room *Room) Init()

Init init new element

func (*Room) List

func (room *Room) List() ModelList

List ...

func (*Room) New

func (room *Room) New() Model

New ...

func (*Room) ObjectID

func (room *Room) ObjectID() interface{}

ObjectID ...

func (*Room) OnCreate

func (room *Room) OnCreate(ctx context.Context) error

OnCreate create event handler

func (*Room) OnDelete

func (room *Room) OnDelete(ctx context.Context) error

OnDelete delete event handler

func (*Room) OnUpdate

func (room *Room) OnUpdate(ctx context.Context) error

OnUpdate update event handler

func (*Room) SetCustomerID

func (room *Room) SetCustomerID(id string) error

SetCustomerID set id

func (*Room) SetID

func (room *Room) SetID(id string) error

SetID set id

func (*Room) SetUserID

func (room *Room) SetUserID(id string) error

SetUserID set id

func (Room) String

func (room Room) String() string

func (*Room) Type

func (room *Room) Type() string

Type ...

func (*Room) Update

func (room *Room) Update(ctx context.Context) error

Update ...

func (*Room) UpdatePermission

func (room *Room) UpdatePermission(role string, publish, subscribe, commands []string)

UpdatePermission ...

func (*Room) UpdateRecording

func (room *Room) UpdateRecording(enabled bool, size int64, duration time.Duration)

UpdateRecording ...

type RoomList

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

RoomList ...

func (*RoomList) All

func (rooms *RoomList) All() []*Room

All ...

func (*RoomList) Collection

func (rooms *RoomList) Collection() string

Collection ...

func (*RoomList) Get

func (rooms *RoomList) Get(ctx context.Context, start string, limit int) error

Get get all

func (*RoomList) GetByUser

func (rooms *RoomList) GetByUser(ctx context.Context, user, start string, limit int) error

GetByUser ...

func (*RoomList) Index

func (rooms *RoomList) Index(index int) Model

Index ...

func (*RoomList) Length

func (rooms *RoomList) Length() int

Length ...

func (*RoomList) New

func (rooms *RoomList) New() Model

New ...

type RoomPermissionEntry

type RoomPermissionEntry struct {
	Publish   []string `bson:"publish,omitempty"`
	Subscribe []string `bson:"subscribe,omitempty"`
	Commands  []string `bson:"commands,omitempty"`
}

RoomPermissionEntry permission for room

type RoomRecording

type RoomRecording struct {
	Enabled  bool          `bson:"enabled,omitempty"`
	Size     int64         `bson:"size,omitempty"`
	Duration time.Duration `bson:"duration,omitempty"`
	Upload   *UploadInfo   `bson:"upload,omitempty"`
}

RoomRecording recording info

func (*RoomRecording) UpdateUploadInfo

func (recording *RoomRecording) UpdateUploadInfo(uploadType, location, prefix string, options map[string]string)

UpdateUploadInfo Update upload info

type Sequence

type Sequence struct {
	ID       string `json:"id" bson:"_id,omitempty"`
	Value    int64  `json:"value,omitempty" bson:"value,omitempty"`
	Customer *Customer
}

Sequence ...

func GetSequence

func GetSequence(name string) *Sequence

GetSequence ...

func (*Sequence) Cache

func (sequence *Sequence) Cache(status bool)

Cache counter object

func (*Sequence) Cached

func (sequence *Sequence) Cached(id string) bool

Cached counter

func (*Sequence) Collection

func (sequence *Sequence) Collection() string

Collection get collection

func (*Sequence) Create

func (sequence *Sequence) Create(ctx context.Context) error

Create ...

func (*Sequence) Decode

func (sequence *Sequence) Decode(data []byte) error

Decode app object

func (*Sequence) Delete

func (sequence *Sequence) Delete(ctx context.Context) error

Delete ...

func (*Sequence) Encode

func (sequence *Sequence) Encode() ([]byte, error)

Encode app object

func (*Sequence) Get

func (sequence *Sequence) Get(ctx context.Context, name string) error

Get ...

func (*Sequence) GetID

func (sequence *Sequence) GetID() string

GetID ...

func (*Sequence) List

func (sequence *Sequence) List() ModelList

List ...

func (*Sequence) MarshalJSON

func (sequence *Sequence) MarshalJSON() ([]byte, error)

MarshalJSON ...

func (*Sequence) Name

func (sequence *Sequence) Name() string

Name create model

func (*Sequence) New

func (sequence *Sequence) New() Model

New create model

func (*Sequence) Next

func (sequence *Sequence) Next(ctx context.Context) (int64, error)

Next get next value of sequence

func (*Sequence) ObjectID

func (sequence *Sequence) ObjectID() interface{}

ObjectID ...

func (*Sequence) OnCreate

func (sequence *Sequence) OnCreate(ctx context.Context) error

OnCreate create event handler

func (*Sequence) OnDelete

func (sequence *Sequence) OnDelete(ctx context.Context) error

OnDelete delete event handler

func (*Sequence) OnUpdate

func (sequence *Sequence) OnUpdate(ctx context.Context) error

OnUpdate update event handler

func (*Sequence) Reset

func (sequence *Sequence) Reset(ctx context.Context, value int64) error

Reset ...

func (*Sequence) SetID

func (sequence *Sequence) SetID(id string) error

SetID set id

func (*Sequence) String

func (sequence *Sequence) String() string

func (*Sequence) Type

func (sequence *Sequence) Type() string

Type ...

func (*Sequence) UnmarshalJSON

func (sequence *Sequence) UnmarshalJSON(data []byte) error

UnmarshalJSON ...

func (*Sequence) Update

func (sequence *Sequence) Update(ctx context.Context) error

Update ...

func (*Sequence) UpdateValue

func (sequence *Sequence) UpdateValue(ctx context.Context) error

UpdateValue add subscription

type Session

type Session struct {
	ID         primitive.ObjectID  `bson:"_id,omitempty"`
	RoomID     primitive.ObjectID  `bson:"room_id,omitempty"`
	CustomerID primitive.ObjectID  `bson:"customer_id,omitempty"`
	UserID     primitive.ObjectID  `bson:"user_id,omitempty"`
	Active     bool                `bson:"active,omitempty"`
	Peers      []string            `bson:"peers,omitempty"`
	Recordings []*SessionRecording `bson:"recordings,omitempty"`
	CreatedAt  time.Time           `bson:"created_at,omitempty"`
	UpdatedAt  time.Time           `bson:"updated_at,omitempty"`
	User       *User               `bson:"-"`
	Customer   *Customer           `bson:"-"`
	Room       *Room               `bson:"-"`
}

Session ...

func (*Session) Cache

func (session *Session) Cache(status bool)

Cache room object

func (*Session) CacheKey

func (session *Session) CacheKey() string

CacheKey ...

func (*Session) Cached

func (session *Session) Cached(id string) bool

Cached get cached value of room

func (*Session) Collection

func (session *Session) Collection() string

Collection model collection

func (*Session) Create

func (session *Session) Create(ctx context.Context) error

Create ...

func (*Session) Decode

func (session *Session) Decode(data []byte) error

Decode session object

func (*Session) Delete

func (session *Session) Delete(ctx context.Context) error

Delete ...

func (*Session) Encode

func (session *Session) Encode() ([]byte, error)

Encode session object

func (*Session) Get

func (session *Session) Get(ctx context.Context, id string) error

Get ...

func (*Session) GetCustomer

func (session *Session) GetCustomer(ctx context.Context) (*Customer, error)

GetCustomer Get auth session

func (*Session) GetCustomerID

func (session *Session) GetCustomerID() string

GetCustomerID ...

func (*Session) GetID

func (session *Session) GetID() string

GetID get id

func (*Session) GetRoom

func (session *Session) GetRoom(ctx context.Context) (*Room, error)

GetRoom Get auth session

func (*Session) GetRoomID

func (session *Session) GetRoomID() string

GetRoomID ...

func (*Session) GetUser

func (session *Session) GetUser(ctx context.Context) (*User, error)

GetUser Get auth session

func (*Session) GetUserID

func (session *Session) GetUserID() string

GetUserID ...

func (*Session) Init

func (session *Session) Init()

Init init new element

func (*Session) List

func (session *Session) List() ModelList

List ...

func (*Session) New

func (session *Session) New() Model

New ...

func (*Session) ObjectID

func (session *Session) ObjectID() interface{}

ObjectID ...

func (*Session) OnCreate

func (session *Session) OnCreate(ctx context.Context) error

OnCreate create event handler

func (*Session) OnDelete

func (session *Session) OnDelete(ctx context.Context) error

OnDelete delete event handler

func (*Session) OnUpdate

func (session *Session) OnUpdate(ctx context.Context) error

OnUpdate update event handler

func (*Session) SetCustomerID

func (session *Session) SetCustomerID(id string) error

SetCustomerID set id

func (*Session) SetID

func (session *Session) SetID(id string) error

SetID set id

func (*Session) SetRoomID

func (session *Session) SetRoomID(id string) error

SetRoomID set id

func (*Session) SetUserID

func (session *Session) SetUserID(id string) error

SetUserID set id

func (Session) String

func (session Session) String() string

func (*Session) Type

func (session *Session) Type() string

Type ...

func (*Session) Update

func (session *Session) Update(ctx context.Context) error

Update ...

func (*Session) UpdateRecording

func (session *Session) UpdateRecording(location string, size int64, duration time.Duration)

UpdateRecording ...

type SessionList

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

SessionList ...

func (*SessionList) All

func (sessions *SessionList) All() []*Session

All ...

func (*SessionList) Collection

func (sessions *SessionList) Collection() string

Collection ...

func (*SessionList) Get

func (sessions *SessionList) Get(ctx context.Context, start string, limit int) error

Get get all

func (*SessionList) GetByUser

func (sessions *SessionList) GetByUser(ctx context.Context, user, start string, limit int) error

GetByUser ...

func (*SessionList) Index

func (sessions *SessionList) Index(index int) Model

Index ...

func (*SessionList) Length

func (sessions *SessionList) Length() int

Length ...

func (*SessionList) New

func (sessions *SessionList) New() Model

New ...

type SessionRecording

type SessionRecording struct {
	Location  string        `bson:"location,omitempty"`
	Size      int64         `bson:"size,omitempty"`
	Available bool          `bson:"available,omitempty"`
	Duration  time.Duration `bson:"closed,omitempty"`
	CreatedAt time.Time     `bson:"created_at,omitempty"`
}

SessionRecording ...

type UploadInfo

type UploadInfo struct {
	Type        string            `bson:"type,omitempty"`
	Location    string            `json:"location,omitempty"`
	Prefix      string            `bson:"prefix,omitempty"`
	Credentials *Credentials      `bson:"credentials,omitempty"`
	Options     map[string]string `bson:"options,omitempty"`
}

UploadInfo is Recording info of the room

func (*UploadInfo) UpdateCredentials

func (up *UploadInfo) UpdateCredentials(key, secret string)

UpdateCredentials update crdentials

type User

type User struct {
	ID         primitive.ObjectID `bson:"_id,omitempty"`
	CustomerID primitive.ObjectID `bson:"customer_id,omitempty"`
	Name       string             `bson:"name,omitempty"`
	Email      string             `bson:"email,omitempty"`
	Phone      string             `bson:"phone,omitempty"`
	Password   string             `bson:"password,omitempty"`
	Active     bool               `bson:"active,omitempty"`
	Admin      bool               `bson:"admin,omitempty"`
	Roles      []string           `bson:"roles,omitempty"`
	CreatedAt  time.Time          `bson:"created_at,omitempty"`
	UpdatedAt  time.Time          `bson:"updated_at,omitempty"`
}

User user info

func (*User) AddRole

func (user *User) AddRole(role string) bool

AddRole ...

func (*User) Cache

func (user *User) Cache(status bool)

Cache app object

func (*User) CacheKey

func (user *User) CacheKey() string

CacheKey ...

func (*User) Cached

func (user *User) Cached(id string) bool

Cached get cached value of app

func (*User) Collection

func (user *User) Collection() string

Collection model collection

func (*User) Create

func (user *User) Create(ctx context.Context) error

Create ...

func (*User) Decode

func (user *User) Decode(data []byte) error

Decode app object

func (*User) Delete

func (user *User) Delete(ctx context.Context) error

Delete ...

func (*User) Encode

func (user *User) Encode() ([]byte, error)

Encode app User

func (*User) Get

func (user *User) Get(ctx context.Context, id string) error

Get ...

func (*User) GetByEmail

func (user *User) GetByEmail(ctx context.Context, email string) error

GetByEmail ...

func (*User) GetID

func (user *User) GetID() string

GetID get id

func (*User) HasRole

func (user *User) HasRole(role string) bool

HasRole ...

func (*User) Init

func (user *User) Init()

Init init new element

func (*User) List

func (user *User) List() ModelList

List ...

func (*User) Locked

func (user *User) Locked() bool

Locked ...

func (*User) New

func (user *User) New() Model

New ...

func (*User) ObjectID

func (user *User) ObjectID() interface{}

ObjectID ...

func (*User) OnCreate

func (user *User) OnCreate(ctx context.Context) error

OnCreate create event handler

func (*User) OnDelete

func (user *User) OnDelete(ctx context.Context) error

OnDelete delete event handler

func (*User) OnUpdate

func (user *User) OnUpdate(ctx context.Context) error

OnUpdate update event handler

func (*User) SetID

func (user *User) SetID(id string) error

SetID set id

func (*User) SetPassword

func (user *User) SetPassword(password string) error

SetPassword ...

func (*User) String

func (user *User) String() string

func (*User) Type

func (user *User) Type() string

Type ...

func (*User) Update

func (user *User) Update(ctx context.Context) error

Update ...

func (*User) VerifyPassword

func (user *User) VerifyPassword(password string) bool

VerifyPassword ...

type UserList

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

UserList ...

func (*UserList) All

func (users *UserList) All() []*User

All ...

func (*UserList) Collection

func (users *UserList) Collection() string

Collection ...

func (*UserList) Get

func (users *UserList) Get(ctx context.Context, start string, limit int) error

Get get all

func (*UserList) Index

func (users *UserList) Index(index int) Model

Index ...

func (*UserList) Length

func (users *UserList) Length() int

Length ...

func (*UserList) Limit

func (users *UserList) Limit() int

Limit ...

func (*UserList) New

func (users *UserList) New() Model

New ...

type UserModelList

type UserModelList interface {
	GetByUser(ctx context.Context, user, start string, limit int) error
}

UserModelList ...

type Webhook

type Webhook struct {
	URL     string            `bson:"url,omitempty"`
	Headers map[string]string `bson:"headers,omitempty"`
}

Webhook ...

Jump to

Keyboard shortcuts

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