37 lines
841 B
Go
37 lines
841 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
|
|
"git.obamna.ru/erius/ozon-task/graph"
|
|
"git.obamna.ru/erius/ozon-task/internal/storage"
|
|
"github.com/99designs/gqlgen/graphql/handler"
|
|
"github.com/99designs/gqlgen/graphql/playground"
|
|
)
|
|
|
|
const defaultPort = "8080"
|
|
|
|
var port = os.Getenv("APP_PORT")
|
|
|
|
func main() {
|
|
if port == "" {
|
|
port = defaultPort
|
|
}
|
|
|
|
s, err := storage.InitStorage()
|
|
if err != nil {
|
|
log.Fatalf("failed to init storage: %s", err)
|
|
}
|
|
log.Println("finished storage init")
|
|
|
|
res := graph.InitResolver(s)
|
|
srv := handler.NewDefaultServer(graph.NewExecutableSchema(graph.Config{Resolvers: res}))
|
|
|
|
http.Handle("/", playground.Handler("GraphQL playground", "/query"))
|
|
http.Handle("/query", srv)
|
|
|
|
log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)
|
|
log.Fatal(http.ListenAndServe(":"+port, nil))
|
|
}
|