github.com/blong14/gache@v0.0.0-20240124023949-89416fd8bbfa/cmd/gache/main.go (about) 1 package main 2 3 import ( 4 "context" 5 "log" 6 "os" 7 "os/signal" 8 "syscall" 9 "time" 10 11 ghttp "github.com/blong14/gache/internal/io/http" 12 grpc "github.com/blong14/gache/internal/io/rpc" 13 gproxy "github.com/blong14/gache/internal/proxy" 14 ghandlers "github.com/blong14/gache/internal/server" 15 ) 16 17 func main() { 18 sigint := make(chan os.Signal, 1) 19 signal.Notify(sigint, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) 20 21 ctx, cancel := context.WithCancel(context.Background()) 22 23 proxy, err := gproxy.NewQueryProxy() 24 if err != nil { 25 panic(err) 26 } 27 gproxy.StartProxy(ctx, proxy) 28 29 rpcSRV := ghandlers.Server(":8080") 30 go grpc.Start(rpcSRV, ghandlers.RPCHandlers()) 31 32 httpSRV := ghandlers.Server(":8081") 33 go ghttp.Start(httpSRV, ghandlers.HTTPHandlers(proxy)) 34 35 s := <-sigint 36 log.Printf("received %s signal\n", s) 37 ghttp.Stop(ctx, httpSRV, rpcSRV) 38 gproxy.StopProxy(ctx, proxy) 39 cancel() 40 time.Sleep(500 * time.Millisecond) 41 }