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/income", func(c *gin.Context) { c.JSON(200, GetIncome(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) } }