ozon-task/cmd/server.go

38 lines
841 B
Go
Raw Normal View History

2024-06-24 23:34:10 +00:00
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 {
2024-06-25 00:19:53 +00:00
log.Fatalf("failed to init storage: %s", err)
2024-06-24 23:34:10 +00:00
}
2024-06-25 00:19:53 +00:00
log.Println("finished storage init")
2024-06-24 23:34:10 +00:00
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))
}