in go-gin-react/go-gin-react-part2/main.go [34:76]
func main() {
// Get the working directory
wd, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
// Print the working directory
fmt.Println("Working directory:", wd)
// Open the SQLite database file
db, err := sql.Open("sqlite", wd+"/database.db")
defer func(db *sql.DB) {
err := db.Close()
if err != nil {
log.Fatal(err)
}
}(db)
// Create the Gin router
r := gin.Default()
if err != nil {
log.Fatal(err)
}
// Creation endpoints
r.POST("/users", func(c *gin.Context) { createUser(c, db) })
r.POST("/channels", func(c *gin.Context) { createChannel(c, db) })
r.POST("/messages", func(c *gin.Context) { createMessage(c, db) })
// Listing endpoints
r.GET("/channels", func(c *gin.Context) { listChannels(c, db) })
r.GET("/messages", func(c *gin.Context) { listMessages(c, db) })
// Login endpoint
r.POST("/login", func(c *gin.Context) { login(c, db) })
err = r.Run(":8080")
if err != nil {
log.Fatal(err)
}
}