Documentation ¶
Index ¶
- Variables
- func CancelRequest(r *http.Request) *http.Request
- func Middleware(h ...http.Handler) http.Handler
- func MuxMatcherAnd(priority float64, muxes ...MuxMatcher) *muxMatcherAnd
- func MuxMatcherMethods(priority float64, methods ...string) *muxMatcherMethods
- func MuxMatcherMock(priority float64, test, match bool) *muxMatcherMock
- func MuxMatcherOr(priority float64, muxes ...MuxMatcher) *muxMatcherOr
- func MuxMatcherPattern(priority float64, pattern, start, end string, caseSensitive bool) *muxMatcherPattern
- func NamedArgsFromRequest(r *http.Request) url.Values
- func PanicIf(cond bool, v interface{})
- func PanicRecoveryFromRequest(r *http.Request) interface{}
- func PostgreSQLArray(array interface{}) interface{ ... }
- func SQLNoScan() interface{}
- type BeginTx
- type BoxExec
- type BoxQuery
- type Decoder
- type Encoder
- type ExecContext
- type List
- type ListError
- type Logger
- type Meter
- type MeterConfiguration
- type Mux
- type MuxMatcher
- type Parser
- type PingContext
- type PrepareContext
- type QueryContext
- type QueryRowContext
- type SQL
- func (SQL) BoxExec(sqlResult sql.Result, err error) BoxExec
- func (SQL) BoxQuery(sqlRows *sql.Rows, err error) BoxQuery
- func (SQL) EndTx(tx *sql.Tx, err error) error
- func (SQL) IsDDLCommand(query string) (ok bool)
- func (SQL) IsDMLCommand(query string) (ok bool)
- func (SQL) IsMultipleCommand(query string) (ok bool)
- func (SQL) IsSELECTCommand(query string) (ok bool)
- func (SQL) IsValidCommand(query string) (ok bool)
- func (SQL) NewRoundRobin(ctx context.Context, conns ...SQLConn) SQLConn
- func (SQL) OpenWithDSN(ctx context.Context, dsn string) (conn *sql.DB, err error)
- func (SQL) RemoveComment(query string) (query_ string)
- func (SQL) SetupOrTeardown(ctx context.Context, conn ExecContext, queries ...string) error
- type SQLConn
- type SQLRoundRobinError
- type SQLTxConn
- type Tracer
- func (x Tracer) ForceFlush(ctx context.Context) error
- func (x Tracer) RegisterSpanProcessor(s sdk_trace.SpanProcessor)
- func (x Tracer) Shutdown(ctx context.Context) error
- func (x Tracer) UnregisterSpanProcessor(s sdk_trace.SpanProcessor)
- func (t *Tracer) WithContext(ctx context.Context) context.Context
- type TracerConfiguration
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoResult = errors.New("No result") ErrAlreadyClosed = errors.New("Already closed") ErrOverflow = errors.New("Overflow") ErrInvalidValue = errors.New("Invalid value") ErrTracerServiceNameRequired = errors.New("tracer: service name required") ErrTracerEndpointRequired = errors.New("tracer: endpoint required") )
var ( ErrInvalidTransaction = errors.New("Invalid transaction") ErrInvalidArgumentsScan = errors.New("Invalid arguments for scan") ErrNoColumnsReturned = errors.New("No columns returned") ErrInvalidDatabase = errors.New("Invalid database") )
var ( ErrMultipleCommands = errors.New("Multiple commands") ErrInvalidCommand = errors.New("Invalid command") )
nolint: gochecknoglobals
var (
OTel open_telemetry
)
nolint: gochecknoglobals
Functions ¶
func CancelRequest ¶
CancelRequest will cancel the underlying context from *http.Request.
func Middleware ¶
Middleware create a stack of http.Handler that is cancelable via CancelRequest.
func MuxMatcherAnd ¶
func MuxMatcherAnd(priority float64, muxes ...MuxMatcher) *muxMatcherAnd
func MuxMatcherMethods ¶
MuxMatcherMethods receive multiple methods, if contains asterisk `*` then the priority should be set to 0.
func MuxMatcherMock ¶
func MuxMatcherOr ¶
func MuxMatcherOr(priority float64, muxes ...MuxMatcher) *muxMatcherOr
func MuxMatcherPattern ¶
func MuxMatcherPattern(priority float64, pattern, start, end string, caseSensitive bool) *muxMatcherPattern
MuxMatcherPattern receive pattern of named arguments using a pair of start and end string; if start is empty string, then assuming start is colon `:`, when end is empty string, then assuming end is slash `/`
`/:args1/:args2/:args3` // colon at start of arguments `/:args1:/:args2:/:args3:` // colon at both start and end `/{args1}/{args2}/{args3}` // curly-braces at both start and end
func NamedArgsFromRequest ¶
NamedArgsFromRequest is a helper function that extract url.Values that have been parsed using MuxMatcherPattern, url.Values should not be empty if parsing is successful and should be able to extract further following url.Values, same keys in the pattern result in new value added in url.Values.
func PanicRecoveryFromRequest ¶
PanicRecoveryFromRequest is a helper function that extract error value when panic occurred, the value is saved to *http.Request after recovery process and right before calling mux.PanicHandler.
func PostgreSQLArray ¶
Types ¶
type BoxQuery ¶
type BoxQuery interface { // Scan accept do, a func that accept `i int` as index and returns a List // of pointer. // List == nil // break the loop // len(List) < 1 // skip the current loop // len(List) > 0 // assign the pointer, must be same as the length of columns Scan(row func(i int) List) (err error) }
type ExecContext ¶
type List ¶
type List []interface{}
List extends `[]interface{}`, and it should be used to represent json-like data.
type ListError ¶
type ListError struct{ Errors []error }
ListError is a wrapper to slice of `error`.
type MeterConfiguration ¶
type Mux ¶
type Mux struct { // PanicHandler can access the error recovered via PanicRecoveryFromRequest, // PanicRecoveryFromRequest is a helper under httphandler package PanicHandler http.Handler NotFoundHandler http.Handler Middleware func(next http.Handler) http.Handler // contains filtered or unexported fields }
Mux holds a map of entries.
func (*Mux) Handle ¶
Handle will register http.Handler with MuxMatcherMethods on method and MuxMatcherPattern on pattern, see more details on each mux matcher implementation.
type MuxMatcher ¶
type MuxMatcher interface { // Test is called when MuxMatcher is added to Mux, this should be an // opportunity to set priority and test the implementation parameter // e.g. MuxMatcherPattern should check pattern, start, end Test() bool // Priority is called after Test() returning true to set a priority queue Priority() float64 // Match is called by order of Priority, after its turn, it will validate // the *http.Request and if the result is true, the http.Handler registered // in the entry will be served Match(*http.Request) bool }
MuxMatcher is an incoming *http.Request matcher.
type Parser ¶
type PingContext ¶
type PrepareContext ¶
type QueryContext ¶
type QueryRowContext ¶
type SQL ¶
type SQL struct{}
func (SQL) BoxExec ¶
BoxExec will wrap `ExecContext` so that we can Scan later
BoxExec(cmd.ExecContext(ctx, "..."))
Scan the result of ExecContext that usually return numbers of rowsAffected and lastInsertID.
func (SQL) BoxQuery ¶
BoxQuery will wrap `QueryContext` so that we can Scan later
BoxQuery(cmd.QueryContext(ctx, "..."))
Scan all the rows and map it into []map[string]interface{} using column name as key in the map and then parse it into json format, after that unmarshal into designated dest.
func (SQL) EndTx ¶
EndTx will end transaction with provided *sql.Tx and error. The tx argument should be valid, and then will check the err, if any error occurred, will commencing the ROLLBACK else will COMMIT the transaction.
txc := XSQLTxConn(db) // shared between *sql.Tx, *sql.DB and *sql.Conn if tx, err := db.BeginTx(ctx, nil); err == nil && tx != nil { defer func() { err = xsql.EndTx(tx, err) }() txc = tx }
func (SQL) IsDDLCommand ¶
IsDDLCommand only valid if starts with CREATE, ALTER, DROP, USE, ADD, EXEC, TRUNCATE.
func (SQL) IsDMLCommand ¶
IsDMLCommand only valid if starts with INSERT, UPDATE, DELETE.
func (SQL) IsMultipleCommand ¶
IsMultipleCommand is a naive implementation of checking multiple sql command.
func (SQL) IsSELECTCommand ¶
IsSELECTCommand only valid if starts with SELECT.
func (SQL) IsValidCommand ¶
func (SQL) NewRoundRobin ¶
NewRoundRobin will reduce multiple connections into one with RoundRobin style.
func (SQL) OpenWithDSN ¶
OpenWithDSN will open connection from the given dsn string with URL format, note that any error when opening the database should result in a panic.
func (SQL) RemoveComment ¶
RemoveComment from sql command.
func (SQL) SetupOrTeardown ¶
SetupOrTeardown will execute multiple queries and useful in SETUP/TEARDOWN phase of Behavior Driven Development (BDD). BDD approach is useful to make sure that the SQL Query should satisfied the syntax and reduce integration issues.
type SQLConn ¶
type SQLConn interface { BeginTx io.Closer PingContext SQLTxConn }
SQLConn is a common interface of *sql.DB and *sql.Conn.
type SQLRoundRobinError ¶
type SQLRoundRobinError struct{ Total, Index int }
SQLRoundRobinError reporting issue when getting from set of Conn from SQLRoundRobin.
func (*SQLRoundRobinError) Error ¶
func (e *SQLRoundRobinError) Error() string
type SQLTxConn ¶
type SQLTxConn interface { ExecContext PrepareContext QueryContext QueryRowContext }
SQLTxConn is a common interface of *sql.DB, *sql.Conn, and *sql.Tx.
type Tracer ¶
func (Tracer) ForceFlush ¶
func (Tracer) RegisterSpanProcessor ¶
func (x Tracer) RegisterSpanProcessor(s sdk_trace.SpanProcessor)
func (Tracer) UnregisterSpanProcessor ¶
func (x Tracer) UnregisterSpanProcessor(s sdk_trace.SpanProcessor)