db

package
v1.0.0-beta Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2018 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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(s 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 NewSession

func NewSession(Host string, Username string, Password string, Database string) *mgo.Session

NewSession returns a new Mongo Session.

func PrepareDB

func PrepareDB(session *mgo.Session, db string, dbCollection string, indexes [][]string) *mgo.Collection

PrepareDB ensure presence of persistent and immutable data in the DB.

Types

type AppRepository

type AppRepository interface {
	// GetApp looks up a applications by the app ID.
	GetApp(appID string) (*app.Apps, error)
	GetMyApps(userID string) ([]byte, error)
	GetUserApps(userID string) ([]byte, error)
	RegisterApp(payload *app.AppPayload, userID string) (*app.RegApps, error)
	DeleteApp(appID string) error
	UpdateApp(payload *app.AppPayload, appID string) (*app.Apps, error)
	RegenerateSecret(appID string) ([]byte, error)
	FindApp(id, secret string) (*ClientApp, error)
}

AppRepository defaines the interface for accessing the application data.

type ClientApp

type ClientApp struct {
	ID           string `json:"id" bson:"_id"`
	Name         string `json:"name" bson:"name"`
	Description  string `json:"description,omitempty" bson:"description"`
	Domain       string `json:"domain,omitempty" bson:"domain"`
	Owner        string `json:"owner" bson:"owner"`
	RegisteredAt int64  `json:"registeredAt" bson:"registeredAt"`
	Secret       string `json:"secret" bson:"secret"`
}

ClientApp holds the data for a registered application (client).

type DB

type DB struct {
	sync.Mutex
	// contains filtered or unexported fields
}

DB emulates a database driver using in-memory data structures.

func New

func New() *DB

New initializes a new "DB" with dummy data.

func (*DB) DeleteApp

func (db *DB) DeleteApp(appID string) error

Mock DeleteApp method

func (*DB) FindApp

func (db *DB) FindApp(ID, secret string) (*ClientApp, error)

FindApp tries to find an app with the supplied app ID and secret.

func (*DB) GetApp

func (db *DB) GetApp(appID string) (*app.Apps, error)

Mock GetApp method

func (*DB) GetMyApps

func (db *DB) GetMyApps(userID string) ([]byte, error)

Mock GetUserApps method

func (*DB) GetUserApps

func (db *DB) GetUserApps(userID string) ([]byte, error)

Mock GetUserApps method

func (*DB) RegenerateSecret

func (db *DB) RegenerateSecret(appID string) ([]byte, error)

Mock RegenerateSecret method

func (*DB) RegisterApp

func (db *DB) RegisterApp(payload *app.AppPayload, userID string) (*app.RegApps, error)

Mock RegisterApp method

func (*DB) UpdateApp

func (db *DB) UpdateApp(payload *app.AppPayload, appID string) (*app.Apps, error)

Mock UpdateApp method

type MongoCollection

type MongoCollection struct {
	*mgo.Collection
}

MongoCollection wraps a mgo.Collection to embed methods in models.

func (*MongoCollection) DeleteApp

func (c *MongoCollection) DeleteApp(appID string) error

func (*MongoCollection) FindApp

func (c *MongoCollection) FindApp(ID, secret string) (*ClientApp, error)

FindApp tries to find an application (client) by its ID and secret. Returns nil if no such app is found.

func (*MongoCollection) GetApp

func (c *MongoCollection) GetApp(appID string) (*app.Apps, error)

func (*MongoCollection) GetMyApps

func (c *MongoCollection) GetMyApps(userID string) ([]byte, error)

func (*MongoCollection) GetUserApps

func (c *MongoCollection) GetUserApps(userID string) ([]byte, error)

func (*MongoCollection) RegenerateSecret

func (c *MongoCollection) RegenerateSecret(appID string) ([]byte, error)

func (*MongoCollection) RegisterApp

func (c *MongoCollection) RegisterApp(payload *app.AppPayload, userID string) (*app.RegApps, error)

func (*MongoCollection) UpdateApp

func (c *MongoCollection) UpdateApp(payload *app.AppPayload, appID string) (*app.Apps, error)

Jump to

Keyboard shortcuts

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