github.com/roneli/gqlgen@v0.7.2/codegen/templates/server.gotpl (about)

     1  package main
     2  
     3  import (
     4  	%%%IMPORTS%%%
     5  
     6  	{{ reserveImport "context" }}
     7  	{{ reserveImport "log" }}
     8  	{{ reserveImport "net/http" }}
     9  	{{ reserveImport "os" }}
    10  	{{ reserveImport "github.com/99designs/gqlgen/handler" }}
    11  )
    12  
    13  const defaultPort = "8080"
    14  
    15  func main() {
    16  	port := os.Getenv("PORT")
    17  	if port == "" {
    18  		port = defaultPort
    19  	}
    20  
    21  	http.Handle("/", handler.Playground("GraphQL playground", "/query"))
    22  	http.Handle("/query", handler.GraphQL({{ lookupImport .ExecPackageName }}.NewExecutableSchema({{ lookupImport .ExecPackageName}}.Config{Resolvers: &{{ lookupImport .ResolverPackageName}}.Resolver{}})))
    23  
    24  	log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)
    25  	log.Fatal(http.ListenAndServe(":" + port, nil))
    26  }