std

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package std provides a standard HTTP implementation of the HTTP server abstraction.

Package std provides a standard HTTP implementation of the HTTP server abstraction.

Package std provides a standard HTTP implementation of the HTTP server abstraction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewErrorHandlerMiddleware

func NewErrorHandlerMiddleware() middleware.IErrorHandlerMiddleware

NewErrorHandlerMiddleware creates a new ErrorHandlerMiddleware.

func NewLoggingMiddleware

func NewLoggingMiddleware() core.ILoggingMiddleware

NewLoggingMiddleware creates a new LoggingMiddleware.

Types

type Context

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

Context is an implementation of core.Context using the standard net/http package.

func (*Context) Abort added in v0.0.6

func (c *Context) Abort()

Abort implements core.Context.Abort It prevents pending handlers in the chain from being called.

func (*Context) Bind

func (c *Context) Bind(obj interface{}) error

Bind implements core.Context.Bind

func (*Context) BindJSON

func (c *Context) BindJSON(obj interface{}) error

BindJSON implements core.Context.BindJSON

func (*Context) DefaultQuery

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

DefaultQuery implements core.Context.DefaultQuery

func (*Context) Error

func (c *Context) Error(err error) error

Error implements core.Context.Error Since the standard HTTP package doesn't have a built-in error handling mechanism, this implementation stores the error in the context and returns it.

func (*Context) Errors

func (c *Context) Errors() []error

Errors implements core.Context.Errors It returns all errors added to the context.

func (*Context) File

func (c *Context) File(filepath string)

File implements core.Context.File

func (*Context) Get

func (c *Context) Get(key string) (interface{}, bool)

Get implements core.Context.Get It returns the value for the given key and a boolean indicating whether the key exists.

func (*Context) GetHeader

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

GetHeader implements core.Context.GetHeader

func (*Context) JSON

func (c *Context) JSON(code int, obj interface{})

JSON implements core.Context.JSON

func (*Context) Next

func (c *Context) Next()

Next implements core.Context.Next It calls the next handler in the chain.

func (*Context) Param

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

Param implements core.Context.Param

func (*Context) Query

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

Query implements core.Context.Query

func (*Context) Redirect

func (c *Context) Redirect(code int, location string)

Redirect implements core.Context.Redirect

func (*Context) Request

func (c *Context) Request() *http.Request

Request implements core.Context.Request

func (*Context) Set

func (c *Context) Set(key string, value interface{})

Set implements core.Context.Set It stores a value in the context for the given key.

func (*Context) SetHeader

func (c *Context) SetHeader(key, value string)

SetHeader implements core.Context.SetHeader

func (*Context) SetStatus

func (c *Context) SetStatus(code int)

SetStatus implements core.Context.SetStatus

func (*Context) ShouldBindJSON

func (c *Context) ShouldBindJSON(obj interface{}) error

ShouldBindJSON implements core.Context.ShouldBindJSON

func (*Context) String

func (c *Context) String(code int, format string, values ...interface{})

String implements core.Context.String

func (*Context) Writer

func (c *Context) Writer() http.ResponseWriter

Writer implements core.Context.Writer

type ErrorHandlerMiddleware

type ErrorHandlerMiddleware struct{}

ErrorHandlerMiddleware is a standard HTTP implementation of middleware.IErrorHandlerMiddleware.

func (*ErrorHandlerMiddleware) Middleware

Middleware returns a middleware function that handles errors for standard HTTP.

type LoggingMiddleware

type LoggingMiddleware struct {
	middleware.BaseLoggingMiddleware
}

LoggingMiddleware is a standard HTTP implementation of core.ILoggingMiddleware.

func (*LoggingMiddleware) Middleware

func (m *LoggingMiddleware) Middleware(config *core.LoggingConfig) core.HandlerFunc

Middleware returns a middleware function that logs API requests for standard HTTP. This implementation can capture the actual status code set by the handler.

type ResponseWriterWrapper

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

ResponseWriterWrapper is a wrapper for http.ResponseWriter that captures the status code.

func (*ResponseWriterWrapper) Status

func (w *ResponseWriterWrapper) Status() int

Status returns the captured status code.

func (*ResponseWriterWrapper) Write

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

Write captures the status code (if not already set) and calls the underlying ResponseWriter's Write.

func (*ResponseWriterWrapper) WriteHeader

func (w *ResponseWriterWrapper) WriteHeader(code int)

WriteHeader captures the status code and calls the underlying ResponseWriter's WriteHeader.

type RouterGroup

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

RouterGroup is an implementation of core.RouterGroup using the standard net/http package.

func (*RouterGroup) DELETE

func (g *RouterGroup) DELETE(path string, handlers ...core.HandlerFunc)

DELETE implements core.RouterGroup.DELETE for RouterGroup

func (*RouterGroup) GET

func (g *RouterGroup) GET(path string, handlers ...core.HandlerFunc)

GET implements core.RouterGroup.GET for RouterGroup

func (*RouterGroup) Group

func (g *RouterGroup) Group(path string) core.RouterGroup

Group implements core.RouterGroup.Group for RouterGroup

func (*RouterGroup) PATCH

func (g *RouterGroup) PATCH(path string, handlers ...core.HandlerFunc)

PATCH implements core.RouterGroup.PATCH for RouterGroup

func (*RouterGroup) POST

func (g *RouterGroup) POST(path string, handlers ...core.HandlerFunc)

POST implements core.RouterGroup.POST for RouterGroup

func (*RouterGroup) PUT

func (g *RouterGroup) PUT(path string, handlers ...core.HandlerFunc)

PUT implements core.RouterGroup.PUT for RouterGroup

func (*RouterGroup) RegisterRouter

func (g *RouterGroup) RegisterRouter(controllers ...core.Controller)

RegisterRouter implements core.RouterGroup.RegisterRouter

func (*RouterGroup) Use

func (g *RouterGroup) Use(middleware ...core.HandlerFunc)

Use implements core.RouterGroup.Use for RouterGroup

type Server

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

Server is an implementation of core.Server using the standard net/http package.

func NewServer

func NewServer(port string, showLogs bool) *Server

NewServer creates a new Server instance using the standard HTTP package. If showLogs is true, logs about the framework, middleware, and routes will be printed to the console. If showLogs is false, these logs will be suppressed.

func (*Server) DELETE

func (s *Server) DELETE(path string, handlers ...core.HandlerFunc)

DELETE implements core.Server.DELETE for Server

func (*Server) GET

func (s *Server) GET(path string, handlers ...core.HandlerFunc)

GET implements core.Server.GET for Server

func (*Server) GetErrorHandlerMiddleware

func (s *Server) GetErrorHandlerMiddleware() core.IErrorHandlerMiddleware

GetErrorHandlerMiddleware returns a standard HTTP-specific error handler middleware.

func (*Server) GetLoggingMiddleware

func (s *Server) GetLoggingMiddleware() core.ILoggingMiddleware

GetLoggingMiddleware returns a standard HTTP-specific logging middleware.

func (*Server) GetPort added in v0.1.3

func (s *Server) GetPort() string

GetPort implements core.Server.GetPort for Server

func (*Server) Group

func (s *Server) Group(path string) core.RouterGroup

Group implements core.Server.Group for Server

func (*Server) NoMethod

func (s *Server) NoMethod(handlers ...core.HandlerFunc)

NoMethod implements core.Server.NoMethod

func (*Server) NoRoute

func (s *Server) NoRoute(handlers ...core.HandlerFunc)

NoRoute implements core.Server.NoRoute

func (*Server) PATCH

func (s *Server) PATCH(path string, handlers ...core.HandlerFunc)

PATCH implements core.Server.PATCH for Server

func (*Server) POST

func (s *Server) POST(path string, handlers ...core.HandlerFunc)

POST implements core.Server.POST for Server

func (*Server) PUT

func (s *Server) PUT(path string, handlers ...core.HandlerFunc)

PUT implements core.Server.PUT for Server

func (*Server) RegisterRouter

func (s *Server) RegisterRouter(controllers ...core.Controller)

RegisterRouter implements core.Server.RegisterRouter

func (*Server) Run

func (s *Server) Run() error

Run implements core.Server.Run for Server

func (*Server) RunTLS

func (s *Server) RunTLS(addr, certFile, keyFile string) error

RunTLS implements core.Server.RunTLS for Server

func (*Server) Shutdown

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

Shutdown implements core.Server.Shutdown for Server

func (*Server) StartLambda

func (s *Server) StartLambda() error

StartLambda starts the server in AWS Lambda mode. This method should be called instead of Run or RunTLS when running in AWS Lambda. This method uses the httpadapter library to convert the standard HTTP handler to a Lambda handler.

Example usage:

import (
    "github.com/mythofleader/go-http-server"
)

func main() {
    s, _ := server.NewServer(server.FrameworkStdHTTP, "8080")
    // ... configure your server ...
    if err := s.StartLambda(); err != nil {
        // Handle error
    }
}

func (*Server) Stop added in v0.0.6

func (s *Server) Stop() error

Stop implements core.Server.Stop for Server

func (*Server) Use

func (s *Server) Use(middleware ...core.HandlerFunc)

Use implements core.Server.Use for Server

Jump to

Keyboard shortcuts

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