This a template of GoLang Web API, Using the Gin Framework and GO ORM with PostgreSQL Database
MIT License
This a template of GoLang Web API, using the Gin framework and Go ORM with PostgreSQL Database.
By Hidayat Arghandabi 2023
Last Update 06/19/2023
Run the docker-compose up
command
go run migrate/migrate.go
. It will create the posts and users table in the database.go mod tidy
CompileDaemon -command="./go-crud"
the Daemon tool, make sure it is installed.go mod init
creating a go mod file (like a node file for nodejs projects)
go get github.com/githubnemo/CompileDaemon
and install it, so that it can be run as command-line tool go install github.com/githubnemo/CompileDaemon
watch files for changes and rebuildgo get github.com/joho/godotenv
Easy to load environment variablesgo get -u github.com/gin-gonic/gin
Gin Framework for Http Servergo get -u gorm.io/gorm
and go get -u gorm.io/driver/postgres
Go ORM Library for Gogo get -u github.com/sirupsen/logrus
Package for logging in a Gin applicationgo get github.com/redis/go-redis/v9
Package for Redis gogo get -u golang.org/x/crypto/bcrypt
for cryptography visit https://pkg.go.dev/golang.org/x/crypto
go get -u github.com/golang-jwt/jwt/v4
jwt package visit https://pkg.go.dev/github.com/golang-jwt/jwt or https://github.com/golang-jwt/jwt
CompileDaemon -command="./go-crud"
Run the Daemon and given the package name
https://gorm.io/docs/models.html visit the link to see how to declare your models. we are using the following model
type User struct {
gorm.Model
Name string
}
// equals
type User struct {
ID uint `gorm:"primaryKey"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt gorm.DeletedAt `gorm:"index"`
Name string
to make auto db.AutoMigrate(&Product{})
visit link https://gorm.io/docs/index.html
as migrate/migrate.go is created run the migration using
go run migrate/migrate.go
, It will make the posts table in the database.
visit the link https://gorm.io/docs/create.html for Go ORM
docker-compose up --build