Documentation
¶
Index ¶
- Constants
- Variables
- func BuildDeleteUri(resource string) string
- func BuildInsertUri(resource string) string
- func BuildQueryUri(resource string) string
- func BuildSql(r *request) string
- func BuildUpdateUri(resource string) string
- func BuildUri(nid string, nss, resource string) string
- func BuildWhere(values map[string][]string) []pgxdml.Attr
- func ClientShutdown()
- func ClientStartup(rsc startup.Resource, credentials startup.Credentials) error
- func GetStatus() *runtime.Status
- func Ping(ctx context.Context) (status *runtime.Status)
- func Query(ctx context.Context, req Request) (result pgx.Rows, status *runtime.Status)
- func Scan[T Scanner[T]](rows pgx.Rows) ([]T, error)
- func Stat(ctx context.Context) (stat *pgxpool.Stat, status *runtime.Status)
- type CommandTag
- type ExecController
- type PingController
- type PingFn
- type QueryController
- type Request
- func NewDeleteRequest(uri, template string, where []pgxdml.Attr, args ...any) Request
- func NewInsertRequest(uri, template string, values [][]any, args ...any) Request
- func NewQueryRequest(uri, template string, where []pgxdml.Attr, args ...any) Request
- func NewQueryRequestFromValues(uri, template string, values map[string][]string, args ...any) Request
- func NewUpdateRequest(uri, template string, attrs []pgxdml.Attr, where []pgxdml.Attr, args ...any) Request
- type Scanner
- type StatusAgent
- type Threshold
Examples ¶
Constants ¶
const ( QueryNSS = "query" SelectNSS = "select" InsertNSS = "insert" UpdateNSS = "update" DeleteNSS = "delete" PingNSS = "ping" StatNSS = "stat" PostgresNID = "postgresql" PingUri = "urn:" + PostgresNID + ":" + PingNSS StatUri = "urn:" + PostgresNID + ":" + StatNSS SelectCmd = 0 InsertCmd = 1 UpdateCmd = 2 DeleteCmd = 3 NullExpectedCount = int64(-1) )
Variables ¶
var (
PkgUri = reflect.TypeOf(any(pkg{})).PkgPath()
)
Functions ¶
func BuildDeleteUri ¶
BuildDeleteUri - build an uri with the Delete NSS
func BuildInsertUri ¶
BuildInsertUri - build an uri with the Insert NSS
func BuildQueryUri ¶
BuildQueryUri - build an uri with the Query NSS
func BuildUpdateUri ¶
BuildUpdateUri - build an uri with the Update NSS
func BuildWhere ¶
BuildWhere - build the []Attr based on the URL query parameters
func ClientShutdown ¶
func ClientShutdown()
func ClientStartup ¶
func ClientStartup(rsc startup.Resource, credentials startup.Credentials) error
ClientStartup - entry point for creating the pooling client and verifying a connection can be acquired
Example ¶
rsc := startup.Resource{Uri: ""}
err := ClientStartup(rsc, nil)
if err == nil {
defer ClientShutdown()
}
fmt.Printf("test: ClientStartup() -> %v\n", err)
Output: test: ClientStartup() -> database URL is empty
func Ping ¶
Ping - function for pinging the database cluster
Example ¶
err := testStartup()
if err != nil {
fmt.Printf("test: testStartup() -> [error:%v]\n", err)
} else {
defer ClientShutdown()
fmt.Printf("test: clientStartup() -> [started:%v]\n", isStarted())
status := Ping(nil)
fmt.Printf("test: Ping(nil) -> %v\n", status)
}
Output: test: clientStartup() -> [started:true] test: Ping(nil) -> OK
func Stat ¶
Stat - function for retrieving runtime stats
Example ¶
err := testStartup()
if err != nil {
fmt.Printf("test: testStartup() -> [error:%v]\n", err)
} else {
defer ClientShutdown()
fmt.Printf("test: clientStartup() -> [started:%v]\n", isStarted())
stat, status := Stat(nil)
fmt.Printf("test: Stat(nil) -> [status:%v] [stat:%v]\n", status, stat != nil)
}
Output: test: clientStartup() -> [started:true] test: Stat(nil) -> [status:OK] [stat:true]
Types ¶
type CommandTag ¶
type CommandTag struct {
Sql string
RowsAffected int64
Insert bool
Update bool
Delete bool
Select bool
}
CommandTag - results from an Exec command
type ExecController ¶
type ExecController interface {
Apply(ctx context.Context, r Request) (pgconn.CommandTag, *runtime.Status)
// contains filtered or unexported methods
}
ExecController - an interface that manages exec resiliency
func NewExecController ¶
func NewExecController(name string, threshold Threshold, logFn log2.AccessHandler) ExecController
NewExecController - create a new resiliency controller
type PingController ¶
type PingController interface {
Apply(ctx context.Context) *runtime.Status
// contains filtered or unexported methods
}
PingController - an interface that manages ping resiliency
func NewPingController ¶
func NewPingController(name string, threshold Threshold, logFn log2.AccessHandler) PingController
NewPingController - create a new resiliency controller
type QueryController ¶
type QueryController interface {
Apply(ctx context.Context, r Request) (pgx.Rows, *runtime.Status)
// contains filtered or unexported methods
}
QueryController - an interface that manages query resiliency
func NewQueryController ¶
func NewQueryController(name string, threshold Threshold, logFn log2.AccessHandler) QueryController
NewQueryController - create a new resiliency controller
type Request ¶
type Request interface {
Uri() string
Method() string
Sql() string
Args() []any
String() string
HttpRequest() *http.Request
}
func NewDeleteRequest ¶
func NewInsertRequest ¶
func NewQueryRequest ¶
type StatusAgent ¶
type StatusAgent interface {
Run()
Stop()
}
StatusAgent - an agent that will manage returning an endpoint back to receiving traffic
func NewStatusAgent ¶
func NewStatusAgent(threshold int, interval time.Duration, query *QueryController, exec *ExecController) (StatusAgent, error)
NewStatusAgent - creation of an agent with configuration