<< All versions
Skill v1.0.1
currentAutomated scan100/100majiayu000/claude-skill-registry/go
3 files
──Details
PublishedJune 16, 2026 at 09:43 PM
Content Hashsha256:d5b542fd28825b44...
Git SHA0432e4f16a18
Bump Typepatch
──Files
Files (1 file, 3.4 KB)
SKILL.md3.4 KBactive
SKILL.md · 170 lines · 3.4 KB
version: "1.0.1" name: go description: Write Go code following best practices. Use when developing Go applications. Covers error handling, concurrency, and project structure. allowed-tools: Read, Write, Edit, Bash, Glob, Grep
Go Development
Project Structure
myproject/├── cmd/│ └── server/│ └── main.go├── internal/│ ├── handler/│ ├── service/│ └── repository/├── pkg/│ └── shared/├── go.mod└── go.sum
Error Handling
go
// Custom error typestype NotFoundError struct {Resource stringID string}func (e *NotFoundError) Error() string {return fmt.Sprintf("%s not found: %s", e.Resource, e.ID)}// Error wrappingfunc GetUser(id string) (*User, error) {user, err := db.FindUser(id)if err != nil {return nil, fmt.Errorf("GetUser(%s): %w", id, err)}return user, nil}// Error checkingif errors.Is(err, sql.ErrNoRows) {return nil, &NotFoundError{Resource: "user", ID: id}}
Concurrency
go
// Goroutines with errgroupfunc fetchAll(ctx context.Context, urls []string) ([]Response, error) {g, ctx := errgroup.WithContext(ctx)results := make([]Response, len(urls))for i, url := range urls {i, url := i, url // capture loop variablesg.Go(func() error {resp, err := fetch(ctx, url)if err != nil {return err}results[i] = respreturn nil})}if err := g.Wait(); err != nil {return nil, err}return results, nil}// Channelsfunc producer(ch chan<- int) {for i := 0; i < 10; i++ {ch <- i}close(ch)}func consumer(ch <-chan int) {for v := range ch {fmt.Println(v)}}
HTTP Handler
go
func (h *Handler) GetUser(w http.ResponseWriter, r *http.Request) {ctx := r.Context()id := chi.URLParam(r, "id")user, err := h.service.GetUser(ctx, id)if err != nil {var notFound *NotFoundErrorif errors.As(err, ¬Found) {http.Error(w, err.Error(), http.StatusNotFound)return}http.Error(w, "Internal error", http.StatusInternalServerError)return}w.Header().Set("Content-Type", "application/json")json.NewEncoder(w).Encode(user)}
Testing
go
func TestGetUser(t *testing.T) {t.Parallel()tests := []struct {name stringid stringwant *UserwantErr bool}{{name: "existing user",id: "123",want: &User{ID: "123", Email: "test@example.com"},},{name: "non-existent user",id: "999",wantErr: true,},}for _, tt := range tests {t.Run(tt.name, func(t *testing.T) {got, err := service.GetUser(context.Background(), tt.id)if (err != nil) != tt.wantErr {t.Errorf("error = %v, wantErr %v", err, tt.wantErr)}if !reflect.DeepEqual(got, tt.want) {t.Errorf("got = %v, want %v", got, tt.want)}})}}
Tooling
bash
# Formatgofmt -w .goimports -w .# Lintgolangci-lint run# Testgo test -v -race -cover ./...