httpinfra

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: MIT Imports: 27 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDefaultConfig

func NewDefaultConfig() *config

NewDefaultConfig returns a new default config.

func NewOpenTelemetryMiddleware

func NewOpenTelemetryMiddleware(service string) mux.MiddlewareFunc

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option specifies server configuration options.

func WithHost

func WithHost(host string) Option

WithHost sets the host for the server.

func WithIdleTimeout

func WithIdleTimeout(timeout time.Duration) Option

WithIdleTimeout sets the idle timeout for the server.

func WithPort

func WithPort(port int) Option

WithPort sets the port for the server.

func WithReadTimeout

func WithReadTimeout(timeout time.Duration) Option

WithReadTimeout sets the read timeout for the server.

func WithRevision

func WithRevision(revision string) Option

WithRevision sets the revision for the server.

func WithTracer

func WithTracer() Option

WithTracer enables the tracer for the server.

func WithTracerServiceName

func WithTracerServiceName(name string) Option

WithTracerServiceName sets the tracer service name for the server.

func WithVersion

func WithVersion(version string) Option

WithVersion sets the version for the server.

func WithWriteTimeout

func WithWriteTimeout(timeout time.Duration) Option

WithWriteTimeout sets to write timeout for the server.

type RuntimeResponse

type RuntimeResponse struct {
	Hostname     string `json:"hostname"`
	Version      string `json:"version"`
	Revision     string `json:"revision"`
	GOOS         string `json:"goos"`
	GOARCH       string `json:"goarch"`
	Runtime      string `json:"runtime"`
	NumGoroutine string `json:"num_goroutine"`
	NumCPU       string `json:"num_cpu"`
}

type Server

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

func New

func New(ctx context.Context, logger *slog.Logger, opts ...Option) *Server

func (*Server) JSONResponse

func (s *Server) JSONResponse(w http.ResponseWriter, _ *http.Request, result interface{})

JSONResponse is a helper function to write a JSON response to the client.

func (*Server) Run

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

Run starts the HTTP server.

func (*Server) ServeHTTP

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

Jump to

Keyboard shortcuts

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