common

package
v0.0.0-...-29bbd77 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *sql.DB

Functions

func AddUsernameToRequest

func AddUsernameToRequest(req *http.Request, username string) *http.Request

func CommonInitialize

func CommonInitialize(c CommonConfig)

func GetQueryInt

func GetQueryInt(req *http.Request, key string) (int, error)

func GetQueryIntOpt

func GetQueryIntOpt(req *http.Request, key string) (int, bool, error)

func MysqlInitConfig

func MysqlInitConfig(config DatabaseConfig) *mysql.Config

func OpenDatabase

func OpenDatabase(config DatabaseConfig) *sql.DB

func ReadStrings

func ReadStrings(rows *sql.Rows) ([]string, error)

func Username

func Username(ctx context.Context) string

func UsernameMiddleware

func UsernameMiddleware(next http.Handler) http.Handler

func WriteErrorFunc

func WriteErrorFunc(knownErrors map[error]ErrorResponse) func(context.Context, http.ResponseWriter, error) error

func WriteResponse

func WriteResponse(ctx context.Context, w http.ResponseWriter, data interface{}) error

func WriteResponseOrErrorFunc

func WriteResponseOrErrorFunc(writeError func(context.Context, http.ResponseWriter, error) error) func(context.Context, http.ResponseWriter, interface{}, error) error

func WriteServerError

func WriteServerError(ctx context.Context, w http.ResponseWriter, err error) error

Types

type CommonConfig

type CommonConfig struct {
	Database DatabaseConfig
}

type DatabaseConfig

type DatabaseConfig struct {
	Host        string
	Port        string
	User        string
	Password    string
	Base        string
	Timeout     int
	MaxLifetime int `yaml:"max_lifetime"`
	MaxConn     int `yaml:"max_conn"`
}

type ErrorResponse

type ErrorResponse struct {
	HTTPCode  int    `json:"-"`
	ErrorCode string `json:"error"`
	Message   string `json:"message"`
}

func (ErrorResponse) Error

func (e ErrorResponse) Error() string

func (ErrorResponse) StatusCode

func (e ErrorResponse) StatusCode() int

type HTTPResponse

type HTTPResponse interface {
	StatusCode() int
}

type NullBool

type NullBool struct {
	sql.NullBool
}

func (NullBool) MarshalJSON

func (ns NullBool) MarshalJSON() ([]byte, error)

func (*NullBool) UnmarshalJSON

func (ns *NullBool) UnmarshalJSON(data []byte) error

type NullString

type NullString struct {
	sql.NullString
}

func (*NullString) CodecDecodeSelf

func (ns *NullString) CodecDecodeSelf(dec *codec.Decoder)

func (*NullString) CodecEncodeSelf

func (ns *NullString) CodecEncodeSelf(enc *codec.Encoder)

func (NullString) MarshalJSON

func (ns NullString) MarshalJSON() ([]byte, error)

func (*NullString) UnmarshalJSON

func (ns *NullString) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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