-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
37 lines (30 loc) · 795 Bytes
/
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
package main
import (
"database/sql"
"log"
_ "github.com/glebarez/go-sqlite"
"github.com/gofiber/fiber/v2"
"github.com/spf13/viper"
"github.com/ushieru/sqlirest/handlers"
"github.com/ushieru/sqlirest/utils"
)
func main() {
viper.SetConfigFile(".env")
viper.ReadInConfig()
viper.SetDefault("DATABASE_URL", ":memory:")
viper.SetDefault("PORT", "8080")
database := viper.GetString("DATABASE_URL")
sqlFile := viper.GetString("SQL_FILE")
port := viper.GetString("PORT")
app := fiber.New()
db, err := sql.Open("sqlite", database)
if err != nil {
log.Fatal(err)
}
utils.LoadSQL(sqlFile, db)
handlers.SetupGetHandler(app, db)
handlers.SetupPostHandler(app, db)
handlers.SetupPatchHandler(app, db)
handlers.SetupDeleteHandler(app, db)
log.Fatal(app.Listen(":" + port))
}