-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (51 loc) · 1.28 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
63
package main
import (
"github.com/gin-gonic/contrib/static"
"github.com/gin-gonic/gin"
"github.com/gobitmap/routes"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"os/exec"
)
func init() {
//react build setup.
if err := copyNewBuild(); err != nil {
panic(err)
}
//database setup.
routes.CreateSchema()
//environment variables setup.
config()
//redis Connection
}
func main() {
// Set the router as the default one shipped with Gin
router := gin.Default()
router.NoRoute(customNoRouteHandler)
// Serve frontend static files
router.Use(static.Serve("/", static.LocalFile("./build", true)))
//Setup route group for the API
user := router.Group("/user")
{
user.GET("/all", routes.FindAll)
user.GET("/fromCookie", routes.GetUserFromCookie)
user.POST("/create", routes.Create)
user.PATCH("/update/:id", routes.Update)
user.POST("/login", routes.Login)
user.DELETE("/delete", routes.DeleteAll)
}
news := router.Group("/news")
{
news.GET("/all", routes.News)
news.GET("/search", routes.News)
}
// Start and run the server
panic(router.Run(":8000"))
}
//redirect to home page when route not found.
func customNoRouteHandler(c *gin.Context) {
c.Redirect(301, "/")
}
func copyNewBuild() error {
err := exec.Command("/bin/sh", "./buildHelper.sh").Start()
return err
}