handler

package
v0.0.0-...-d3e5ef2 Latest Latest
Warning

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

Go to latest
Published: May 4, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderContentType = "Content-Type"
	MimeJSON          = "application/json"
)

Variables

This section is empty.

Functions

func DecodeJSON

func DecodeJSON[T any]() func(next http.Handler) http.Handler

func FromParamsContext

func FromParamsContext[T any](ctx context.Context) (any, T, bool)

func FromUserContext

func FromUserContext(ctx context.Context) (string, bool)

func LogRequest

func LogRequest(next http.Handler) http.Handler

func MountRoutes

func MountRoutes(r router.Router, h *Handler, v *validator.Validate)

func NewParamsContext

func NewParamsContext[T any](ctx context.Context, t T) context.Context

func NewUserContext

func NewUserContext(ctx context.Context, userID string) context.Context

func RequireAuth

func RequireAuth(signer security.Signer) func(http.Handler) http.Handler

func StartPProf

func StartPProf()

func ValidateInput

func ValidateInput[T any](validate *validator.Validate) func(next http.Handler) http.Handler

Types

type AuthHandler

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

func NewAuthHandler

func NewAuthHandler(userService service.AuthService, signer security.Signer, cfg *config.Config) *AuthHandler

func (*AuthHandler) HandleLogout

func (h *AuthHandler) HandleLogout(w http.ResponseWriter, r *http.Request)

func (*AuthHandler) HandleRefreshToken

func (h *AuthHandler) HandleRefreshToken(w http.ResponseWriter, r *http.Request)

func (*AuthHandler) HandleUserLogin

func (h *AuthHandler) HandleUserLogin(w http.ResponseWriter, r *http.Request)

func (*AuthHandler) HandleUserRegister

func (h *AuthHandler) HandleUserRegister(w http.ResponseWriter, r *http.Request)

func (*AuthHandler) VerifyEmail

func (h *AuthHandler) VerifyEmail(w http.ResponseWriter, r *http.Request)

type BaseHandler

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

func NewBaseHandler

func NewBaseHandler(svc service.BaseService) *BaseHandler

func (*BaseHandler) HandleHealth

func (h *BaseHandler) HandleHealth(w http.ResponseWriter, r *http.Request)

type Handler

type Handler struct {
	Base BaseHandler
	Auth AuthHandler
}

func New

func New(svc service.Service, signer security.Signer, cfg *config.Config) *Handler

type RegisterUserRequest

type RegisterUserRequest struct {
	Email           string `json:"email,omitempty" validate:"required,email"`
	Password        string `json:"password,omitempty" validate:"required"`
	PasswordConfirm string `json:"password_confirm,omitempty" validate:"required,eqfield=Password"`
}

func (*RegisterUserRequest) LogValue

func (r *RegisterUserRequest) LogValue() slog.Value

type RegisterUserResponse

type RegisterUserResponse struct {
	ID        string    `json:"id"`
	Email     string    `json:"email"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type Response

type Response[T any] struct {
	Message string            `json:"message,omitempty"`
	Errors  map[string]string `json:"errors,omitempty"`
	Data    T                 `json:"data,omitempty"`
}

type SafeResponseWriter

type SafeResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func NewSafeResponseWriter

func NewSafeResponseWriter(ctx context.Context, w http.ResponseWriter) *SafeResponseWriter

func (*SafeResponseWriter) BytesWritten

func (w *SafeResponseWriter) BytesWritten() int

func (*SafeResponseWriter) Status

func (w *SafeResponseWriter) Status() int

func (*SafeResponseWriter) Write

func (w *SafeResponseWriter) Write(b []byte) (int, error)

func (*SafeResponseWriter) WriteHeader

func (w *SafeResponseWriter) WriteHeader(statusCode int)

type UserLoginRequest

type UserLoginRequest struct {
	Email    string `json:"email,omitempty" validate:"required,email"`
	Password string `json:"password,omitempty" validate:"required"`
}

func (*UserLoginRequest) LogValue

func (r *UserLoginRequest) LogValue() slog.Value

type UserLoginResponse

type UserLoginResponse struct {
	AccessToken string `json:"access_token,omitempty"`
}

Jump to

Keyboard shortcuts

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