12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- 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
- }
|