httpserver

package module
v0.0.0-...-da40346 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2023 License: BSD-3-Clause Imports: 11 Imported by: 3

README

HttpServer

Default Go http server with middleware for logging and the option to verbose the request and response.

Usage

	mux := http.NewServeMux()
	mux.HandleFunc("/ping", func(w http.ResponseWriter, _ *http.Request) {
		w.WriteHeader(http.StatusOK)
		_, _ = fmt.Fprintf(w, "pong")
	})
	handler := cors.Default().Handler(mux)
	server := httpserver.NewHttpServer(
		httpserver.WithPort("9082"),
		httpserver.WithHandlers(handler),
		httpserver.WithVerbose(false),
	)
	server.Start(context.Background())

Documentation

Overview

Copyright 2023 The Go SSI Framework Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithHandlers

func WithHandlers(handler http.Handler) func(*HttpServer)

WithHandlers sets the engin to be used by the webserver

func WithPort

func WithPort(port string) func(*HttpServer)

WithPort sets the option of the serving port of the webserver

func WithVerbose

func WithVerbose(verbose bool) func(*HttpServer)

WithVerbose sets the verbosity of the webserver

Types

type HttpServer

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

Server options for the http server

func DefaultOptions

func DefaultOptions() *HttpServer

DefaultOptions sets the default options of the http server

func NewHttpServer

func NewHttpServer(options ...HttpServerOption) *HttpServer

NewHttpServer initializes the http server

func (*HttpServer) Start

func (h *HttpServer) Start(serverContext context.Context) error

Start wilt start the http server, this is the extrnal service function This function includes the graceful shutsown of the server

type HttpServerContext

type HttpServerContext string
const VerboseHttpServer HttpServerContext = "httpserververbose"

type HttpServerOption

type HttpServerOption func(*HttpServer)

func WithHost

func WithHost(hostName string) HttpServerOption

WithHost sets the option of the serving hostname of the webserver

type StatusRecorder

type StatusRecorder struct {
	http.ResponseWriter
	Status  int
	Start   time.Time
	Method  string
	Address string
	Path    string
	// contains filtered or unexported fields
}

func (*StatusRecorder) WriteHeader

func (r *StatusRecorder) WriteHeader(status int)

Jump to

Keyboard shortcuts

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