1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- 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/admin-api/graph/product/generated"
- "gshopper.com/gshopify/admin-product/graphql"
- "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)
- }
- h := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{
- Resolvers: resolver,
- }))
- srv := server.NewServer(h, 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)
- }
|