util

package
v0.0.0-...-3ec4966 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: MIT Imports: 16 Imported by: 3 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	CONTEXT_TIMEOUT = 5 * time.Second
)

Variables

This section is empty.

Functions

func GetContextWithThisTimeout

func GetContextWithThisTimeout(ctx context.Context, timeout time.Duration) (context.Context, context.CancelFunc)

func GetContextWithTimeout

func GetContextWithTimeout(ctx context.Context) (context.Context, context.CancelFunc)

func QuoteBytes

func QuoteBytes(buf []byte) string

func QuoteString

func QuoteString(str string) string

func RandomString

func RandomString(n int) string

func SanitizeSQL

func SanitizeSQL(sql string, args ...interface{}) (string, error)

SanitizeSQL replaces placeholder values with args. It quotes and escapes args as necessary. This function is only safe when standard_conforming_strings is on.

func SendNotification

func SendNotification(
	ctx context.Context,
	projectId string,
	topic string,
	data map[string]string,
) error

func WriteError

func WriteError(w http.ResponseWriter, statusCode int, errorMessage string)

func WriteInternalServerError

func WriteInternalServerError(w http.ResponseWriter)

func WriteJson

func WriteJson(w http.ResponseWriter, res interface{})

func WriteOK

func WriteOK(w http.ResponseWriter)

func WriteStatus

func WriteStatus(w http.ResponseWriter, statusCode int)

func WriteUnauthorized

func WriteUnauthorized(w http.ResponseWriter)

Types

type DatabaseLogger

type DatabaseLogger struct{}

func (*DatabaseLogger) Log

func (d *DatabaseLogger) Log(ctx context.Context, level pgx.LogLevel, msg string, data map[string]interface{})

type Part

type Part interface{}

Part is either a string or an int. A string is raw SQL. An int is a argument placeholder.

type Query

type Query struct {
	Parts []Part
}

func NewQuery

func NewQuery(sql string) (*Query, error)

func (*Query) Sanitize

func (q *Query) Sanitize(args ...interface{}) (string, error)

type Result

type Result struct {
	Ok     bool         `json:"ok"`
	Err    *string      `json:"error,omitempty"`
	Result *interface{} `json:"result,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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