func (af *AF) Run() error {
	flag.Parse()
	var err error
	if err = af.init(); err != nil {
		return err
	}
	go func(af *AF) {
		log.Println(fmt.Sprintf("AF server is run at pid:%d", os.Getpid()))
		err = af.server.Serve(af.listener)
	}(af)
	if af.signalHandlerMap == nil {
		af.defaultSignalHandle()
	}
	af.signalHandle()
	return nil
}
Run the AF
package af
import (
	"context"
	"errors"
	"flag"
	"fmt"
	"log"
	"net"
	"net/http"
	"os"
	"os/exec"
	"os/signal"
	"reflect"
	"time"
)
var (
	graceful *bool = flag.Bool("graceful", false, "listen on fd open 3 (internal use only)")
)
type AF struct {
	Addr             string
	Handler          http.Handler
	ShutdownTimeOut  time.Duration
	listener         net.Listener
	server           *http.Server
	signalSlice      []os.Signal
	signalHandlerMap map[os.Signal]func(*AF)
}
func Default() *AF {
	return &AF{
		Addr:            ":8080",
		ShutdownTimeOut: time.Second * 10,
	}
}
func NewWithHandler(handler http.Handler) *AF {
	return &AF{
		Addr:            ":8080",
		Handler:         handler,
		ShutdownTimeOut: time.Second * 10,
	}
}
func NewWithServer(server *http.Server) *AF {
	return &AF{
		server:          server,
		Addr:            server.Addr,
		Handler:         server.Handler,
		ShutdownTimeOut: time.Second * 10,
	}
}
func (af *AF) init() error {
	if af.server == nil {
		if af.Handler == nil {
			af.Handler = http.DefaultServeMux
		}
		af.server = &http.Server{
			Addr:         af.Addr,
			Handler:      af.Handler,
			ReadTimeout:  10 * time.Second,
			WriteTimeout: 10 * time.Second,
		}
	}
	var err error
	if *graceful {
		f := os.NewFile(3, "")
		af.listener, err = net.FileListener(f)
	} else {
		af.listener, err = net.Listen("tcp", af.server.Addr)
	}
	return err
}
func (af *AF) signalHandle() {
	signalChan := make(chan os.Signal, 1)
	signal.Notify(signalChan, af.signalSlice...)
	for {
		select {
		case s := <-signalChan:
			if f, ok := af.signalHandlerMap[s]; ok {
				f(af)
			}
			break
		}
	}
}
func (af *AF) HandleSignal(handler func(*AF), signals ...os.Signal) {
	if af.signalHandlerMap == nil {
		af.signalHandlerMap = make(map[os.Signal]func(*AF))
	}
	for _, s := range signals {
		if _, ok := af.signalHandlerMap[s]; !ok {
			af.signalSlice = append(af.signalSlice, s)
		}
		af.signalHandlerMap[s] = handler
	}
}