ds

package
v0.2.20 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(fn AclDSFactory, d IDataSource) (err error)

Meant to be executed on startup, Init loads the acl map in memory. acl maps each grant to a time range. Helps speed up Authorization middleware.

func PatchReceiver

func PatchReceiver() interface{}

func QOFactory

func QOFactory(c *gin.Context, d IDataSource) (*QueryOptions, *TagError)

QueryOptsFactory exported

func UID

func UID(c *gin.Context) string

Returns the authenticated UID or empty string if authentication was skipped.

func Values added in v0.2.12

func Values(d IDataSource) map[string]interface{}

Types

type Acl

type Acl map[Grant]TimeRange

Acl exported

type AclDSFactory

type AclDSFactory func(dsrc IDataSource) (IAclDataSource, error)

AclDSFactory makes a IAclDataSource from a generic dsrc IDataSource.

type DuplicatedEntry added in v0.2.14

type DuplicatedEntry struct {
	msg.Message
}

DuplicatedEntry exported

type ExpiredCredentials

type ExpiredCredentials struct {
	msg.Message
}

ExpiredCredentials exported

type ExpiredPinError

type ExpiredPinError struct {
	msg.Message
}

ExpiredPIN exported

type ForeignKeyConstraint added in v0.2.10

type ForeignKeyConstraint struct {
	msg.Message
}

ForeignKeyConstraint exported

type Grant

type Grant struct {
	Role   string `json:"role"`
	Route  string `json:"route"`
	Method string `json:"method"`
}

Grant exported

func (Grant) Valid

func (g Grant) Valid() bool

Validates if g Grant exists and is valid at the time.

type IAclDataSource added in v0.2.10

type IAclDataSource interface {

	// Returns all grants mapped to its corresponding validity time range.
	Fetch() (Acl, error)
}

Defines an interface for ACL data access.

type IDataSource added in v0.2.10

type IDataSource interface {

	// Must return ds name.
	// i.e. For a db store this is the table name
	Name() string

	Count(qo *QueryOptions) (int64, error)

	Find(qo *QueryOptions) (ResultSetMeta, interface{}, error)

	Fetch(qo *QueryOptions) (ResultSetMeta, []interface{}, error)

	Insert(qo *QueryOptions) error

	Update(qo *QueryOptions) (int64, error)

	Delete(qo *QueryOptions) (int64, error)
}

IDataSource defines an interface for resource data access.

type IPinDataSource added in v0.2.10

type IPinDataSource interface {

	// Post Pin
	Post(email string) (Pin, error)

	// Patch password
	PatchPwd(patch *Patch, crypto lib.ICrypto) error
}

IPinDataSource defines an interface to post pins and patch passwords using a pin.

type IUserDataSource added in v0.2.10

type IUserDataSource interface {

	// Return the active User matching the username
	Get(username string) (User, error)
}

Defines an interface to retrieve user data and modify password.

type InsertError added in v0.2.16

type InsertError struct {
	msg.Message
}

InsertError exported

type InvalidCredentials

type InvalidCredentials struct {
	msg.Message
}

InvalidCredentials exported

type InvalidPinError

type InvalidPinError struct {
	msg.Message
}

InvalidPIN exported

type NotAllowedError

type NotAllowedError struct {
	msg.Message
}

NotAllowedError exported

type NotFoundError

type NotFoundError struct {
	msg.Message
}

NotFoundError exported

type ParamType

type ParamType int64
const (
	Primary ParamType = iota
	Url
	Qry
)

type Params

type Params map[string]string

type Patch

type Patch struct {
	Pin      string `json:"pin"`
	Email    string `json:"usr"`
	Password string `json:"pwd"`
}

func PatchDecoder

func PatchDecoder(pr any) *Patch

type Pin

type Pin struct {
	Email      string    `json:"email"`
	Code       string    `json:"code"`
	Created    time.Time `json:"created"`
	Expiration time.Time `json:"expiration"`
}

func (Pin) Send

func (p Pin) Send()

type PinDSFactory

type PinDSFactory func(p, u IDataSource) (IPinDataSource, error)

AclDSFactory makes a IPinDataSource from generic p(pin) and u(user) IDataSource's.

type QueryOptions

type QueryOptions struct {
	User             User
	DataSource       IDataSource
	Fields           []string
	WritableFields   []string
	Checksum         int
	Dig              []string
	Equal            map[ParamType]Params
	IsNull           []string
	IsNotNull        []string
	In               map[string][]interface{}
	NotIn            map[string][]interface{}
	NotEqual         Params
	GreaterThan      Params
	LessThan         Params
	GreaterEqualThan Params
	LessEqualThan    Params
	Order            []string
	Offset           int
	Limit            *int
}

QueryOpts exported

func (*QueryOptions) Copy

func (qo *QueryOptions) Copy(dsrc IDataSource, params Params) *QueryOptions

type ResultSetMeta

type ResultSetMeta struct {
	Range    string
	Checksum string
}

type TagError

type TagError struct {
	msg.Message
}

TagError exported

func Meta added in v0.2.11

func Meta(d IDataSource) (k, f, w []string, e *TagError)

func TagValuesPivoted

func TagValuesPivoted(dsrc IDataSource, targetTagKey string, pivotTagKey string, pivotTagValues []string) ([]string, *TagError)

Works on structs with two tag sets, let's call them target and pivot.

Returns a slice with the target tag's values, provided the pivot tag name and values are matched.

model is the struct to work with.

tagName is the target tag name.

pivotTagName is the pivot tag name to be matched.

pivotTagFields are the pivot tag values to be matched.

Example:

type User struct {
	 UserID    int64     `db:"user_id"   auth:"id"    json:"user_id"   pk:"1"`
	 RoleID    *int64    `db:"role_id"   auth:"role"  json:"role_id"`
	 Email     string    `db:"email"     auth:"usr"   json:"email"`
}

fields, _ := TagFieldsPivoted(new(User), "auth", []string{"id","role","usr"}) fields -> []string{"user_id","role_id","email"}

type TimeRange

type TimeRange struct {
	From time.Time `json:"from"`
	To   time.Time `json:"to"`
}

TimeRange exported

type UpdateError added in v0.2.16

type UpdateError struct {
	msg.Message
}

UpdateError exported

type User

type User struct {
	UID  string    `json:"uid"`
	Usr  string    `json:"usr"`
	Pwd  string    `json:"pwd"`
	Type string    `json:"type"`
	Role string    `json:"role"`
	TPS  float32   `json:"tps"`
	From time.Time `json:"from"`
	To   time.Time `json:"to"`
}

User exported

type UserDSFactory

type UserDSFactory func(dsrc IDataSource) (IUserDataSource, error)

UserDSFactory makes a IUserDataSource from a generic dsrc IDataSource.

type ValidationErrors added in v0.2.15

type ValidationErrors msg.MessageList

TagError exported

func (*ValidationErrors) Error added in v0.2.15

func (ve *ValidationErrors) Error() string

Error exported

Jump to

Keyboard shortcuts

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