package main import ( "context" "github.com/99designs/gqlgen/graphql/handler" "github.com/gshopify/service-wrapper/server" "gshopper.com/gshopify/customer/graphql" "gshopper.com/gshopify/customer/graphql/generated" "log" "os" "os/signal" "syscall" "time" ) var ( signals = make(chan os.Signal, 1) ) func serve() error { opts, err := server.NewDefaultOpts(*fPort, *fTimeout) if err != nil { return err } resolver, err := graphql.NewResolver() if err != nil { return 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") return nil }