qorexGoHelpers

package module
v0.0.0-...-1e3a046 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2020 License: MIT Imports: 9 Imported by: 0

README

qorexGoHelpers Package

qorexGoHelpers provides a series of library functions and types to be used across all entities.

Response

Gives a standard API response using http status codes and messages. It can also contain an error on a failed api interaction or a data array.

SetStatus(statusCode int, statusText string, err error)

Used to set the returned response or any error

AppendData(entityList []interface{})

Used to append data to the internal data slice. For efficiency data shouldn't be appended as individual items.

GetJson()

Returns a []byte for use with the JSON.Unmarshal functionality

RowDecorator

Using the Wrap() method a collection of Sql/Row can be iterated over and have a callback applied to each individual row

SecretManager

SecretManager allows access to AWS secretManager service by passing in config of secret and region to return a DBConnection struct

Documentation

Index

Constants

View Source
const (
	BadCredentialRequest        = 400
	BadCredentialRequestMessage = "Malformed credential request"
	BadCredentialRequestError   = "SecretManager error, both SecretName and Region must be provided"

	ErrorUnknown = "An unknown error occurred"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DBConnectionConfig

type DBConnectionConfig struct {
	User     string `json:"username"`
	Password string `json:"password"`
	Host     string `json:"host"`
}

type Response

type Response struct {
	Code   int
	Status string
	Data   []interface{}
	Rows   int
	Error  error
}

func (*Response) AppendData

func (r *Response) AppendData(entityList []interface{})

func (*Response) GetJson

func (r *Response) GetJson() []byte

func (*Response) SetStatus

func (r *Response) SetStatus(statusCode int, statusText string, err error)

type RowDecorator

type RowDecorator struct {
	*sql.Rows
	OnScan func([]interface{}, error)
}

https://stackoverflow.com/questions/50046151/loop-through-database-sql-sql-rows-multiple-times Struct that holds a row collection and an OnScan callback func

func Wrap

func Wrap(rows *sql.Rows, onScan func([]interface{}, error)) *RowDecorator

Wrap adds a callback func to the RowDecorator

func (*RowDecorator) Scan

func (rows *RowDecorator) Scan(dest ...interface{}) error

The Scan method overwrites the default Scan behaviour and applies the OnScan callback passing on the params if present

type SecretsConfig

type SecretsConfig struct {
	SecretName string // Instance name to pass in
	Region     string // Region of Secret to pass in
	Response   *Response
}

SecretsConfig is used to set up the connection

func (*SecretsConfig) GenerateDBConnectionFromSecret

func (s *SecretsConfig) GenerateDBConnectionFromSecret() DBConnectionConfig

Jump to

Keyboard shortcuts

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