-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
62 lines (49 loc) · 1.2 KB
/
main.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"encoding/json"
"os"
"github.com/labstack/echo"
"github.com/labstack/echo/engine/fasthttp"
"github.com/labstack/echo/middleware"
"github.com/mewben/config-echo"
//_ "github.com/lib/pq"
//"github.com/mewben/db-go-env"
)
// Initialize Port and DB Connection config
func init() {
type Config struct {
SERVERPORT string
//DB db.Database
}
configFile, err := os.Open("env.json")
if err != nil {
panic(err)
}
var devConfig Config
jsonParser := json.NewDecoder(configFile)
if err = jsonParser.Decode(&devConfig); err != nil {
panic(err)
}
// setup postgres db connection
//db.Setup(devConfig.DB)
// setup port
// This sets the global Port string
// If you set an environment variable DATABASE_URL,
// it sets Mode = "prod" and uses the env Port instead
config.Setup(devConfig.SERVERPORT)
}
func main() {
app := echo.New()
app.Use(middleware.Recover())
app.Use(middleware.Gzip())
app.Use(middleware.Secure())
app.Use(middleware.BodyLimit("100K"))
if config.Mode == "dev" {
// Enable Debug
app.Use(middleware.Logger())
app.SetDebug(true)
}
app.File("/*", "public/index.html")
app.Static("/assets", "public/assets")
app.Run(fasthttp.New(config.Port))
}