handler

package
v0.0.0-...-2da20e2 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package handler contains HTTP handlers for the app's API endpoints. It provides utilities for request binding, validation, and response rendering. Route handlers must not contain any business logic; this belongs in the service layer..

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrIDParamMissingFromRequest is returned when an expected ID URL parameter is absent.
	ErrIDParamMissingFromRequest = app.ErrBadRequest("ID param missing from request")
	// ErrIDParamMustBeInt64 is returned when an ID URL parameter is present but cannot be parsed as a positive int64.
	ErrIDParamMustBeInt64 = app.ErrBadRequest("ID param must be positive int64")
)

Functions

func Abort

func Abort(w http.ResponseWriter, r *http.Request, err error)

Abort serializes and writes an application error (app.Error or app.InputError) to the client, handling appropriate HTTP status codes and logging internal errors.

func GetSessionFromCookie

func GetSessionFromCookie(r *http.Request) string

GetSessionFromCookie retrieves the authentication token string from the request cookies.

func NewSessionCookie

func NewSessionCookie(token string) *http.Cookie

NewSessionCookie creates and returns a new session cookie.

func RenderDefaultLayout

func RenderDefaultLayout(ctx context.Context, w http.ResponseWriter, data layout.Data)

RenderDefaultLayout renders a default layout with provided data.

func RenderTempl

func RenderTempl(ctx context.Context, w http.ResponseWriter, t templ.Component)

RenderTempl renders a templ.Component to the http.ResponseWriter, setting the Content-Type to HTML and the status to 200 OK.

func RenderUserSignInPage

func RenderUserSignInPage(w http.ResponseWriter, r *http.Request, redirectTo string)

RenderUserSignInPage renders the HTML page containing the user sign-in form, optionally specifying a redirect-to path after successful login.

func SetServerJSON

func SetServerJSON(r *http.Request) *http.Request

SetServerJSON marks request context to indicate the response must be JSON.

func ShouldServeJSON

func ShouldServeJSON(r *http.Request) bool

ShouldServeJSON reports whether the current request must be served as JSON.

Types

type Error

type Error struct {
	Code        int               `json:"code"`
	Error       string            `json:"error,omitempty"`
	Errors      []string          `json:"errors,omitempty"`
	InputErrors map[string]string `json:"input_errors,omitempty"`
}

Error is the structure used for serializing and returning structured JSON error responses to the client, categorized by code.

type Fn

type Fn func(w http.ResponseWriter, r *http.Request)

Fn is the function signature for a standard request handler.

type Handler

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

Handler holds dependencies required by request handlers.

func New

func New(service *service.Service, t trace.Tracer) *Handler

New creates and returns a new Handler instance.

func (*Handler) ApplyChangeRequest

func (h *Handler) ApplyChangeRequest(w http.ResponseWriter, r *http.Request)

ApplyChangeRequest applies a pending change request to the entity.

@ID			ApplyChangeRequest
@Summary	Apply a pending change request to the entity.
@Tags		change-requests
@Accept		json
@Produce	json
@Param		id	path		string	true	"Change request ID"
@Success	200		{object}	service.ChangeDiff
@Failure	400		{object}	Error
@Failure	422		{object}	Error
@Failure	500		{object}	Error
@Router		/change-requests/{id}/diff/ [put]
@Security	ApiKeyAuth

func (*Handler) ApproveNewBook

func (h *Handler) ApproveNewBook(w http.ResponseWriter, r *http.Request)

ApproveNewBook approves new book

@ID			ApproveNewBook
@Summary	Approve new book
@Tags		books
@Accept		json
@Produce	json
@Param		id	path		string	true	"Book ID"
@Success	200		{object}	response.Status
@Failure	400		{object}	Error
@Failure	401		{object}	Error
@Failure	500		{object}	Error
@Router		/books/{id}/approve/ [put]
@Security	ApiKeyAuth

func (*Handler) ChangePassword

func (h *Handler) ChangePassword(w http.ResponseWriter, r *http.Request)

ChangePassword handles the API request for an authenticated user to change their password.

@ID			ChangePassword
@Summary	Change user password
@Tags		users
@Accept		json
@Produce	json
@Param		request	body		request.ChangePassword	true	"Old and new passwords"
@Success	200		{object}	response.Status
@Failure	401		{object}	Error "Unauthorized"
@Failure	422		{object}	Error "Validation error or incorrect old password"
@Failure	500		{object}	Error
@Router		/users/password/ [post]
@Security	ApiKeyAuth

func (*Handler) ChangePasswordView

func (h *Handler) ChangePasswordView(w http.ResponseWriter, r *http.Request)

ChangePasswordView renders the static HTML page where a user can manually enter an email confirmation code.

func (*Handler) ChangeUsername

func (h *Handler) ChangeUsername(w http.ResponseWriter, r *http.Request)

ChangeUsername handles the API request for an authenticated user to change their username.

@ID			ChangeUsername
@Summary	Change username
@Tags		users
@Accept		json
@Produce	json
@Param		request	body		request.ChangeUsername	true	"New username and password"
@Success	200		{object}	response.Status
@Failure	401		{object}	Error "Unauthorized"
@Failure	422		{object}	Error "Validation error or incorrect password"
@Failure	500		{object}	Error
@Router		/users/username/ [post]
@Security	ApiKeyAuth

func (*Handler) ChangeUsernameView

func (h *Handler) ChangeUsernameView(w http.ResponseWriter, r *http.Request)

ChangeUsernameView renders the page with the form to change username.

func (*Handler) ConfirmEmail

func (h *Handler) ConfirmEmail(w http.ResponseWriter, r *http.Request)

ConfirmEmail is the API handler for confirming a user's email address via a confirmation code.

@ID			ConfirmEmail
@Summary	Confirm email
@Tags		users
@Accept		json
@Produce	json
@Param		request	body		request.ConfirmEmail	true	"Request body"
@Success	200		{object}	response.Status
@Failure	422		{object}	Error
@Failure	500		{object}	Error
@Router		/users/confirm-email/ [post]
@Security	ApiKeyAuth

func (*Handler) ConfirmEmailChange

func (h *Handler) ConfirmEmailChange(w http.ResponseWriter, r *http.Request)

ConfirmEmailChange handles the confirmation for an email change.

@ID			EmailChangeConfirm
@Summary	Confirm changing user email
@Tags		users
@Accept		json
@Produce	json
@Param		request	body		request.EmailChangeRequest	true	"Old and new passwords"
@Success	200		{object}	response.Status
@Failure	401		{object}	Error "Unauthorized"
@Failure	422		{object}	Error "Validation error"
@Failure	500		{object}	Error
@Router		/users/email/ [post]
@Security	ApiKeyAuth

func (*Handler) ConfirmEmailChangeView

func (h *Handler) ConfirmEmailChangeView(w http.ResponseWriter, r *http.Request)

ConfirmEmailChangeView handles the confirmation link for an email change.

func (*Handler) ConfirmEmailView

func (h *Handler) ConfirmEmailView(w http.ResponseWriter, r *http.Request)

ConfirmEmailView renders the static HTML form page where a user can enter an email confirmation code.

func (*Handler) CreateBook

func (h *Handler) CreateBook(w http.ResponseWriter, r *http.Request)

CreateBook handles the API request for creating a new book.

@ID			CreateBook
@Summary	Create a new book
@Tags		books
@Accept		json
@Produce	json
@Param		request	body		request.CreateBook	true	"Request body"
@Success	201		{object}	ds.Book
@Failure	400		{object}	Error
@Failure	401		{object}	Error
@Failure	500		{object}	Error
@Router		/books/ [post]
@Security	ApiKeyAuth

func (*Handler) CreateBookView

func (h *Handler) CreateBookView(w http.ResponseWriter, r *http.Request)

CreateBookView renders the static HTML page with the form for creating a new book.

func (*Handler) CreatePage

func (h *Handler) CreatePage(w http.ResponseWriter, r *http.Request)

CreatePage handles the API request for creating a new page. TODO add openapi specs when this endpoint becomes public.

func (*Handler) CreatePageView

func (h *Handler) CreatePageView(w http.ResponseWriter, r *http.Request)

CreatePageView renders the static HTML page with the form for creating a new page.

func (*Handler) Dashboard

func (h *Handler) Dashboard(w http.ResponseWriter, r *http.Request)

Dashboard salty dashboard.

func (*Handler) DeleteBook

func (h *Handler) DeleteBook(w http.ResponseWriter, r *http.Request)

DeleteBook handles the API request for updating book.

@ID			DeleteBook
@Summary	Delete book
@Tags		books
@Accept		json
@Produce	json
@Param		id	path		string	true	"Book ID"
@Success	200		{object}	response.Status
@Failure	400		{object}	Error
@Failure	422		{object}	Error
@Failure	500		{object}	Error
@Router		/books/{id}/ [delete]
@Security	ApiKeyAuth

func (*Handler) DeleteFile

func (h *Handler) DeleteFile(w http.ResponseWriter, r *http.Request)

DeleteFile handles file deletion.

@ID			DeleteFile
@Summary	Delete file
@Tags		files
@Accept		json
@Produce	json
@Param		id	path		string	true	"File ID"
@Success	200		{object}	response.Status
@Failure	422		{object}	Error
@Failure	500		{object}	Error
@Router		/files/{id}/ [delete]
@Security	ApiKeyAuth

func (*Handler) DeleteUser

func (h *Handler) DeleteUser(w http.ResponseWriter, r *http.Request)

DeleteUser handles the API request for an authenticated user to delete their account.

@ID			DeleteUser
@Summary	Delete user account
@Tags		users
@Accept		json
@Produce	json
@Param		request	body		request.DeleteUser	true	"Password"
@Success	200		{object}	response.Status
@Failure	401		{object}	Error "Unauthorized"
@Failure	422		{object}	Error "Validation error or incorrect password"
@Failure	500		{object}	Error
@Router		/users/ [delete]
@Security	ApiKeyAuth

func (*Handler) DeleteUserView

func (h *Handler) DeleteUserView(w http.ResponseWriter, r *http.Request)

DeleteUserView renders the page with the form to delete user account.

func (*Handler) EditBookView

func (h *Handler) EditBookView(w http.ResponseWriter, r *http.Request)

EditBookView renders the static HTML page with the form for editing existing book.

func (*Handler) EditPageView

func (h *Handler) EditPageView(w http.ResponseWriter, r *http.Request)

EditPageView renders the static HTML page with the form for editing existing page.

func (*Handler) EventLogChanges

func (h *Handler) EventLogChanges(w http.ResponseWriter, r *http.Request)

EventLogChanges return changes of event log

@ID			EventLogChanges
@Summary	Get changes in an event log
@Tags		event-logs
@Accept		json
@Produce	json
@Param		id	path		string	true	"Event log ID"
@Success	200		{object}	response.EventLogChanges
@Failure	400		{object}	Error
@Failure	422		{object}	Error
@Failure	500		{object}	Error
@Router		/event-logs/ [get]
@Security	ApiKeyAuth

func (*Handler) FilterBooks

func (h *Handler) FilterBooks(w http.ResponseWriter, r *http.Request)

FilterBooks handles API requests for retrieving a filtered list of books.

@ID			FilterBooks
@Summary	Filter books
@Tags		books
@Accept		json
@Produce	json
@Param		params	query		request.FilterBooks			false	"Query parameters"
@Success	200		{object}	response.FilterBooks
@Failure	400		{object}	Error
@Failure	422		{object}	Error
@Failure	500		{object}	Error
@Router		/books/ [get]
@Security	ApiKeyAuth

func (*Handler) FilterBooksView

func (h *Handler) FilterBooksView(w http.ResponseWriter, r *http.Request)

FilterBooksView renders the books listing page with filtering UI.

func (*Handler) FilterChangeRequests

func (h *Handler) FilterChangeRequests(w http.ResponseWriter, r *http.Request)

FilterChangeRequests handles API requests for retrieving a filtered list of change requests.

@ID			FilterChangeRequests
@Summary	Get change requests
@Tags		change-requests
@Accept		json
@Produce	json
@Param		params	query		request.FilterChangeRequests			false	"Query parameters"
@Success	200		{object}	response.FilterChangeRequests
@Failure	400		{object}	Error
@Failure	422		{object}	Error
@Failure	500		{object}	Error
@Router		/change-requests/ [get]
@Security	ApiKeyAuth

func (*Handler) FilterEventLogs

func (h *Handler) FilterEventLogs(w http.ResponseWriter, r *http.Request)

FilterEventLogs handles API requests for retrieving a filtered list of logs.

@ID			FilterEventLogs
@Summary	Get activity log
@Tags		event-logs
@Accept		json
@Produce	json
@Param		params	query		request.FilterEventLogs			false	"Query parameters"
@Success	200		{object}	response.FilterEventLogs
@Failure	400		{object}	Error
@Failure	422		{object}	Error
@Failure	500		{object}	Error
@Router		/event-logs/ [get]
@Security	ApiKeyAuth

func (*Handler) FilterEventLogsView

func (h *Handler) FilterEventLogsView(w http.ResponseWriter, r *http.Request)

FilterEventLogsView renders the logs listing page with filtering UI.

func (*Handler) FilterTopics

func (h *Handler) FilterTopics(w http.ResponseWriter, r *http.Request)

FilterTopics handles the API request for creating a new book.

@ID			FilterTopics
@Summary	Filter topics
@Tags		topics
@Accept		json
@Produce	json
@Param		params	query		request.FilterTopics			false	"Query parameters"
@Success	200		{object}	response.FilterTopics
@Failure	400		{object}	Error
@Failure	422		{object}	Error
@Failure	500		{object}	Error
@Router		/topics/ [get]
@Security	ApiKeyAuth

func (*Handler) GetBook

func (h *Handler) GetBook(w http.ResponseWriter, r *http.Request)

GetBook handles the API request for creating a new book.

@ID			GetBook
@Summary	Get book
@Tags		books
@Accept		json
@Produce	json
@Param		id	path		string	true	"Book ID"
@Success	201		{object}	ds.Book
@Failure	400		{object}	Error
@Failure	401		{object}	Error
@Failure	500		{object}	Error
@Router		/books/{id}/ [get]
@Security	ApiKeyAuth

func (*Handler) GetBookEditState

func (h *Handler) GetBookEditState(w http.ResponseWriter, r *http.Request)

GetBookEditState return state of book changes for current user

@ID			GetBookEditState
@Summary	Get book for editing
@Tags		books
@Accept		json
@Produce	json
@Param		id	path		string	true	"Book ID"
@Success	201		{object}	service.EntityChange
@Failure	400		{object}	Error
@Failure	401		{object}	Error
@Failure	500		{object}	Error
@Router		/books/{id}/edit/ [get]
@Security	ApiKeyAuth

func (*Handler) GetBookView

func (h *Handler) GetBookView(w http.ResponseWriter, r *http.Request)

GetBookView renders a single book details page.

func (*Handler) GetChangeRequestDiff

func (h *Handler) GetChangeRequestDiff(w http.ResponseWriter, r *http.Request)

GetChangeRequestDiff retrieves and returns the diff for a specific change request.

@ID			GetChangeRequestDiff
@Summary	Get change requests diff for review
@Tags		change-requests
@Accept		json
@Produce	json
@Param		id	path string	true "Change request ID"
@Success	200		{object}	response.ChangeRequestDiff
@Failure	400		{object}	Error
@Failure	422		{object}	Error
@Failure	500		{object}	Error
@Router		/change-requests/{id}/diff/ [get]
@Security	ApiKeyAuth

func (*Handler) GetFileMetadata

func (h *Handler) GetFileMetadata(w http.ResponseWriter, r *http.Request)

GetFileMetadata returns file metadata.

@ID			GetFileMetadata
@Summary	Get file metadata
@Tags		files
@Accept		json
@Produce	json
@Param		id	path		string	true	"File ID"
@Success	200		{object}	ds.File
@Failure	422		{object}	Error
@Failure	500		{object}	Error
@Router		/files/{id}/ [get]
@Security	ApiKeyAuth

func (*Handler) GetPageEditState

func (h *Handler) GetPageEditState(w http.ResponseWriter, r *http.Request)

GetPageEditState return state of page changes for current user

@ID			GetPageEditState
@Summary	Get page for editing
@Tags		books
@Accept		json
@Produce	json
@Param		id	path		string	true	"Page ID"
@Success	201		{object}	service.EntityChange
@Failure	400		{object}	Error
@Failure	401		{object}	Error
@Failure	500		{object}	Error
@Router		/pages/{id}/edit/ [get]
@Security	ApiKeyAuth

func (*Handler) Home

func (h *Handler) Home(w http.ResponseWriter, r *http.Request)

Home sweet home.

func (*Handler) OAuthComplete

func (h *Handler) OAuthComplete(w http.ResponseWriter, r *http.Request)

OAuthComplete ...

func (*Handler) OAuthStart

func (h *Handler) OAuthStart(w http.ResponseWriter, r *http.Request)

OAuthStart ...

func (*Handler) PasswordResetConfirm

func (h *Handler) PasswordResetConfirm(w http.ResponseWriter, r *http.Request)

PasswordResetConfirm handles the form submission for resetting the password.

@ID			PasswordResetConfirm
@Summary	Password reset
@Tags		users
@Accept		json
@Produce	json
@Param		request	body		request.PasswordReset	true	"Request body"
@Success	200		{object}	response.Status
@Failure	422		{object}	Error
@Failure	500		{object}	Error
@Router		/users/password-reset/ [post]
@Security	ApiKeyAuth

func (*Handler) PasswordResetConfirmView

func (h *Handler) PasswordResetConfirmView(w http.ResponseWriter, r *http.Request)

PasswordResetConfirmView renders the page with the form to reset the password.

func (*Handler) PasswordResetRequest

func (h *Handler) PasswordResetRequest(w http.ResponseWriter, r *http.Request)

PasswordResetRequest handles the form submission for requesting a password reset.

@ID			PasswordResetRequest
@Summary	Initiate password reset
@Tags		users
@Accept		json
@Produce	json
@Param		request	body		request.PasswordResetRequest	true	"Request body"
@Success	200		{object}	response.Status
@Failure	422		{object}	Error
@Failure	500		{object}	Error
@Router		/users/password-reset-request/ [post]
@Security	ApiKeyAuth

func (*Handler) PasswordResetRequestView

func (h *Handler) PasswordResetRequestView(w http.ResponseWriter, r *http.Request)

PasswordResetRequestView renders the page with the form to request a password reset.

func (*Handler) RejectChangeRequest

func (h *Handler) RejectChangeRequest(w http.ResponseWriter, r *http.Request)

RejectChangeRequest rejects a pending change request with a review note.

@ID			RejectChangeRequest
@Summary	Reject a pending change request
@Tags		change-requests
@Accept		json
@Produce	json
@Param		request	body		request.RejectBook	true	"Request body"
@Param		id	path		string	true	"Change request ID"
@Success	200		{object}	service.ChangeDiff
@Failure	400		{object}	Error
@Failure	422		{object}	Error
@Failure	500		{object}	Error
@Router		/change-requests/{id}/diff/ [put]
@Security	ApiKeyAuth

func (*Handler) RejectNewBook

func (h *Handler) RejectNewBook(w http.ResponseWriter, r *http.Request)

RejectNewBook approves new book

@ID			RejectNewBook
@Summary	Reject new book
@Tags		books
@Accept		json
@Produce	json
@Param		id	path		string	true	"Book ID"
@Param		request	body		request.RejectBook	true	"Request body"
@Success	201		{object}	response.Status
@Failure	400		{object}	Error
@Failure	401		{object}	Error
@Failure	500		{object}	Error
@Router		/books/{id}/reject/ [put]
@Security	ApiKeyAuth

func (*Handler) RenderFile

func (h *Handler) RenderFile(w http.ResponseWriter, r *http.Request)

RenderFile serves the file content.

func (*Handler) RenderPageOrNotFound

func (h *Handler) RenderPageOrNotFound(w http.ResponseWriter, r *http.Request)

RenderPageOrNotFound ...

func (*Handler) RequestEmailChange

func (h *Handler) RequestEmailChange(w http.ResponseWriter, r *http.Request)

RequestEmailChange handles the request for an email change.

@ID			EmailChangeRequest
@Summary	Request to change user email
@Tags		users
@Accept		json
@Produce	json
@Param		request	body		request.EmailChangeRequest	true	"Old and new passwords"
@Success	200		{object}	response.Status
@Failure	401		{object}	Error "Unauthorized"
@Failure	422		{object}	Error "Validation error"
@Failure	500		{object}	Error
@Router		/users/email/ [post]
@Security	ApiKeyAuth

func (*Handler) RequestEmailChangeView

func (h *Handler) RequestEmailChangeView(w http.ResponseWriter, r *http.Request)

RequestEmailChangeView renders the page with the form to request an email change.

func (*Handler) SearchBooks

func (h *Handler) SearchBooks(w http.ResponseWriter, r *http.Request)

SearchBooks handles search across books, books authors and books topics.

@ID			SearchBooks
@Summary	Search books
@Tags		books
@Produce	json
@Param		search	query		string	true	"Search query"
@Success	200		{array}	[]service.SearchBooksResult
@Failure	400		{object}	Error
@Failure	422		{object}	Error
@Failure	500		{object}	Error
@Router		/books/search/ [get]

func (*Handler) SendEmailConfirmationCode

func (h *Handler) SendEmailConfirmationCode(w http.ResponseWriter, r *http.Request)

SendEmailConfirmationCode sends a confirmation code to the authenticated user's email.

@ID			SendEmailConfirmationCode
@Summary	SendE email confirmation code
@Tags		users
@Accept		json
@Produce	json
@Success	200		{object}	response.Status
@Failure	422		{object}	Error
@Failure	500		{object}	Error
@Router		/users/confirm-email/ [post]
@Security	ApiKeyAuth

func (*Handler) ServerStatus

func (h *Handler) ServerStatus(w http.ResponseWriter, r *http.Request)

ServerStatus is an HTTP handler that returns basic information about the running server.

func (*Handler) UpdateBook

func (h *Handler) UpdateBook(w http.ResponseWriter, r *http.Request)

UpdateBook handles the API request for updating book.

@ID			UpdateBook
@Summary	Update book
@Tags		books
@Accept		json
@Produce	json
@Param		id	path		string	true	"Book ID"
@Param		request	body		request.UpdateBook	true	"Request body"
@Success	200		{object}	ds.EntityChangeRequest
@Failure	400		{object}	Error
@Failure	422		{object}	Error
@Failure	500		{object}	Error
@Router		/books/{id}/ [put]
@Security	ApiKeyAuth

func (*Handler) UpdatePage

func (h *Handler) UpdatePage(w http.ResponseWriter, r *http.Request)

UpdatePage handles the API request for updating page.

@ID			UpdatePage
@Summary	Update page
@Tags		pages
@Accept		json
@Produce	json
@Param		id	path		string	true	"Page ID"
@Param		request	body		request.UpdatePage	true	"Request body"
@Success	200		{object}	ds.EntityChangeRequest
@Failure	400		{object}	Error
@Failure	422		{object}	Error
@Failure	500		{object}	Error
@Router		/pages/{id}/ [put]
@Security	ApiKeyAuth

func (*Handler) UploadFile

func (h *Handler) UploadFile(w http.ResponseWriter, r *http.Request)

UploadFile is a handler for file upload.

@ID			UploadFile
@Summary	Upload file
@Tags		files
@Accept		mpfd
@Produce	json
@Param		file	body		[]byte	true	"File"
@Param		purpose	body		string	true	"File purpose"
@Success	201		{object}	response.Status
@Failure	422		{object}	Error
@Failure	500		{object}	Error
@Router		/files/ [post]
@Security	ApiKeyAuth

func (*Handler) UserSettingsView

func (h *Handler) UserSettingsView(w http.ResponseWriter, r *http.Request)

UserSettingsView renders the static HTML page where a user can manually enter an email confirmation code.

func (*Handler) UserSignIn

func (h *Handler) UserSignIn(w http.ResponseWriter, r *http.Request)

UserSignIn is the API handler for the user login endpoint.

@ID			UserSignIn
@Summary	User auth
@Tags		users
@Accept		json
@Produce	json
@Param		request	body		request.UserSignIn	true	"Request body"
@Success	200		{object}	response.UserSignIn
@Failure	422		{object}	Error
@Failure	500		{object}	Error
@Router		/users/sign-in/ [post]
@Security	ApiKeyAuth

TODO either email or username can be used to login.

func (*Handler) UserSignInView

func (h *Handler) UserSignInView(w http.ResponseWriter, r *http.Request)

UserSignInView renders the static HTML form for user login. It is a wrapper around the RenderUserSignInPage helper.

func (*Handler) UserSignOut

func (h *Handler) UserSignOut(w http.ResponseWriter, r *http.Request)

UserSignOut handles user log-out by clearing the session cookie and deleting the session record from the database.

@ID			UserSignOut
@Summary	Logout
@Tags		users
@Produce	json
@Success	200		{object}	response.Status
@Failure	422		{object}	Error
@Failure	500		{object}	Error
@Router		/users/sign-out/ [post]
@Security	ApiKeyAuth

func (*Handler) UserSignUp

func (h *Handler) UserSignUp(w http.ResponseWriter, r *http.Request)

UserSignUp is the API handler for user registration.

@ID			UserSignUp
@Summary	User registration
@Tags		users
@Accept		json
@Produce	json
@Param		request	body		request.UserSignUp	true	"Request body"
@Success	200		{object}	response.UserSignIn
@Failure	422		{object}	Error
@Failure	500		{object}	Error
@Router		/users/sign-up/ [post]
@Security	ApiKeyAuth

func (*Handler) UserSignUpView

func (h *Handler) UserSignUpView(w http.ResponseWriter, r *http.Request)

UserSignUpView renders the static HTML form for user registration.

type Request

type Request struct {
	Request  *http.Request
	Response http.ResponseWriter
	// contains filtered or unexported fields
}

Request is a wrapper around the standard http.Request and http.ResponseWriter that provides convenience methods for handling the current request/response lifecycle.

func NewRequest

func NewRequest(r *http.Request, w http.ResponseWriter) *Request

NewRequest creates and returns a new Request wrapper object.

func (*Request) Abort

func (h *Request) Abort(err error)

Abort flags the request as aborted and writes the provided error to the response.

func (*Request) AbortUnauthorized

func (h *Request) AbortUnauthorized()

AbortUnauthorized wraps Abort with 401 Unauthorized.

func (*Request) Aborted

func (h *Request) Aborted() bool

Aborted returns true if the request lifecycle has been stopped due to an error.

func (*Request) MapHeaders

func (h *Request) MapHeaders(to any)

MapHeaders parses request headers and maps values to fields in the 'to' struct based on the struct's 'h' tags.

type Sanitizer

type Sanitizer interface {
	Sanitize()
}

Sanitizer is an interface for structs that can clean or normalize their input data.

type Validator

type Validator interface {
	Validate(err *app.InputError)
}

Validator is an interface for structs that can perform custom, multi-field validation.

Jump to

Keyboard shortcuts

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