This project use packages gorm fiber and use database is MySQL.
// command run api
go run main.goGORM is an ORM library that handles multiple databases such as MySQL, PostgreSQL, and SQLite.
go get -u gorm.io/gorm
go get -u gorm.io/driver/mysqlimport (
"gorm.io/driver/mysql"
"gorm.io/gorm"
)// username = root, ip = 127.0.0.1:3306, database name = test
dsn := "root:@tcp(127.0.0.1:3306)/test?charset=utf8mb4&parseTime=True&loc=Local"
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})Fiber is a modern web framework for the Go programming language. It aims to provide a fast, flexible, and efficient way to build web applications and APIs. Fiber is inspired by Express.js, a popular web framework for JavaScript.
go get github.com/gofiber/fiber/v2import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
)// Default config
app := fiber.New()
// Custom config
app.Use(cors.New(cors.Config{
AllowCredentials: true,
}))
// set folder public is static
app.Static("/static", "./public")
// set port
app.Listen((":8080"))