httpserver

package
v0.4.0-dev Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewServer

func NewServer(conf Config, handler http.Handler, logger *slog.Logger) (*http.Server, error)

func NewService

func NewService(conf Config, logger *slog.Logger) service.Service

Types

type Config

type Config struct {
	Addr string

	// enables https if not nil
	TLS *tlsprovider.Config

	// if non-empty, a fixed status code returned for all requests
	// when zero, defaults to 200
	StatusCode int

	// allow switching between modes
	// more info in the docs: https://gonetsim.lachlanharris.dev/reference/http
	Mode string

	// root directory to serve files
	// only used in real mode
	RootDir string
}

func (Config) Validate

func (c Config) Validate() error

type FakeHandler

type FakeHandler struct {
	// if non-zero, forces this status code for all responses.
	StatusCode int
	Logger     *slog.Logger
}

func (FakeHandler) ServeHTTP

func (h FakeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type RealHandler

type RealHandler struct {
	// same statuscode implementation as fake mode
	StatusCode int
	RootDir    string
	Logger     *slog.Logger
}

func (RealHandler) ServeHTTP

func (h RealHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Server

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

func (*Server) Name

func (s *Server) Name() string

func (*Server) Start

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

func (*Server) Stop

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

Jump to

Keyboard shortcuts

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