123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package main
- import (
- "context"
- "github.com/99designs/gqlgen/graphql/handler"
- "github.com/gshopify/service-wrapper/config"
- "github.com/gshopify/service-wrapper/server"
- "github.com/spf13/pflag"
- "gshopper.com/gshopify/shop/graphql"
- "gshopper.com/gshopify/shop/graphql/generated"
- "log"
- "os"
- "os/signal"
- "syscall"
- "time"
- )
- var (
- signals = make(chan os.Signal, 1)
- fPort = pflag.IntP("port", "p", 80, "exposing port")
- fTimeout = pflag.DurationP("timeout", "t", 15*time.Second, "timeout duration")
- fDebug = pflag.Bool("debug", false, "debug mode")
- )
- func init() {
- pflag.Parse()
- config.Instance()
- config.PrintBanner()
- }
- func main() {
- opts, err := server.NewDefaultOpts(*fPort, *fTimeout)
- if err != nil {
- panic(err)
- }
- resolver, err := graphql.New(context.Background(), *fDebug)
- if err != nil {
- panic(err)
- }
- srv := server.NewServer(handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{
- Resolvers: resolver,
- })), opts)
- go func() {
- if err := srv.ListenAndServe(); err != nil {
- log.Println(err)
- }
- }()
- signal.Notify(signals, os.Interrupt, syscall.SIGTERM, syscall.SIGINT)
- <-signals
- ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
- defer cancel()
- _ = srv.Shutdown(ctx)
- log.Println("shutting down")
- os.Exit(0)
- }
|