jacked

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ReadTimeout           time.Duration
	WriteTimeout          time.Duration
	IdleTimeout           time.Duration
	ReadHeaderTimeout     time.Duration
	MaxConns              int
	TrustedProxies        []string
	AllowedOrigins        []string
	AllowedMethods        []string
	AllowedHeaders        []string
	ExposedHeaders        []string
	AllowCredentials      bool
	MaxAge                time.Duration
	MaxRequestSize        int64
	EnableCompression     bool
	EnableSecurityHeaders bool
	RateLimit             int
	BurstLimit            int
	RateWindow            time.Duration
	CleanupWindow         time.Duration

	Debug bool
	// contains filtered or unexported fields
}

Config holds the server configuration parameters.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a Config struct with default values.

type Context

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

Context represents the context of the current HTTP request.

func (*Context) Abort

func (c *Context) Abort()

Abort prevents further handlers from being executed.

func (*Context) AbortWithError

func (c *Context) AbortWithError(statusCode int, err error) error

AbortWithError sends a JSON error response with the given status code and error, then aborts the context. If the provided error is nil, it uses the default HTTP status text for the given code. Otherwise, it uses the provided error's message. Care should be taken not to expose sensitive internal errors.

func (*Context) BadRequest

func (c *Context) BadRequest(message string) error

BadRequest is a helper function to respond with a 400 Bad Request error. It calls AbortWithError internally. If message is empty, a default "Bad Request" message is used.

func (*Context) InternalServerError

func (c *Context) InternalServerError(originalErr error) error

InternalServerError is a helper function to respond with a 500 Internal Server Error. It calls AbortWithError internally. If the provided err is nil, a default "Internal Server Error" message is used. IMPORTANT: In a production environment, the actual `err` should be logged server-side. Avoid exposing detailed internal error messages to the client.

func (*Context) JSON

func (c *Context) JSON(status int, v interface{}) error

JSON sends a JSON response with the given status code and payload.

func (*Context) Next

func (c *Context) Next() error

Next executes the next handler in the chain.

func (*Context) NotFound

func (c *Context) NotFound(message string) error

NotFound is a helper function to respond with a 404 Not Found error. It calls AbortWithError internally. If message is empty, a default "Not Found" message is used.

func (*Context) Param

func (c *Context) Param(key string) string

Param returns the value of the URL parameter for the given key.

func (*Context) QueryBool

func (c *Context) QueryBool(key string, defaultValue bool) bool

QueryBool returns the boolean value of the query parameter for the given key. If the key is not found or the value is not a valid boolean, it returns the defaultValue. It accepts "true", "1", "false", "0". Case-insensitive for "true" and "false".

func (*Context) QueryInt

func (c *Context) QueryInt(key string, defaultValue int) int

QueryInt returns the integer value of the query parameter for the given key. If the key is not found or the value is not a valid integer, it returns the defaultValue.

func (*Context) QueryString

func (c *Context) QueryString(key string, defaultValue string) string

QueryString returns the value of the query parameter for the given key. If the key is not found, it returns the defaultValue.

func (*Context) Render

func (c *Context) Render(status int, name string, data interface{}) error

Render executes the given HTML template with the provided data and writes it to the response. It sets the Content-Type to "text/html; charset=utf-8".

func (*Context) StreamJSON

func (c *Context) StreamJSON(r io.Reader, v interface{}) error

StreamJSON decodes JSON from the given io.Reader and stores it in the value pointed to by v.

func (*Context) String

func (c *Context) String(status int, message string) error

String sends a string response with the given status code and message.

type HandlerFunc

type HandlerFunc func(*Context) error

HandlerFunc defines the handler function signature for middleware and route handlers.

type Server

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

Server is the main server struct.

func New

func New() *Server

New creates a new Server instance with the default configuration.

func NewWithConfig

func NewWithConfig(config *Config) *Server

NewWithConfig creates a new Server instance with the given configuration.

func (*Server) DELETE

func (s *Server) DELETE(path string, handler HandlerFunc)

DELETE registers a new DELETE request handler with the given path.

func (*Server) GET

func (s *Server) GET(path string, handler HandlerFunc)

GET registers a new GET request handler with the given path.

func (*Server) Handle

func (s *Server) Handle(method, path string, handler HandlerFunc)

Handle registers a new request handler with the given method and path.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string) error

ListenAndServe starts the server and listens for incoming connections on the specified address.

func (*Server) POST

func (s *Server) POST(path string, handler HandlerFunc)

POST registers a new POST request handler with the given path.

func (*Server) PUT

func (s *Server) PUT(path string, handler HandlerFunc)

PUT registers a new PUT request handler with the given path.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP makes the server implement the http.Handler interface.

func (*Server) Shutdown

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

Shutdown gracefully shuts down the server.

func (*Server) Use

func (s *Server) Use(handlers ...HandlerFunc)

Use adds middleware handlers to the server's middleware stack.

type ServerArgs

type ServerArgs struct {
	Port  string
	Host  string
	Debug bool
}

ServerArgs holds command line arguments for the server

func ParseArgs

func ParseArgs(arguments []string) (*ServerArgs, error)

ParseArgs parses command line arguments from the provided string slice.

Jump to

Keyboard shortcuts

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