fw

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CtxKeyHttpRequest = "ctx_http_request"
)
View Source
const PostgresTxConnKey = "GoZeroPostgresTxConnKey"

Variables

This section is empty.

Functions

func CtxWithHttpRequest

func CtxWithHttpRequest(ctx context.Context, req *http.Request) context.Context

func CtxWithTx

func CtxWithTx(ctx context.Context, sqlConn sqlx.SqlConn) context.Context

func DbErr

func DbErr(err error, msg ...string) error

func EncodeSSEEvent

func EncodeSSEEvent(w io.Writer, e *SSEEvent) error

func ErrHandler

func ErrHandler(ctx context.Context, err error) (int, any)

func HostPortFromCtx

func HostPortFromCtx(ctx context.Context) (host string, port string)

func HttpRequestFromCtx

func HttpRequestFromCtx(ctx context.Context) (*http.Request, bool)

func InitSqlConn

func InitSqlConn(cfg DatabaseConf) error

func JwtDataAuthTokenFromCtx

func JwtDataAuthTokenFromCtx(ctx context.Context) string

func JwtDataEmailFromCtx

func JwtDataEmailFromCtx(ctx context.Context) string

func JwtDataFromCtx

func JwtDataFromCtx(ctx context.Context) (userId int64, uid string, email string, authToken string)

func JwtDataUidFromCtx

func JwtDataUidFromCtx(ctx context.Context) string

func JwtDataUserIdFromCtx

func JwtDataUserIdFromCtx(ctx context.Context) int64

func OkResponseHandler

func OkResponseHandler(ctx context.Context, v any) any

func PingDb

func PingDb(ctx context.Context) error

func RemoteAddrFromCtx

func RemoteAddrFromCtx(ctx context.Context) string

func RemoveTxFromCtx

func RemoveTxFromCtx(ctx context.Context) context.Context

func TxFromCtx

func TxFromCtx(ctx context.Context) (sqlConn sqlx.SqlConn, exists bool)

TxFromCtx returns the transaction session from the context. If the session is not found, it returns the default connection. Return exists as false if the session is not found.

func WithNewTx

func WithNewTx(ctx context.Context, fn func(context.Context, sqlx.SqlConn) error) error

func WithTx

func WithTx(ctx context.Context, fn func(context.Context, sqlx.SqlConn) error) error

func WriteJsonResponse

func WriteJsonResponse(ctx context.Context, w http.ResponseWriter, v any, err error)

Types

type BootTask

type BootTask[T any] struct {
	// contains filtered or unexported fields
}

func NewBootTask

func NewBootTask[T any](ctx context.Context, cfg T, name string, fn func(ctx context.Context, cfg T) error) *BootTask[T]

func (*BootTask[T]) Start

func (t *BootTask[T]) Start() error

func (*BootTask[T]) StartAsync

func (t *BootTask[T]) StartAsync() (done chan error)

type DatabaseConf

type DatabaseConf struct {
	Dsn           string `json:"dsn"`
	MigrationsDir string `json:"migrationsDir"`
}

type SSEEvent

type SSEEvent struct {
	Event string `json:"event"`
	Id    string `json:"id"`
	Retry uint64 `json:"retry"`
	Data  []byte `json:"data"`
}

type SSEStream

type SSEStream struct {
	// contains filtered or unexported fields
}

func NewSSEStream

func NewSSEStream(w http.ResponseWriter, r *http.Request) *SSEStream

func (*SSEStream) Publish

func (s *SSEStream) Publish(event *SSEEvent) error

Jump to

Keyboard shortcuts

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