common

package
v0.0.0-...-9791e59 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2025 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	StartTimeName = "start_time"
	DurationName  = "duration_ms"
	TrafficName   = "traffic"
	CreatedTSName = "created_ts"

	RegionName     = "region"
	ZoneName       = "zone"
	SubZoneName    = "sub_zone"
	HostName       = "host"
	InstanceIdName = "instance_id"

	RequestIdName = "request_id"
	RelatesToName = "relates_to"
	ProtocolName  = "protocol"
	MethodName    = "method"
	FromName      = "from"
	ToName        = "to"
	UrlName       = "url"
	PathName      = "path"

	StatusCodeName = "status_code"
	EncodingName   = "encoding"
	BytesName      = "bytes"

	RouteName   = "route"
	RouteToName = "route_to"

	TimeoutName    = "timeout"
	RateLimitName  = "rate_limit"
	RateBurstName  = "rate_burst"
	ReasonCodeName = "rc"
)
View Source
const (
	PostgresOverride = "x-postgres-override"
)

Variables

This section is empty.

Functions

func QueryT

func QueryT[T Scanner[T]](ctx context.Context, h http.Header, resource, sql string, args ...any) (rows []T, status *messaging.Status)

QueryT - process a SQL select statement, returning a typed array

Example
//e := Entry{}
h := make(http.Header)

rows, status := QueryT[Entry](context.Background(), h, "timeseries", "")

fmt.Printf("test: Query() -> [rows:%v] [status:%v]\n", rows, status)
Output:
fail

func Rows

func Rows[T Scanner[T]](entries []T) ([][]any, *messaging.Status)

Rows - templated function for creating rows

func Scan

func Scan[T Scanner[T]](rows pgx.Rows) ([]T, error)

Scan - templated function for scanning rows

func Unmarshal

func Unmarshal[T Scanner[T]](t any) ([]T, *messaging.Status)

Unmarshal - templated function for JSON unmarshalling

Types

type Attr

type Attr struct {
	Key string
	Val any
}

type Entry

type Entry struct {
	StartTime time.Time `json:"start-time"`
	Duration  int64     `json:"duration"`
	Traffic   string    `json:"traffic"`
	CreatedTS time.Time `json:"created-ts"`

	Region     string `json:"region"`
	Zone       string `json:"zone"`
	SubZone    string `json:"sub-zone"`
	Host       string `json:"host"`
	InstanceId string `json:"instance-id"`

	RequestId string `json:"request-id"`
	RelatesTo string `json:"relates-to"`
	Protocol  string `json:"proto"`
	Method    string `json:"method"`
	From      string `json:"from"`
	To        string `json:"to"`
	Url       string `json:"url"`
	Path      string `json:"path"`

	StatusCode int32  `json:"status-code"`
	Encoding   string `json:"encoding"`
	Bytes      int64  `json:"bytes"`

	Route      string  `json:"route"`
	RouteTo    string  `json:"route-to"`
	Timeout    int32   `json:"timeout"`
	RateLimit  float64 `json:"rate-limit"`
	RateBurst  int32   `json:"rate-burst"`
	ReasonCode string  `json:"rc"`
}

Entry - timeseries access log struct

Example
buf, err := json.Marshal(list)
if err != nil {
	fmt.Printf("test: Entry{} -> [err:%v]\n", err)
} else {
	fmt.Printf("test: Entry{} -> %v\n", string(buf))
}
entry := Entry{}

if v, ok := any(entry).(Variant); ok {
	if v != nil {
	}
	fmt.Printf("test: Query() -> [variant:%v]\n", ok)
}
Output:
fail

func (Entry) Rows

func (Entry) Rows(events []Entry) [][]any

func (Entry) Scan

func (Entry) Scan(columnNames []string, values []any) (log Entry, err error)

func (Entry) Values

func (a Entry) Values() []any

type Scanner

type Scanner[T any] interface {
	Scan(columnNames []string, values []any) (T, error)
	Rows([]T) [][]any
}

Scanner - templated interface for scanning rows

type Variant

type Variant interface {
	Get() ([]byte, *messaging.Status)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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