mirror of
https://github.com/ananthakumaran/paisa.git
synced 2024-09-17 18:39:29 -04:00
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/ananthakumaran/paisa/web"
|
|
"github.com/gin-gonic/gin"
|
|
log "github.com/sirupsen/logrus"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func Listen(db *gorm.DB) {
|
|
gin.SetMode(gin.ReleaseMode)
|
|
|
|
router := gin.Default()
|
|
router.SetTrustedProxies(nil)
|
|
router.GET("/static/*filepath", func(c *gin.Context) {
|
|
c.FileFromFS(c.Request.URL.Path, http.FS(web.Static))
|
|
})
|
|
router.GET("/", func(c *gin.Context) {
|
|
c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(web.Index))
|
|
})
|
|
router.GET("/api/overview", func(c *gin.Context) {
|
|
c.JSON(200, GetOverview(db))
|
|
})
|
|
router.GET("/api/investment", func(c *gin.Context) {
|
|
c.JSON(200, GetInvestment(db))
|
|
})
|
|
router.GET("/api/gain", func(c *gin.Context) {
|
|
c.JSON(200, GetGain(db))
|
|
})
|
|
router.GET("/api/allocation", func(c *gin.Context) {
|
|
c.JSON(200, GetAllocation(db))
|
|
})
|
|
router.GET("/api/ledger", func(c *gin.Context) {
|
|
c.JSON(200, GetLedger(db))
|
|
})
|
|
log.Info("Listening on 7500")
|
|
err := router.Run(":7500")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|