2020-04-10 04:40:22 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-06-23 22:20:53 +02:00
|
|
|
_ "github.com/lib/pq"
|
2020-07-05 01:02:57 +02:00
|
|
|
"io/ioutil"
|
2020-04-10 04:40:22 +02:00
|
|
|
"net/http"
|
2020-06-23 22:20:53 +02:00
|
|
|
"time"
|
2020-04-10 04:40:22 +02:00
|
|
|
|
2020-07-05 01:02:57 +02:00
|
|
|
"github.com/BurntSushi/toml"
|
2020-04-10 04:40:22 +02:00
|
|
|
"github.com/jmoiron/sqlx"
|
2020-07-05 01:02:57 +02:00
|
|
|
"github.com/jordanknott/project-citadel/api/internal/route"
|
2020-04-10 04:40:22 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2020-07-05 01:02:57 +02:00
|
|
|
type Database struct {
|
|
|
|
Host string
|
|
|
|
Name string
|
|
|
|
User string
|
|
|
|
Password string
|
|
|
|
}
|
|
|
|
type AppConfig struct {
|
|
|
|
Database Database
|
|
|
|
}
|
|
|
|
|
2020-04-10 04:40:22 +02:00
|
|
|
func main() {
|
2020-07-05 01:02:57 +02:00
|
|
|
dat, err := ioutil.ReadFile("conf/app.toml")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var appConfig AppConfig
|
|
|
|
_, err = toml.Decode(string(dat), &appConfig)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2020-04-10 04:40:22 +02:00
|
|
|
Formatter := new(log.TextFormatter)
|
|
|
|
Formatter.TimestampFormat = "02-01-2006 15:04:05"
|
|
|
|
Formatter.FullTimestamp = true
|
|
|
|
log.SetFormatter(Formatter)
|
2020-07-05 01:02:57 +02:00
|
|
|
log.SetLevel(log.InfoLevel)
|
|
|
|
connection := fmt.Sprintf("user=%s password=%s host=%s dbname=%s sslmode=disable",
|
|
|
|
appConfig.Database.User,
|
|
|
|
appConfig.Database.Password,
|
|
|
|
appConfig.Database.Host,
|
|
|
|
appConfig.Database.Name,
|
|
|
|
)
|
|
|
|
db, err := sqlx.Connect("postgres", connection)
|
2020-04-10 04:40:22 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Panic(err)
|
|
|
|
}
|
2020-06-23 22:20:53 +02:00
|
|
|
db.SetMaxOpenConns(25)
|
|
|
|
db.SetMaxIdleConns(25)
|
|
|
|
db.SetConnMaxLifetime(5 * time.Minute)
|
|
|
|
|
2020-04-10 04:40:22 +02:00
|
|
|
defer db.Close()
|
|
|
|
fmt.Println("starting graphql server on http://localhost:3333")
|
|
|
|
fmt.Println("starting graphql playground on http://localhost:3333/__graphql")
|
2020-07-05 01:02:57 +02:00
|
|
|
r, _ := route.NewRouter(db)
|
2020-04-10 04:40:22 +02:00
|
|
|
http.ListenAndServe(":3333", r)
|
|
|
|
}
|