db

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APIKeyDocumentV1Type = "apikey"
	APIKeysCollection    = "apikeys"
)
View Source
const (
	SessionDocumentV1Type = "session"
	SessionsCollection    = "sessions"
)

Variables

This section is empty.

Functions

func Connect

func Connect(ctx context.Context) error

Connect establishes a connection to the database server and a handle to the actual database if neither have been connected.

The following errors are returned by this function: DBConnectFailure

func RemoveExpiredAPIKeysV1

func RemoveExpiredAPIKeysV1(ctx context.Context) error

RemoveExpiredAPIKeysV1 removes APIKeyDocumentV1 documents with expired API keys.

The following errors are returned by this function: DBDeleteFailure

func RemoveExpiredSessionsV1

func RemoveExpiredSessionsV1(ctx context.Context) error

RemoveExpiredSessionsV1 removes SessionDocumentV1 documents with expired sessions.

The following errors are returned by this function: DBDeleteFailure

func RemoveSessionV1

func RemoveSessionV1(ctx context.Context, sessionID string) (int64, error)

RemoveSessionV1 removes the SessionDocumentV1 document with the given session ID from the database if it exists.

The following errors are returned by this function: DBDeleteFailure

Types

type APIKeyDocumentV1

type APIKeyDocumentV1 struct {
	Expires    int64              `bson:"expires"`
	ID         primitive.ObjectID `bson:"_id,omitempty"`
	Key        string             `bson:"key"`
	ObjectType string             `bson:"_objectType"`
	Secret     string             `bson:"secret"`
	Username   string             `bson:"username"`
	Version    uint               `bson:"_version"`
}

APIKeyDocumentV1 represents an individual API key.

func AuthenticateAPIKeyV1

func AuthenticateAPIKeyV1(ctx context.Context, apiKey, apiSecret string) (*APIKeyDocumentV1, error)

AuthenticateAPIKeyV1 checks to see if there is an APIKeyDocumentV1 with a matching API key and secret for the given user in the database.

The following errors are returned by this function: DBQueryFailure

func CreateAPIKeyV1

func CreateAPIKeyV1(ctx context.Context, username, apiKey, apiSecret string, expires int64) (
	*APIKeyDocumentV1, error)

CreateAPIKeyV1 inserts a new APIKeyDocumentV1 object into the database.

The following errors are returned by this function: GeneralFailure, DBInsertFailure

func (*APIKeyDocumentV1) ToJSON

func (d *APIKeyDocumentV1) ToJSON() string

ToJSON renders the document as a JSON string.

type SessionDocumentV1

type SessionDocumentV1 struct {
	Data       map[string]interface{} `bson:"data"`
	Expires    int64                  `bson:"expires"`
	ID         primitive.ObjectID     `bson:"_id,omitempty"`
	ObjectType string                 `bson:"_objectType"`
	SessionID  string                 `bson:"sessionID"`
	Version    uint                   `bson:"_version"`
}

SessionDocumentV1 represents an individual session.

func GetSessionV1

func GetSessionV1(ctx context.Context, sessionID string) (*SessionDocumentV1, error)

GetSessionV1 returns the SessionDocumentV1 object with the matching session ID from the database.

The following errors are returned by this function: DBQueryFailure

func SaveSessionV1

func SaveSessionV1(ctx context.Context, id string, expires int64, data map[string]interface{}) (
	*SessionDocumentV1, error)

SaveSessionV1 creates or updates a SessionDocumentV1 object in the database.

The following errors are returned by this function: GeneralFailure, DBInsertFailure, DBUpdateFailure

func (*SessionDocumentV1) ToJSON

func (d *SessionDocumentV1) ToJSON() string

ToJSON renders the document as a JSON string.

Jump to

Keyboard shortcuts

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