All Projects → TV4 → Graceful

TV4 / Graceful

Licence: mit
Graceful shutdown of Go 1.8+ servers using Server.Shutdown

Programming Languages

go
31211 projects - #10 most used programming language

Labels

Projects that are alternatives of or similar to Graceful

Snakecase
🐍🐍🐍 A systematic approach to parse strings and automate the conversion to snake_case, UpperCamelCase or any other case.
Stars: ✭ 104 (-15.45%)
Mutual labels:  package
Headlesschrome
A Go package for working with headless Chrome. Run interactive JavaScript commands on web pages with Go and Chrome.
Stars: ✭ 112 (-8.94%)
Mutual labels:  package
Laravel Natural Language
This package makes using the Google Natural API in your laravel app a breeze with minimum to no configuration, clean syntax and a consistent package API.
Stars: ✭ 119 (-3.25%)
Mutual labels:  package
Contracts
A set of reusable smart-contracts
Stars: ✭ 101 (-17.89%)
Mutual labels:  package
Mtcnn
MTCNN face detection implementation for TensorFlow, as a PIP package.
Stars: ✭ 1,689 (+1273.17%)
Mutual labels:  package
Elm Doc Preview
Elm offline documentation previewer
Stars: ✭ 113 (-8.13%)
Mutual labels:  package
Laravel Factory Prefill
Prefills factories with faker method suggestions to increase productivity
Stars: ✭ 104 (-15.45%)
Mutual labels:  package
Guardian
Eloquent Guardian is a simple permissions system for your users. While there are many other packages for permissions, this one solves everything in the most eloquent way.
Stars: ✭ 121 (-1.63%)
Mutual labels:  package
Datepickertimelineflutter
Flutter Date Picker Library that provides a calendar as a horizontal timeline
Stars: ✭ 112 (-8.94%)
Mutual labels:  package
Pie chart
Flutter Pie chart with animation
Stars: ✭ 117 (-4.88%)
Mutual labels:  package
Rando Php
RandoPhp is a open source library that implements random generators (Integer, Char, Byte, Sequences, Boolean) and take random sample from arrays
Stars: ✭ 107 (-13.01%)
Mutual labels:  package
Docusign Node Client
The Official DocuSign Node.js Client Library used to interact with the eSign REST API. Send, sign, and approve documents using this client.
Stars: ✭ 108 (-12.2%)
Mutual labels:  package
Flutter auth buttons
Flutter buttons for social platforms
Stars: ✭ 114 (-7.32%)
Mutual labels:  package
Incrementselection
Add a number to each selection in Sublime Text, incremented once per selection
Stars: ✭ 105 (-14.63%)
Mutual labels:  package
Laravel Optimus
Transform your internal id's to obfuscated integers based on Knuth's integer hash. Laravel wrapper for the Optimus Library by Jens Segers with multiple connections support.
Stars: ✭ 119 (-3.25%)
Mutual labels:  package
Turtlebot3 simulations
Simulations for TurtleBot3
Stars: ✭ 104 (-15.45%)
Mutual labels:  package
Repurrrsive
Recursive lists to use in teaching and examples, because there is no iris data for lists.
Stars: ✭ 112 (-8.94%)
Mutual labels:  package
Pharbuilder
Create Phar of Composer based PHP application
Stars: ✭ 122 (-0.81%)
Mutual labels:  package
Zflutter
Flat, round, designer-friendly pseudo-3D engine for Flutter
Stars: ✭ 121 (-1.63%)
Mutual labels:  package
Golibs
general purpose Golang code (to be included in other projects)
Stars: ✭ 114 (-7.32%)
Mutual labels:  package

graceful

Build Status Go Report Card GoDoc License MIT

Installation

go get -u github.com/TV4/graceful

Usage

package main

import (
	"log"
	"net/http"
	"time"

	"github.com/TV4/graceful"
)

type server struct{}

func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	time.Sleep(2 * time.Second)
	w.Write([]byte("Hello!"))
}

func main() {
	addr := ":2017"

	log.Printf("Listening on http://0.0.0.0%s\n", addr)

	graceful.ListenAndServe(&http.Server{
		Addr:    addr,
		Handler: &server{},
	})
}
$ go run main.go
2017/06/19 16:35:28 Listening on http://0.0.0.0:2017
^C

You can also use graceful.LogListenAndServe

package main

import (
	"net/http"
	"time"

	"github.com/TV4/graceful"
)

type server struct{}

func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	time.Sleep(2 * time.Second)
	w.Write([]byte("Hello!"))
}

func main() {
	graceful.LogListenAndServe(&http.Server{
		Addr:    ":2017",
		Handler: &server{},
	})
}
$ go run main.go
Listening on http://0.0.0.0:2017
^C
Server shutdown with timeout: 15s
Finished all in-flight HTTP requests
Shutdown finished 14s before deadline

And optionally your handler can implement the Shutdowner interface

package main

import (
	"context"
	"fmt"
	"net/http"

	graceful "github.com/TV4/graceful"
)

func main() {
	graceful.LogListenAndServe(&http.Server{
		Addr:    ":8080",
		Handler: &server{},
	})
}

type server struct{}

func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hello world!")
}

func (s *server) Shutdown(ctx context.Context) error {
	// Here you can do anything that you need to do
	// after the *http.Server has stopped accepting
	// new connections and finished its Shutdown

	// The ctx is the same as the context used to
	// perform *https.Server.Shutdown and thus
	// shares the timeout (15 seconds by default)

	fmt.Println("Finished *server.Shutdown")

	return nil
}
$ go run main.go
Listening on http://0.0.0.0:8080
^C
Server shutdown with timeout: 15s
Finished all in-flight HTTP requests
Shutting down handler with timeout: 15s
Finished *server.Shutdown
Shutdown finished 15s before deadline

License (MIT)

Copyright (c) 2017-2018 TV4

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].