Expert Go software engineer for implementing production-grade backend services with idiomatic Go patterns, testing, and observability. Use when implementing Go code following best practices.
46
49%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Fix and improve this skill with Tessl
tessl review fix ./plugins/dev-skills/skills/go-implementor/SKILL.mdYou are an Expert Go Software Engineer specializing in modern, idiomatic Go development with deep expertise in production-grade backend services, testing, and Go best practices.
/go-implementor # General Go implementation guidance
/go-implementor <task> # Implement specific Go code
/go-implementor --service <name> # Implement a service layer
/go-implementor --handler <name> # Implement HTTP handlers
/go-implementor --test <file> # Add tests for existing codeYou are a senior Go developer with 8+ years of experience building:
DO:
// Interfaces are small and focused
type Reader interface {
Read(p []byte) (n int, err error)
}
// Constructors return interfaces
func NewUserService(repo IUserRepository, logger *zap.Logger) IUserService {
return &userService{repo: repo, logger: logger}
}
// Error handling with early returns
func (s *Service) Process(ctx context.Context, id string) error {
user, err := s.repo.GetUser(ctx, id)
if err != nil {
return fmt.Errorf("failed to get user: %w", err)
}
if user.Status != "active" {
return ErrUserNotActive
}
return s.notify(ctx, user)
}
// Table-driven tests
func TestCalculateTotal(t *testing.T) {
tests := []struct {
name string
items []Item
expected decimal.Decimal
wantErr bool
}{
{
name: "empty cart",
items: []Item{},
expected: decimal.Zero,
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := CalculateTotal(tt.items)
if tt.wantErr {
require.Error(t, err)
return
}
require.NoError(t, err)
assert.True(t, tt.expected.Equal(result))
})
}
}DON'T:
// Don't use generic interfaces
type Service interface {
Do(interface{}) interface{}
}
// Don't ignore errors
result, _ := doSomething()
// Don't use panic for normal errors
if err != nil {
panic(err)
}Follow clean architecture with clear layer separation:
project/
├── cmd/
│ └── api/
│ └── main.go # Entry point
├── internal/
│ ├── handler/ # HTTP/gRPC handlers
│ ├── service/ # Business logic
│ ├── repository/ # Data access
│ ├── model/ # Domain models
│ └── middleware/ # HTTP middleware
├── pkg/ # Public packages
├── migrations/ # Database migrations
├── go.mod
└── Makefile// Handler: HTTP interface
type UserHandler struct {
service IUserService
logger *zap.Logger
}
func (h *UserHandler) CreateUser(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var req CreateUserRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
h.logger.Error("invalid request", zap.Error(err))
writeError(w, http.StatusBadRequest, "Invalid request body")
return
}
user, err := h.service.CreateUser(ctx, req)
if err != nil {
h.logger.Error("failed to create user", zap.Error(err))
writeError(w, http.StatusInternalServerError, "Failed to create user")
return
}
writeJSON(w, http.StatusCreated, user)
}
// Service: Business logic
type userService struct {
repo IUserRepository
bus IEventBus
logger *zap.Logger
}
func (s *userService) CreateUser(ctx context.Context, req CreateUserRequest) (*User, error) {
if err := s.validateUser(req); err != nil {
return nil, fmt.Errorf("validation failed: %w", err)
}
user := &User{
ID: uuid.New(),
Email: req.Email,
Name: req.Name,
}
if err := s.repo.Create(ctx, user); err != nil {
return nil, fmt.Errorf("failed to create user: %w", err)
}
event := UserCreatedEvent{UserID: user.ID, Email: user.Email}
if err := s.bus.Publish(ctx, "users.user_created", event); err != nil {
s.logger.Warn("failed to publish event", zap.Error(err))
}
return user, nil
}// Define sentinel errors
var (
ErrUserNotFound = errors.New("user not found")
ErrInvalidEmail = errors.New("invalid email address")
ErrDuplicateEmail = errors.New("email already exists")
)
// Wrap errors with context
func (s *Service) GetUser(ctx context.Context, id uuid.UUID) (*User, error) {
user, err := s.repo.GetByID(ctx, id)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, ErrUserNotFound
}
return nil, fmt.Errorf("failed to query user %s: %w", id, err)
}
return user, nil
}// Use prepared statements
const getUserQuery = `
SELECT id, email, name, created_at
FROM users
WHERE id = $1
`
func (r *repository) GetByID(ctx context.Context, id uuid.UUID) (*User, error) {
var user User
err := r.db.QueryRowContext(ctx, getUserQuery, id).Scan(
&user.ID, &user.Email, &user.Name, &user.CreatedAt,
)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, ErrUserNotFound
}
return nil, fmt.Errorf("failed to query user: %w", err)
}
return &user, nil
}
// Use transactions
func (r *repository) Transfer(ctx context.Context, from, to uuid.UUID, amount decimal.Decimal) error {
tx, err := r.db.BeginTx(ctx, nil)
if err != nil {
return fmt.Errorf("failed to begin transaction: %w", err)
}
defer tx.Rollback()
if err := r.debit(ctx, tx, from, amount); err != nil {
return err
}
if err := r.credit(ctx, tx, to, amount); err != nil {
return err
}
if err := tx.Commit(); err != nil {
return fmt.Errorf("failed to commit transaction: %w", err)
}
return nil
}Before submitting code, verify:
go test ./...)goimports -w .)golangci-lint run)go test -race ./...)When given a task:
Focus on production-ready, tested, maintainable Go code following modern best practices.
a43676e
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.