httpserver

package
v1.4.20 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package httpserver provides http server as module.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Opt

type Opt func(s *Server) error

func WithAddr

func WithAddr(addr string) Opt

WithAddr sets http.Server.Addr.

func WithHandler

func WithHandler(h http.Handler) Opt

WithHandler sets http.Server.Handler.

func WithServer

func WithServer(srv *http.Server) Opt

WithServer sets http.Server for module.

func WithShutdownTimeout

func WithShutdownTimeout(d time.Duration) Opt

WithShutdownTimeout sets timeout for graceful shutdown.

type Server

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

func New

func New(opts ...Opt) *Server

New creates Server module with given options.

Example
package main

import (
	"fmt"
	"net/http"
	"time"

	"github.com/elisasre/go-common/service/module/httpserver"
)

func main() {
	httpserver.New(
		httpserver.WithServer(&http.Server{ReadHeaderTimeout: time.Second}),
		httpserver.WithAddr("127.0.0.1:0"),
		httpserver.WithHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			fmt.Fprint(w, "Hello")
		})),
	)
}
Output:

func (*Server) Init

func (s *Server) Init() error

Init starts net.Listener after applying all options. Options are applied in same order as they were provided.

func (*Server) Name

func (s *Server) Name() string

func (*Server) Run

func (s *Server) Run() error

Run starts serving http request and can be called after initialization.

func (*Server) Stop

func (s *Server) Stop() error

Stop calls shutdown for server.

func (*Server) URL

func (s *Server) URL() string

URL returns server's URL and can be called after initialization.

Directories

Path Synopsis
Package pprof provides pprof handler options for httpserver module.
Package pprof provides pprof handler options for httpserver module.
Package prom provides prometheus metrics handler options for httpserver module.
Package prom provides prometheus metrics handler options for httpserver module.

Jump to

Keyboard shortcuts

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