data

package
v0.0.0-...-3719db4 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidOAuthClient = errors.New("invalid oauth client type")
)
View Source
var (
	ErrInvalidOAuthInfo = errors.New("invalid oauth TokenInfo type")
)

Functions

func GetTimeUTCPointer

func GetTimeUTCPointer() *time.Time

GetTimeUTCPointer gets utc time pointer

func IsUnixZero

func IsUnixZero(t time.Time) bool

func RandString

func RandString(n int) string

RandString generates random sting from characters in letters

func TimeToPointer

func TimeToPointer(t time.Time) *time.Time

func UnixToTimePointer

func UnixToTimePointer(v int64) *time.Time

Types

type DBConf

type DBConf struct {
	Database        string   `toml:"database"`
	Hosts           []string `toml:"hosts"`
	Username        string   `toml:"username"`
	Password        string   `toml:"password"`
	DebugQueries    bool     `toml:"debug_queries"`
	ApplicationName string   `toml:"application_name"`
	MaxConnection   int      `toml:"max_connection"`
	SSLMode         string   `toml:"ssl_mode"`
	DatabaseURL     string   `env:"DATABASE_URL"`
}

DBConf database configuration

func (*DBConf) String

func (cf *DBConf) String() string

String converts database config to a connection url

type Database

type Database struct {
	db.Session
	OAuthToken  *OAuthTokensStore
	OAuthClient *OAuthClientsStore
	User        *UsersStore
}

Database holds database postgres table structure

var DB *Database

DB is a pointer to the database interface

func NewDB

func NewDB(conf DBConf) (*Database, error)

NewDB initializes / opens a new database connection

type OAuthClient

type OAuthClient struct {
	ID     string          `db:"id,omitempty"`
	Secret string          `db:"secret"`
	Domain string          `db:"domain"`
	Data   OAuthClientData `db:"data"`
}

func (*OAuthClient) Store

func (u *OAuthClient) Store(sess db.Session) db.Store

type OAuthClientData

type OAuthClientData struct {
	*models.Client
	*postgresql.JSONBConverter
}

type OAuthClientsStore

type OAuthClientsStore struct {
	db.Collection
}

OAuthClientsStore holds oauth_tokens database collection

func OAuthClients

func OAuthClients(sess db.Session) *OAuthClientsStore

func (*OAuthClientsStore) Create

func (s *OAuthClientsStore) Create(info oauth2.ClientInfo) error

Create creates and stores the new client information

func (*OAuthClientsStore) FindOne

func (s *OAuthClientsStore) FindOne(cond db.Cond) (oauth2.ClientInfo, error)

find one client

func (*OAuthClientsStore) GetByID

func (s *OAuthClientsStore) GetByID(ctx context.Context, id string) (oauth2.ClientInfo, error)

according to the ID for the client information

type OAuthToken

type OAuthToken struct {
	ID        int64          `db:"id,omitempty"`
	CreatedAt *time.Time     `db:"created_at"`
	ExpiresAt time.Time      `db:"expires_at"`
	Code      string         `db:"code"`
	Access    string         `db:"access"`
	Refresh   string         `db:"refresh"`
	Data      OAuthTokenData `db:"data"`
}

func (*OAuthToken) BeforeCreate

func (u *OAuthToken) BeforeCreate(sess db.Session) error

BeforeCreate retrives and sets GetTimeUTCPointer before creating a new oauth token

func (*OAuthToken) Store

func (u *OAuthToken) Store(sess db.Session) db.Store

type OAuthTokenData

type OAuthTokenData struct {
	*models.Token
	*postgresql.JSONBConverter
}

type OAuthTokensStore

type OAuthTokensStore struct {
	db.Collection
}

OAuthTokensStore holds oauth_tokens database collection

func OAuthTokens

func OAuthTokens(sess db.Session) *OAuthTokensStore

func (*OAuthTokensStore) Create

func (s *OAuthTokensStore) Create(ctx context.Context, info oauth2.TokenInfo) error

create and store the new token information

func (*OAuthTokensStore) FindAll

func (s *OAuthTokensStore) FindAll(cond db.Cond) ([]*OAuthToken, error)

find all token

func (*OAuthTokensStore) FindOne

func (s *OAuthTokensStore) FindOne(cond db.Cond) (oauth2.TokenInfo, error)

find one token

func (*OAuthTokensStore) GetByAccess

func (s *OAuthTokensStore) GetByAccess(ctx context.Context, access string) (oauth2.TokenInfo, error)

use the access token for token information data

func (*OAuthTokensStore) GetByCode

func (s *OAuthTokensStore) GetByCode(ctx context.Context, code string) (oauth2.TokenInfo, error)

use the authorization code for token information data

func (*OAuthTokensStore) GetByRefresh

func (s *OAuthTokensStore) GetByRefresh(ctx context.Context, refresh string) (oauth2.TokenInfo, error)

use the refresh token for token information data

func (*OAuthTokensStore) RemoveByAccess

func (s *OAuthTokensStore) RemoveByAccess(ctx context.Context, access string) error

use the access token to delete the token information

func (*OAuthTokensStore) RemoveByCode

func (s *OAuthTokensStore) RemoveByCode(ctx context.Context, code string) error

delete the authorization code

func (*OAuthTokensStore) RemoveByRefresh

func (s *OAuthTokensStore) RemoveByRefresh(ctx context.Context, refresh string) error

use the refresh token to delete the token information

type User

type User struct {
	ID           int64      `db:"id,omitempty" json:"id"`
	Email        string     `db:"email,omitempty" json:"email"`
	PasswordHash string     `db:"password_hash,omitempty" json:"-"`
	Role         UserRole   `db:"role" json:"role"`
	FirstName    string     `db:"first_name,omitempty" json:"firstName"`
	LastName     string     `db:"last_name,omitempty" json:"lastName"`
	Location     string     `db:"location,omitempty" json:"location"`
	Etc          UserEtc    `db:"etc,omitempty" json:"etc"`
	CreatedAt    *time.Time `db:"created_at,omitempty" json:"createdAt"`
	UpdatedAt    *time.Time `db:"updated_at,omitempty" json:"updatedAt"`

	// Display Only
	Biography string `json:"biography"`
	Name      string `json:"name"`
}

User holds postgres data structure for user

func (*User) BeforeCreate

func (u *User) BeforeCreate(sess db.Session) error

BeforeCreate retrives and sets GetTimeUTCPointer before creating a new user

func (*User) BeforeUpdate

func (u *User) BeforeUpdate(sess db.Session) error

BeforeUpdate retrives and sets GetTimeUTCPointer before updating a user

func (*User) Store

func (u *User) Store(sess db.Session) db.Store

Store initializes a session interface that defines methods for database adapters.

type UserEtc

type UserEtc struct {
	HasProfile bool

	*postgresql.JSONBConverter
}

UserEtc is a collection of auxillary key/values around a user

type UserRole

type UserRole string

UserRole is users role

const (
	// UserRoleMember is user role member
	UserRoleMember UserRole = "member"
	// UserRoleAdmin is user role admin
	UserRoleAdmin UserRole = "admin"
	// UserRoleBlocked is user role blocked
	UserRoleBlocked UserRole = "blocked"
)

type UsersStore

type UsersStore struct {
	db.Collection
}

UsersStore holds thread users database collection

func Users

func Users(sess db.Session) *UsersStore

Users retrieves a list of all users

func (UsersStore) FindAll

func (store UsersStore) FindAll(cond ...interface{}) ([]*User, error)

FindAll retrieves users by certain conditions from UsersStore

func (UsersStore) FindByAlias

func (store UsersStore) FindByAlias(alias string) (*User, error)

FindByAlias retrieves a particular user by alias

func (UsersStore) FindByEmail

func (store UsersStore) FindByEmail(email string) (*User, error)

FindByEmail retrieves a particular user by email

func (UsersStore) FindByID

func (store UsersStore) FindByID(ID int64) (*User, error)

FindByID retrieves a particular user by id

func (UsersStore) FindOne

func (store UsersStore) FindOne(cond ...interface{}) (*User, error)

FindOne retrieves user by certain conditions from UsersStore

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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