README.md
July 15, 2022 ยท View on GitHub
Sewa Space App - Learn Golang
Overview

This project is documentation of my learning Golang with the best practice based on Standard Go Project Layout, by Kyle Quest.
Features
- Gin Web Framework
- GORM MySQL Database Driver
- Custom Soft Deleted
CreatedAtCreatedByUpdatedAtDeletedAt
- Base Api Response
{ "timestamp": "", "response_key": "", "message": "", "data": {} } - Custom Exception and Exception Handler
- Golang Enumerations
- Golang Generic
- Package Validator
- Logrus
- Containerized Support
- Read Environment Variables
- Json Web Token
- Redis client for Go
- Custom
TypeConverterlikeModelMapperin Spring Boot - Gin-Contrib CORS Filter
- Role Based Access Control
Usage
I use Makefile to simplify command line usage. Change line before build the application. Change binary filename according target operating system and target architecture.
BIN := goapp.exe
VERSION := 1.0.0
TARGET_OS := windows
TARGET_ARCH := amd64
| TARGET OS | TARGET ARCH |
|---|---|
| android | arm |
| linux | amd64 |
| linux | arm |
| linux | arm64 |
| linux | 386 |
| windows | amd64 |
| windows | 386 |
| darwin | amd64 |
| darwin | arm64 |
| etc. | etc. |
The command is :
make buildto build binary filemake cleanto clean package and remove binary filemake dockerit will execute commandcleanandbuildand then build image withdockercommandmake podmanit will execute commandcleanandbuildand then build image withpodmancommand
Note : Run your MySQL Database and Redis Server first before running the application
Run application directly
go run main.go
Work with containerize
Build binary and images
CGO_ENABLED=0 go build -o bin/goapp
docker build -t goapp:latest . -f build/Dockerfile
Run container using Docker
docker run -d --name goapp -p 8080:8080 --env-file=dev.env --network my-network goapp
Run container using Podman (Arch Linux)
Install dnsmasq and cni-plugins using package manager
sudo pacman -S dnsmasq cni-plugins
Looking for cni binary installed.
ls -l /opt/cni/bin
ls -l /usr/lib/cni
Using git, clone https://github.com/containers/dnsname.git see README_PODMAN.md and change line at Makefile
...
LIBEXECDIR ?= ${PREFIX}/cni/bin
...
Install with command sudo make install PREFIX=/opt
Change line again at Makefile
...
LIBEXECDIR ?= ${PREFIX}/lib/cni
...
Install with command sudo make install PREFIX=/usr
Enable cni in /etc/containers/containers.conf.
...
cni_plugin_dirs = [
"/usr/local/libexec/cni",
"/usr/libexec/cni",
"/usr/local/lib/cni",
"/usr/lib/cni",
"/opt/cni/bin",
]
...
Create new network podman network create my-network
Update configuration my-network at $HOME/.config/cni/net.d/my-network.conflist
{
"cniVersion": "0.4.0",
"name": "my-network",
"plugins": [
...
{
"type": "dnsname",
"domainName": "my-network",
"capabilities": {
"aliases": true
}
}
...
]
}
Run container application
podman run -d --name goapp -p 8080:8080 --env-file=dev.env --network my-network goapp