web

package
v0.0.7 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoggerMiddleware

func LoggerMiddleware(logger tools.Logger) func(http.Handler) http.Handler

LoggerMiddleware is a middleware that logs requests and responses middleware uses [DEBUG] level

func OptionalMiddlewares

func OptionalMiddlewares(active bool, middlewares ...func(http.Handler) http.Handler) func(http.Handler) http.Handler

OptionalMiddlewares returns a middleware that applies the given middlewares

Types

type Client

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

func NewClient

func NewClient(logger tools.Logger, baseURL string, prepare ...PrepareClientFn) (client *Client, err error)

NewClient creates a new client instance

func (*Client) Do

func (c *Client) Do(req *http.Request, prepare ...PrepareRequestFn) (*http.Response, error)

Do sends the request and returns the response

func (*Client) Json

func (c *Client) Json(method string, path string, query url.Values, reqBody, respBody any) error

PrepareClient returns a new client with the given prepare functions

type HTMLData added in v0.0.5

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

func NewHTMLData added in v0.0.5

func NewHTMLData(ctx context.Context, tmpl string, data any) *HTMLData

func (*HTMLData) Context added in v0.0.5

func (h *HTMLData) Context() context.Context

func (*HTMLData) Data added in v0.0.5

func (h *HTMLData) Data() any

func (*HTMLData) Template added in v0.0.5

func (h *HTMLData) Template() string

type HTMLResponse added in v0.0.5

type HTMLResponse interface {
	Context() context.Context
	Template() string
	Data() any
}

type PrepareClientFn

type PrepareClientFn func(*http.Client) *http.Client

type PrepareRequestFn

type PrepareRequestFn func(*http.Request) *http.Request

type Response

type Response[T any] struct {
	Success bool   `json:"success"`
	Message string `json:"message,omitempty"`
	Data    T      `json:"data,omitempty"`
}

Response is a generic response structure

func NewResponse

func NewResponse[T any](data T) *Response[T]

NewResponse creates a new response

func (*Response[T]) Write

func (r *Response[T]) Write(code int, wr http.ResponseWriter)

Write writes the response to the writer

type Server

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

func NewServer

func NewServer(logger tools.Logger) *Server

NewServer creates a new server instance

func (*Server) Run

func (s *Server) Run(cancel context.CancelCauseFunc, port int, h http.Handler)

Run starts the server

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

type Template added in v0.0.5

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

func NewTemplate added in v0.0.5

func NewTemplate(log tools.Logger, dir, errorTMPL string) (*Template, error)

NewTemplate создает новый экземпляр шаблона

func ParseTemplate added in v0.0.5

func ParseTemplate(log tools.Logger, tmpl *template.Template, dir string, errorTMPL string) (*Template, error)

ParseTemplate парсит шаблоны из директории

func (*Template) Write added in v0.0.5

func (t *Template) Write(w http.ResponseWriter, code int, data HTMLResponse)

Write записывает шаблон в ответ

Jump to

Keyboard shortcuts

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