Golang http&grpc server for gracefully shutdown like nginx -s reload

supervisor

Golang http & grpc server for gracefully shutdown like nginx -s reload if you want a server which would be restarted without stopping service, you shall choose supervisor

reload

Server's Config shows you the http port which your services shall listen, if you provide :8088 as the default port then you can request the url:

curl http://your_ip:8088/-/reload

to restart the server

metrics

Server's Config also shows the metrics for prometheus, if you provide the Config with :8088 as the default port then you can access the metrics of your services:

curl http://your_ip:8088/-/metrics

demo

HTTP server

package main

import (
	"fmt"
	"github.com/liqiongfan/supervisor"
	"net"
	"net/http"
)


func main() {

	h := &supervisor.HTTPServer{
		Server: supervisor.Server{
			ListenAddr: []string{`:9091`},
			Config: supervisor.ListenConfig{ Addr: ":8088" },
		},
		Entry: Main,
	}

	err := h.Run()
	if err != nil {
		panic(err)
	}
}


func Main(srv []*http.Server, l []net.Listener) {

	http.HandleFunc(`/`, func(w http.ResponseWriter, r *http.Request){
		_, _ = w.Write([]byte("OK\n"))
	})

	err := srv[0].Serve(l[0])
	if err != nil {
		fmt.Printf("error: %v\n", err)
	}
}


gin HTTP server

package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/liqiongfan/supervisor"
	"net"
	"net/http"
)


func main() {

	h := &supervisor.HTTPServer{
		Server: supervisor.Server{
			ListenAddr: []string{`:9091`},
			Config: supervisor.ListenConfig{ Addr: ":8088" },
		},
		Entry: Main,
	}

	err := h.Run()
	if err != nil {
		panic(err)
	}
}


func all(c *gin.Context) {
	uri, _ := c.Params.Get(`uri`)
	c.String(200, "uri: %s", uri)
}


func Main(srv []*http.Server, l []net.Listener) {

	server := srv[0]
	listener := l[0]

	r := gin.New()
	r.GET(`/*uri`, all)

	server.Handler = r
	err := server.Serve(listener)
	if err != nil {
		fmt.Printf("Server: %v\n", err)
	}



}
Similar Resources

Go based grpc - grpc gateway micro service example

go-grpc-gateway-server This repository provides an example for go based microservice. Go micro services developed based on gRPC protobuf's and also us

Dec 8, 2021

Simple grpc web and grpc transcoding with Envoy

Simple grpc web and grpc transcoding with Envoy

gRPC Web and gRPC Transcoding with Envoy This is a simple stand-alone set of con

Dec 25, 2021

GRPC - Creating a gRPC service from scratch

#Go gRPC services course Creating a gRPC service from scratch Command line colle

Jan 2, 2022

Totem - A Go library that can turn a single gRPC stream into bidirectional unary gRPC servers

Totem is a Go library that can turn a single gRPC stream into bidirectional unar

Jan 6, 2023

Grpc-gateway-map-null - gRPC Gateway test using nullable values in map

Demonstrate gRPC gateway behavior with nullable values in maps Using grpc-gatewa

Jan 6, 2022

Todo-app-grpc - Go/GRPC codebase containing RealWorld examples (CRUD, auth, advanced patterns, etc)

Go/GRPC codebase containing RealWorld examples (CRUD, auth, advanced patterns, e

Oct 12, 2022

Raft-grpc-demo - Some example code for how to use Hashicorp's Raft implementation with gRPC

raft-grpc-example This is some example code for how to use Hashicorp's Raft impl

Jan 4, 2022

Benthos-input-grpc - gRPC custom benthos input

gRPC custom benthos input Create a custom benthos input that receives messages f

Sep 26, 2022

Grpc-train - Train booking demo using gRPC

gRPC Demo: Train Booking Service Description Usage Contributing Development Tool

Feb 6, 2022
Related tags
protoc-gen-grpc-gateway-ts is a Typescript client generator for the grpc-gateway project. It generates idiomatic Typescript clients that connect the web frontend and golang backend fronted by grpc-gateway.

protoc-gen-grpc-gateway-ts protoc-gen-grpc-gateway-ts is a Typescript client generator for the grpc-gateway project. It generates idiomatic Typescript

Dec 19, 2022
Laptop Booking Application in Golang and gRPC, load-balancing with NGINX, and fully compatible with HTTPS OpenAPI v3

Laptop Booking Application in Golang and gRPC Goals GitHub CI & Coverage Badge Serialize protobuf messages Create laptop unary gRPC Search laptop Serv

Jun 17, 2022
A TCP Server Framework with graceful shutdown, custom protocol.

xtcp A TCP Server Framework with graceful shutdown,custom protocol. Usage Define your protocol format: Before create server and client, you need defin

Dec 7, 2022
Server and client implementation of the grpc go libraries to perform unary, client streaming, server streaming and full duplex RPCs from gRPC go introduction

Description This is an implementation of a gRPC client and server that provides route guidance from gRPC Basics: Go tutorial. It demonstrates how to u

Nov 24, 2021
A suite of gRPC debugging tools. Like Fiddler/Charles but for gRPC.

grpc-tools A suite of tools for gRPC debugging and development. Like Fiddler/Charles but for gRPC! The main tool is grpc-dump which transparently inte

Dec 22, 2022
Go-grpc - This is grpc server for golang.

go-grpc This is grpc server for golang. protocのインストール brew install protoc Golang用のプラグインのインストール go install google.golang.org/protobuf/cmd/protoc-gen-go

Jan 2, 2022
grpc-http1: A gRPC via HTTP/1 Enabling Library for Go

grpc-http1: A gRPC via HTTP/1 Enabling Library for Go This library enables using all the functionality of a gRPC server even if it is exposed behind a

Dec 17, 2022
GRPC - A client-server mockup, using gRPC to expose functionality.

gRPC This is a mockup application that I built to help me visualise and understand the basic concepts of gRPC. In this exchange, the client can use a

Jan 4, 2022
Go-grpc-tutorial - Simple gRPC server/client using go

Simple gRPC server/client using go Run server go run usermgmt_server/usermgmt_

Feb 14, 2022
Go-grpc-template - A small template for quickly bootstrapping a, developer platform independent gRPC golang application
Go-grpc-template - A small template for quickly bootstrapping a, developer platform independent gRPC golang application

go-grpc-template A small template for quickly bootstrapping a developer platform

Jan 20, 2022