easyshutdown

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2023 License: MIT Imports: 9 Imported by: 0

README

Go

easyshutdown

Gracefully shutdown your Go services in just one line.

This package supports:

  • HTTP and HTTPS servers
  • GRPC server
  • OpenTelemetry tracers
  • And more

Usage

Simple example
package main

import (
	"log"
	"net/http"

	es "github.com/dronezzzko/easyshutdown"
)

func main() {
	srv := &http.Server{
		Addr: ":8080",
	}

	go func() {
		log.Println("starting HTTP server", srv.Addr)

		if err := srv.ListenAndServe(); err != nil {
			log.Fatalf("HTTP server stopped: %s\n", err.Error())
		}
	}()

	sd, _ := es.NewShutdown(
		es.WithHTTPServer(srv),
	)
	sd.Graceful()
}
go run .

Press ctrl+c:

2023/02/04 19:25:04 starting HTTP server :8080
easyshutdown 2023/02/04 19:25:05 Shutting down HTTP/HTTPS server
2023/02/04 19:25:08 HTTP server stopped: http: Server closed
exit status 1

Also see options.go for all available options and supported services.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(sd *Shutdown)

func WithGrpcServer

func WithGrpcServer(srv *grpc.Server) Option

func WithHTTPSServer

func WithHTTPSServer(srv *http.Server) Option

func WithHTTPServer

func WithHTTPServer(srv *http.Server) Option

func WithLogger

func WithLogger(l *log.Logger) Option

func WithShutdownTimeout

func WithShutdownTimeout(d time.Duration) Option

func WithTracerProvider

func WithTracerProvider(t *opentrace.TracerProvider) Option

type Shutdown

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

func NewShutdown

func NewShutdown(options ...Option) (*Shutdown, error)

func (*Shutdown) Graceful

func (s *Shutdown) Graceful()

Jump to

Keyboard shortcuts

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