-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
43 lines (31 loc) · 949 Bytes
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"database/sql"
"log"
"net/http"
"os"
"test/SkyScraper/graph"
"test/SkyScraper/graph/generated"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/playground"
_ "github.com/denisenkom/go-mssqldb"
)
const apiPort = "8080"
const mysqlPort = "1433"
func main() {
// connect to the mysql database
db, err := sql.Open("sqlserver", "Data Source='localhost, 1433';Initial Catalog=DEFAULT;User ID=sa;Password=[MSSQLServer!]")
defer db.Close()
if err != nil {
panic(err.Error())
}
port := os.Getenv("PORT")
if port == "" {
port = apiPort
}
srv := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{}}))
http.Handle("/", playground.Handler("Database access", "/query"))
http.Handle("/query", srv)
log.Printf("connect to http://localhost:%s/ for interactive access", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}