cmd/sgai/skel/.sgai/skills/coding-practices/go-project-layout/SKILL.md
Go module structure and project organization patterns. When setting up a new Go project or organizing existing Go code
npx skillsauth add sandgardenhq/sgai go-project-layoutInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Module structure and organization patterns for Go projects.
For deeper information, fetch these URLs:
# Create new module
mkdir myproject
cd myproject
go mod init github.com/user/myproject
module github.com/user/myproject
go 1.23 // Use Go 1.23+ for iter package and range-over-func
require (
github.com/gin-gonic/gin v1.9.1
github.com/stretchr/testify v1.8.4
)
Go Version Requirements:
go 1.18+ - Generics supportgo 1.21+ - slices and maps packages in stdlibgo 1.23+ - iter package and range-over-function iteratorsgo mod tidy # Add missing, remove unused
go mod download # Download dependencies
go mod verify # Verify dependencies
go mod graph # View dependency graph
go get ./... # Update dependencies
go get pkg@version # Get specific version
myproject/
├── go.mod
├── go.sum
├── main.go # Simple single-file projects
└── main_test.go
myproject/
├── cmd/
│ └── myapp/
│ └── main.go # Application entry point
├── internal/
│ ├── server/
│ │ └── server.go # HTTP server
│ ├── handler/
│ │ └── handler.go # Request handlers
│ └── model/
│ └── model.go # Data models
├── go.mod
├── go.sum
└── README.md
mylib/
├── go.mod
├── go.sum
├── mylib.go # Main package code
├── mylib_test.go # Tests
├── helper.go # Additional files
└── README.md
myproject/
├── cmd/
│ ├── myapp/
│ │ └── main.go
│ └── mytool/
│ └── main.go
├── internal/
│ ├── pkg/ # Private shared packages
│ │ └── database/
│ └── app/
│ └── myapp/
├── pkg/ # Public packages (if any)
│ └── api/
├── api/ # API definitions (OpenAPI, proto)
├── configs/ # Configuration files
├── scripts/ # Build scripts
├── test/ # Additional test data
├── go.mod
├── go.sum
├── Makefile
└── README.md
Application entry points. Each subdirectory is a separate binary.
// cmd/myapp/main.go
package main
import (
"github.com/user/myproject/internal/server"
)
func main() {
s := server.New()
s.Run()
}
Private packages. Cannot be imported by external projects.
// internal/server/server.go
package server
type Server struct {
// ...
}
func New() *Server {
return &Server{}
}
Public packages. Can be imported by external projects. Note: Only use if you explicitly want to share code.
API definitions: OpenAPI specs, Protocol Buffers, etc.
Each directory is one package. All .go files in a directory must have the same package statement.
util, common, misc// Good
package server
package handler
package model
// Bad
package serverPkg
package server_utils
package common
Import path = module path + subdirectory.
// go.mod: module github.com/user/myproject
// Import internal package
import "github.com/user/myproject/internal/server"
// Import cmd package (rare, usually just main)
import "github.com/user/myproject/cmd/myapp"
# Build current directory
go build
# Build specific package
go build ./cmd/myapp
# Build all packages
go build ./...
# Install binary
go install ./cmd/myapp
# Run without installing
go run ./cmd/myapp
# Build for Linux
GOOS=linux GOARCH=amd64 go build -o myapp-linux ./cmd/myapp
# Build for Windows
GOOS=windows GOARCH=amd64 go build -o myapp.exe ./cmd/myapp
# Build for macOS ARM
GOOS=darwin GOARCH=arm64 go build -o myapp-darwin ./cmd/myapp
cmd/
├── api-server/
│ └── main.go
├── worker/
│ └── main.go
└── cli-tool/
└── main.go
internal/
├── config/ # Configuration loading
│ └── config.go
├── database/ # Database connection
│ └── db.go
└── model/ # Shared models
└── user.go
internal/
├── handler/ # HTTP handlers
├── service/ # Business logic
├── repository/ # Data access
└── model/ # Data structures
Tests live alongside code with _test.go suffix.
internal/
└── server/
├── server.go
└── server_test.go
test/
├── testdata/
│ └── fixtures/
└── integration/
// server_test.go - test from outside perspective
package server_test
import (
"testing"
"github.com/user/myproject/internal/server"
)
func TestServer(t *testing.T) {
s := server.New()
// ...
}
.PHONY: build test lint clean
build:
go build -o bin/myapp ./cmd/myapp
test:
go test ./...
lint:
go vet ./...
golangci-lint run
clean:
rm -rf bin/
run:
go run ./cmd/myapp
| Directory | Purpose | Importable | |-----------|---------|------------| | /cmd | Entry points | No (main packages) | | /internal | Private packages | Only within module | | /pkg | Public packages | Yes | | /api | API definitions | N/A | | /configs | Config files | N/A | | /test | Test helpers | N/A |
When setting up a new project, consider which modern Go features you'll use:
| Feature | Minimum Go Version |
|---------|-------------------|
| Generics | Go 1.18 |
| slices package | Go 1.21 |
| maps package | Go 1.21 |
| iter package | Go 1.23 |
| Range-over-func | Go 1.23 |
Set your go.mod version accordingly to leverage these features:
// For full modern Go feature support
go 1.23
// For generics + slices/maps but no iterators
go 1.21
References:
documentation
Start, stop, and steer agentic sessions in sgai workspaces. Use when you need to launch AI agent sessions, halt running sessions, or inject steering instructions to guide the agent mid-execution without stopping it.
development
Monitor sgai workspace status, events, progress, diffs, and workflow diagrams. Use when you need to observe what agents are doing, track progress, get the current state of all workspaces, subscribe to real-time updates via SSE, or inspect code changes.
development
Access agents, skills, and code snippets available in sgai workspaces. Use when you need to discover what agents are defined in a workspace, browse available skills, get skill instructions, find code snippets by language, or retrieve snippet content for a specific task.
data-ai
Handle agent questions and work gates in sgai workspaces. Use when an agent is blocked waiting for human input, when you need to respond to multi-choice questions, approve work gates, or provide free-text answers to agent queries.