This repository provides common libraries and example applications for Go language, utilizing libraries such as AWS SDK v2, Gin, and GORM with practical samples.
- Go 1.24
- AWS SDK v2
- Gin (Web Framework)
- GORM (ORM)
- golangci-lint (Lint Tool)
- Delve (Debugger)
| Directory/File | Description |
|---|---|
| .github/ | GitHub related files |
| .github/instructions/ | Copilot instruction files |
| .github/workflows/ | GitHub Actions CI/CD |
| .vscode/ | VS Code settings |
| env/ | Environment related files |
| env/common/ | Common environment settings |
| env/common/scripts/ | Common scripts (init.sh etc.) |
| example/ | Example applications |
| example/gin1/ | Sample using Gin |
| example/... | Other examples |
| pkg/ | Common libraries |
| pkg/aws/ | AWS related utilities |
| pkg/db/ | Database related |
| pkg/... | Other common modules |
| go.mod | Go module definition |
| go.sum | Go dependencies |
| LICENSE | License file |
To use this library in your Go project, add it as a dependency:
go get github.com/y-miyazaki/go-commonThen, import the required packages in your code:
import (
"github.com/y-miyazaki/go-common/pkg/aws" // AWS utilities
"github.com/y-miyazaki/go-common/pkg/db" // Database utilities
// Add other packages as needed
)After adding the dependency, run:
go mod tidyThis will download and install all necessary dependencies.
Here is a tiny example showing how to use pkg/aws and pkg/db helpers (adjust imports and usage to your needs):
package main
import (
"context"
"fmt"
"github.com/y-miyazaki/go-common/pkg/aws"
"github.com/y-miyazaki/go-common/pkg/db"
)
func main() {
ctx := context.Background()
// Example: initialize AWS client helper
awsCfg, err := aws.NewConfig(ctx)
if err != nil {
panic(err)
}
fmt.Println("AWS region:", awsCfg.Region)
// Example: open database connection
dsn := "user:pass@tcp(localhost:3306)/example"
conn, err := db.Open(ctx, dsn)
if err != nil {
panic(err)
}
defer conn.Close()
fmt.Println("DB connected")
}This section describes how to set up a local development environment and run example applications.
This section explains how to set up a local, non-containerized development workspace on your machine. It includes quick, platform-agnostic steps to clone the repository, install dependencies, and run example applications for development and testing.
- Go 1.25 or higher
- Git
- GitHub CLI (gh)
-
Clone the repository:
git clone https://github.com/y-miyazaki/go-common.git cd go-common -
Install dependencies:
go mod download
-
Set up authentication with GitHub CLI:
gh auth login
This section describes how to use a VS Code devcontainer to create a reproducible development environment. The devcontainer provides consistent tool versions and preconfigured mounts so contributors can work with the same development setup.
- Visual Studio Code
- Docker (choose one of the following options):
- Docker Desktop (recommended for Windows/macOS)
- Docker Engine (for Linux)
- lima+ (alternative for macOS/Linux, integrates with Docker)
-
Clone the repository (if not already done):
git clone https://github.com/y-miyazaki/go-common.git cd go-common -
Create devcontainer
mkdir -p .devcontainer mkdir -p env/common/tmp/gh touch env/common/tmp/.gitconfig cp -p env/example/.devcontainer/devcontainer.json .devcontainer/devcontainer.json
-
Adjust devcontainer.json
The following excerpt is a locally mounted configuration; update mount paths to match your environment. Replace${env:HOME}/workspace/go-commonwith your actual local path to this repository (e.g.,/Users/yourname/projects/go-commonon macOS orC:\Users\yourname\projects\go-commonon Windows).cat .devcontainer/devcontainer.json
{ "runArgs": [ "-v", "${env:HOME}/workspace/go-common:/workspace", "-v", "${env:HOME}/workspace/go-common/env/common/.bashrc:/home/vscode/.bashrc", "-v", "${env:HOME}/workspace/go-common/env/common/tmp/.gitconfig:/home/vscode/.gitconfig", "-v", "${env:HOME}/workspace/go-common/env/common/tmp/.aws:/home/vscode/.aws", "-v", "${env:HOME}/workspace/go-common/env/common/gh:/home/vscode/.config/gh", "-v", "/var/run/docker.sock:/var/run/docker.sock" ] } -
Configure .gitconfig
The following excerpt is a locally mounted file; update values for your name and email.cat env/common/tmp/.gitconfig
[user] name = Your Name email = [email protected] [init] defaultBranch = main [credential] helper = !gh auth git-credential [safe] directory = /workspace
-
Launch devcontainer from Visual Studio Code
Open the command palette withF1orCtrl+Shift+P, then runDev Containers: Open folder in Container(orDev containers: Reopen in Container/Dev Containers: Rebuild Container). -
Download Go modules:
go mod download
-
GitHub CLI login
After launching the devcontainer, run the following to log in to GitHub CLI. Skip if already logged in.gh auth login
-
Run the Gin example (example/gin1):
cd example/gin1 go run ./... # or from repo root # bash ./scripts/go/check.sh -f ./example/gin1/
-
Test the server (default port 8080):
curl http://localhost:8080/health
# Batch verification (recommended)
bash ./scripts/go/check.sh
# Specific directory only
bash ./scripts/go/check.sh -f ./example/gin1/
# Individual execution (when necessary)
go build ./...
go test ./...
go test -cover ./...# Batch verification (recommended)
bash ./scripts/go/check.sh
# Individual execution (when necessary)
go mod tidy
go fmt ./...
go vet ./...
golangci-lint run
govulncheck ./...# Module organization
go mod tidy
# Update dependencies
go get -u ./...
# Debug execution (Delve)
dlv debug ./example/gin1- Git push returns 403 error
Check if GitHub CLI authentication is set correctly. Usegh auth statusto verify status, and re-rungh auth loginif necessary. - devcontainer startup failure
Check execution permissions ofenv/common/scripts/init.shand verify/bin/shcompatibility issues. Run withbashif needed. - Dependency errors
Rungo mod tidyand ensure Go version is 1.24 or higher. - Lint errors
Check output ofgolangci-lint runand fix pointed locations. Refer to configuration file.golangci.yml.
- Documentation
Refer to this README and documentation in each directory. - Issues
Report issues via GitHub Issues. - Contribution
Refer to CONTRIBUTING.md and create pull requests.
This project is licensed under the Apache License 2.0. See the LICENSE file for details.
- This project is under development, so APIs or structures may change.
- Security note: Use environment variables or secret management tools for sensitive information, avoid hardcoding.
- Utilize MCP Tools for support in AWS documentation search and context management.