Documentation
¶
Overview ¶
Package db for database layer connection handling
Index ¶
- func MongoConnect(ctx *context.Context, dbUser, dbPass, dbHost, dbTimeout string, dnsSeed bool) (*mongo.Client, context.Context, context.CancelFunc, error)
- type APIKey
- type Conn
- func (d Conn) Close()
- func (d Conn) Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
- func (d Conn) GenerateAPIKey(name string, tags []string) (string, string, error)
- func (d *Conn) GetAPIKey(host, keyID string) (APIKey, error)
- func (d Conn) Query(ctx context.Context, sql string, optionsAndArgs ...any) (pgx.Rows, error)
- func (d Conn) QueryRow(ctx context.Context, sql string, optionsAndArgs ...any) pgx.Row
- func (d Conn) ValidateAPIKey(id, token string) (string, error)
- func (d *Conn) ValidateConnection() error
- type DBIface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MongoConnect ¶
func MongoConnect(ctx *context.Context, dbUser, dbPass, dbHost, dbTimeout string, dnsSeed bool) (*mongo.Client, context.Context, context.CancelFunc, error)
MongoConnect establishes a connection to a MongoDB cluster https://www.geeksforgeeks.org/how-to-use-go-with-mongodb/
Types ¶
type APIKey ¶
type APIKey struct { Created time.Time `yaml:"created" json:"created" sql:"created"` Updated time.Time `yaml:"updated" json:"updated" sql:"updated"` Name string `yaml:"name" json:"name" sql:"name"` ID uuid.UUID `yaml:"id" json:"id" sql:"id"` Role uuid.UUID `yaml:"role" json:"role" sql:"role"` }
APIKey ApiKey for authentication
type Conn ¶
Conn database connection pool and context
func (Conn) GenerateAPIKey ¶
GenerateAPIKey generate an api key and a public key for a new host
func (*Conn) GetAPIKey ¶
GetAPIKey retrieves an API key from the database TODO: Add validation to the function
func (Conn) ValidateAPIKey ¶
ValidateAPIKey validates an API Key for a host
func (*Conn) ValidateConnection ¶
ValidateConnection validates the pool with a ping
type DBIface ¶
type DBIface interface { Close() Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error) Query(ctx context.Context, sql string, optionsAndArgs ...any) (pgx.Rows, error) QueryRow(ctx context.Context, sql string, optionsAndArgs ...any) pgx.Row GenerateAPIKey(name string, tags []string) (string, string, error) ValidateAPIKey(id, token string) (string, error) }
Click to show internal directories.
Click to hide internal directories.