vibes-plug 1.0.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +20 -0
- package/AGENTS.md +66 -0
- package/BLUEPRINT.md +152 -60
- package/CHANGELOG.md +50 -0
- package/README.md +346 -194
- package/package.json +25 -25
- package/plugin.json +1 -1
- package/skills/ai-cost-token-optimizer/SKILL.md +52 -0
- package/skills/ai-llm-integration-expert/SKILL.md +180 -162
- package/skills/api-design-expert/SKILL.md +314 -310
- package/skills/app-analyzer-optimizer/SKILL.md +193 -189
- package/skills/apple-ecosystem-expert/SKILL.md +142 -0
- package/skills/async-queue-temporal-expert/SKILL.md +54 -0
- package/skills/authentication-identity-expert/SKILL.md +251 -20
- package/skills/auto-doc-updater/SKILL.md +214 -204
- package/skills/autonomous-chaos-monkey/SKILL.md +63 -0
- package/skills/autonomous-red-teamer/SKILL.md +59 -0
- package/skills/autonomous-swarm-director/SKILL.md +69 -0
- package/skills/autonomous-tdd-debugger/SKILL.md +65 -0
- package/skills/bootstrap-to-modern/SKILL.md +90 -86
- package/skills/brainstorming/SKILL.md +373 -353
- package/skills/browser-automation-expert/SKILL.md +46 -0
- package/skills/ci-cd-devops-architect/SKILL.md +72 -45
- package/skills/cloud-hosting-expert/SKILL.md +244 -244
- package/skills/coderabbit/SKILL.md +192 -192
- package/skills/cron-scheduler-expert/SKILL.md +298 -0
- package/skills/data-telemetry-expert/SKILL.md +213 -213
- package/skills/database-orm-expert/SKILL.md +294 -294
- package/skills/dependency-upgrade-migrator/SKILL.md +295 -0
- package/skills/design-system-architect/SKILL.md +27 -10
- package/skills/doku-mcp-server/SKILL.md +251 -0
- package/skills/doku-payment-gateway/SKILL.md +227 -0
- package/skills/e2e-testing-expert/SKILL.md +315 -315
- package/skills/edge-serverless-db-expert/SKILL.md +43 -0
- package/skills/email-notification-expert/SKILL.md +362 -0
- package/skills/error-resilience-expert/SKILL.md +480 -0
- package/skills/event-driven-architect/SKILL.md +81 -81
- package/skills/feature-flag-analytics-expert/SKILL.md +46 -0
- package/skills/file-upload-media-expert/SKILL.md +431 -0
- package/skills/form-validation-expert/SKILL.md +401 -0
- package/skills/fullstack-expert/SKILL.md +202 -202
- package/skills/fullstack-expert/references/api_design_guide.md +466 -466
- package/skills/fullstack-expert/references/multi_language_backend.md +528 -528
- package/skills/fullstack-expert/scripts/api_contract_validator.py +253 -253
- package/skills/fullstack-expert/scripts/architecture_analyzer.py +326 -326
- package/skills/gemini-agent-booster/SKILL.md +135 -135
- package/skills/global-a11y-i18n-expert/SKILL.md +81 -81
- package/skills/glsl-shader-expert/SKILL.md +101 -0
- package/skills/go-programming-expert/SKILL.md +295 -295
- package/skills/graphql-apollo-expert/SKILL.md +108 -0
- package/skills/hig/SKILL.md +188 -188
- package/skills/hyper-context-synthesizer/SKILL.md +55 -0
- package/skills/js-backend-expert/SKILL.md +34 -9
- package/skills/legacy-code-translator/SKILL.md +65 -0
- package/skills/llm-cost-arbitrage-router/SKILL.md +59 -0
- package/skills/logging-error-tracking-expert/SKILL.md +338 -0
- package/skills/mcp-client-orchestrator/SKILL.md +70 -0
- package/skills/mcp-server-architect/SKILL.md +194 -194
- package/skills/micro-frontend-architect/SKILL.md +106 -0
- package/skills/mobile-expo-expert/SKILL.md +186 -186
- package/skills/mobile-push-notification-expert/SKILL.md +51 -0
- package/skills/monday-design-aesthetic/SKILL.md +67 -67
- package/skills/monorepo-architect/SKILL.md +227 -227
- package/skills/mpa-orchestrator/SKILL.md +101 -101
- package/skills/multi-agent-orchestration/SKILL.md +234 -234
- package/skills/multiple-entry-points/SKILL.md +55 -55
- package/skills/mvc-expert/SKILL.md +231 -231
- package/skills/payment-gateway-expert/SKILL.md +45 -45
- package/skills/performance-web-vitals/SKILL.md +332 -332
- package/skills/post-quantum-crypto-migrator/SKILL.md +57 -0
- package/skills/prd-architect/SKILL.md +201 -191
- package/skills/proactive-background-watcher/SKILL.md +62 -0
- package/skills/production-ready-hardener/PRODUCTION_READINESS_REPORT.md +67 -0
- package/skills/production-ready-hardener/SKILL.md +173 -186
- package/skills/production-ready-hardener/references/production_checklist.md +161 -161
- package/skills/production-ready-hardener/scripts/production_readiness_scanner.py +881 -875
- package/skills/project-context-mapper/SKILL.md +79 -0
- package/skills/python-programming-expert/SKILL.md +263 -132
- package/skills/rate-limit-abuse-prevention/SKILL.md +371 -0
- package/skills/realtime-collaboration-expert/SKILL.md +45 -45
- package/skills/rust-programming-expert/SKILL.md +235 -235
- package/skills/saas-billing/SKILL.md +377 -377
- package/skills/saas-multi-tenant/SKILL.md +251 -237
- package/skills/saas-mvp-launcher/SKILL.md +10 -0
- package/skills/saas-transformer/SKILL.md +187 -144
- package/skills/saas-transformer/references/billing_integration_guide.md +401 -401
- package/skills/saas-transformer/references/feature_gating_patterns.md +137 -137
- package/skills/saas-transformer/references/saas_transformation_checklist.md +121 -121
- package/skills/saas-transformer/scripts/saas_transformation_scanner.py +39 -29
- package/skills/scalability-clean-code/SKILL.md +229 -229
- package/skills/self-evolving-memory-graph/SKILL.md +75 -0
- package/skills/self-healing-cloud-orchestrator/SKILL.md +57 -0
- package/skills/senior-frontend/SKILL.md +161 -161
- package/skills/senior-fullstack/SKILL.md +167 -167
- package/skills/seo/SKILL.md +235 -225
- package/skills/seo-geo/SKILL.md +188 -188
- package/skills/session-context-loader/SKILL.md +77 -0
- package/skills/session-handoff-resume/SKILL.md +158 -158
- package/skills/skill_baru/SKILL.md +172 -147
- package/skills/spa-orchestrator/SKILL.md +288 -288
- package/skills/state-management-expert/SKILL.md +272 -272
- package/skills/supabase-security-expert/SKILL.md +243 -243
- package/skills/tailwind-expert/SKILL.md +188 -188
- package/skills/tanstack-query-expert/SKILL.md +199 -199
- package/skills/token-saver/SKILL.md +119 -111
- package/skills/typescript-expert/SKILL.md +324 -279
- package/skills/ui-components-expert/SKILL.md +263 -46
- package/skills/ui-ux-pro-max/SKILL.md +202 -201
- package/skills/ui-ux-pro-max/scripts/__pycache__/core.cpython-310.pyc +0 -0
- package/skills/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-310.pyc +0 -0
- package/skills/ui_ux_expert/SKILL.md +17 -6
- package/skills/vector-db-rag-expert/SKILL.md +52 -0
- package/skills/vibe-code-gardener/SKILL.md +181 -173
- package/skills/visual-qa-vision-agent/SKILL.md +65 -0
- package/skills/vue-frontend-expert/SKILL.md +126 -0
- package/skills/web-3d-graphics-expert/SKILL.md +131 -0
- package/skills/web-game-engine-expert/SKILL.md +96 -0
- package/skills/web-scraper/SKILL.md +207 -205
- package/skills/website-design-cloner/SKILL.md +174 -0
- package/skills/webxr-ar-vr-expert/SKILL.md +117 -0
- package/skills/zero-to-prod-orchestrator/SKILL.md +206 -180
- package/skills/zero-trust-secret-vault/SKILL.md +40 -0
- package/vibes-swarm-demo.gif +0 -0
|
@@ -1,295 +1,295 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: go-programming-expert
|
|
3
|
-
description: "Expert-level skill for Go programming (Go 1.23/1.24+). Covers high-performance microservices, concurrency patterns, sqlc, net/http, Gin/Echo/Fiber, gRPC, and testing in English and Indonesian."
|
|
4
|
-
author: "Roedy Rustam"
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Go Programming Expert (Go 1.24 Edition)
|
|
8
|
-
|
|
9
|
-
[English](#english) | [Bahasa Indonesia](#bahasa-indonesia)
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
<a name="english"></a>
|
|
14
|
-
## English
|
|
15
|
-
|
|
16
|
-
### Description
|
|
17
|
-
Expert-level Go development for building high-performance microservices, APIs, and CLI tools. Covers **Go 1.24** features (range-over-func iterators, generic type aliases, weak pointers), structured logging with `slog`, `net/http` with the new ServeMux patterns, Gin/Echo/Fiber frameworks, sqlc for type-safe SQL, gRPC, and production testing patterns.
|
|
18
|
-
|
|
19
|
-
### Trigger Conditions
|
|
20
|
-
- Writing Go 1.23+ / 1.24+ microservices or APIs.
|
|
21
|
-
- Implementing concurrency patterns with goroutines, channels, and `sync` primitives.
|
|
22
|
-
- Using structured logging with `log/slog`.
|
|
23
|
-
- Building HTTP servers with `net/http` ServeMux (Go 1.22+) or Gin/Echo/Fiber.
|
|
24
|
-
- Writing type-safe SQL with **sqlc** or using **GORM**.
|
|
25
|
-
- Implementing gRPC services with protobuf.
|
|
26
|
-
- Writing Go tests with the standard `testing` package + `testify`.
|
|
27
|
-
|
|
28
|
-
### Go 1.24 — Key Features
|
|
29
|
-
|
|
30
|
-
#### Range-Over-Func (Go 1.22 → Stable in 1.24)
|
|
31
|
-
Range over custom iterators — enables functional-style collection operations:
|
|
32
|
-
```go
|
|
33
|
-
// Define an iterator function
|
|
34
|
-
func Fibonacci() iter.Seq[int] {
|
|
35
|
-
return func(yield func(int) bool) {
|
|
36
|
-
a, b := 0, 1
|
|
37
|
-
for {
|
|
38
|
-
if !yield(a) {
|
|
39
|
-
return
|
|
40
|
-
}
|
|
41
|
-
a, b = b, a+b
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Range over it naturally
|
|
47
|
-
for n := range Fibonacci() {
|
|
48
|
-
if n > 100 {
|
|
49
|
-
break
|
|
50
|
-
}
|
|
51
|
-
fmt.Println(n)
|
|
52
|
-
}
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
#### Generic Type Aliases (Go 1.24)
|
|
56
|
-
```go
|
|
57
|
-
// Type alias with generic parameters
|
|
58
|
-
type Set[T comparable] = map[T]struct{}
|
|
59
|
-
type Result[T any] = struct{ Value T; Err error }
|
|
60
|
-
|
|
61
|
-
// Usage
|
|
62
|
-
var s Set[string] = make(map[string]struct{})
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
#### Weak Pointers (Go 1.24)
|
|
66
|
-
```go
|
|
67
|
-
import "weak"
|
|
68
|
-
|
|
69
|
-
// Weak pointer — does not prevent GC collection
|
|
70
|
-
ptr := weak.Make(&myStruct{})
|
|
71
|
-
if val := ptr.Value(); val != nil {
|
|
72
|
-
// Still alive
|
|
73
|
-
}
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
### Structured Logging with `log/slog`
|
|
77
|
-
```go
|
|
78
|
-
package main
|
|
79
|
-
|
|
80
|
-
import (
|
|
81
|
-
"log/slog"
|
|
82
|
-
"os"
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
func main() {
|
|
86
|
-
// Production JSON logger
|
|
87
|
-
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
|
|
88
|
-
Level: slog.LevelInfo,
|
|
89
|
-
AddSource: true, // include file:line
|
|
90
|
-
}))
|
|
91
|
-
slog.SetDefault(logger)
|
|
92
|
-
|
|
93
|
-
slog.Info("server started", "port", 8080, "env", "production")
|
|
94
|
-
slog.Error("database connection failed", "error", err, "host", dbHost)
|
|
95
|
-
|
|
96
|
-
// Grouped context
|
|
97
|
-
reqLogger := logger.WithGroup("request").With(
|
|
98
|
-
"trace_id", traceID,
|
|
99
|
-
"user_id", userID,
|
|
100
|
-
)
|
|
101
|
-
reqLogger.Info("handler called", "method", r.Method, "path", r.URL.Path)
|
|
102
|
-
}
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### HTTP Server — net/http ServeMux (Go 1.22+)
|
|
106
|
-
Go 1.22 upgraded the standard ServeMux with method-based routing and path parameters — reducing the need for external routers:
|
|
107
|
-
```go
|
|
108
|
-
package main
|
|
109
|
-
|
|
110
|
-
import (
|
|
111
|
-
"encoding/json"
|
|
112
|
-
"net/http"
|
|
113
|
-
"log/slog"
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
func main() {
|
|
117
|
-
mux := http.NewServeMux()
|
|
118
|
-
|
|
119
|
-
// Method + path pattern matching (Go 1.22+)
|
|
120
|
-
mux.HandleFunc("GET /api/users", listUsers)
|
|
121
|
-
mux.HandleFunc("POST /api/users", createUser)
|
|
122
|
-
mux.HandleFunc("GET /api/users/{id}", getUser) // path params
|
|
123
|
-
mux.HandleFunc("DELETE /api/users/{id}", deleteUser)
|
|
124
|
-
|
|
125
|
-
slog.Info("starting server", "addr", ":8080")
|
|
126
|
-
http.ListenAndServe(":8080", mux)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
func getUser(w http.ResponseWriter, r *http.Request) {
|
|
130
|
-
id := r.PathValue("id") // Extract path parameter
|
|
131
|
-
// ...
|
|
132
|
-
w.Header().Set("Content-Type", "application/json")
|
|
133
|
-
json.NewEncoder(w).Encode(user)
|
|
134
|
-
}
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
### Type-Safe SQL with sqlc
|
|
138
|
-
```bash
|
|
139
|
-
# Install sqlc
|
|
140
|
-
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
|
|
141
|
-
|
|
142
|
-
# sqlc.yaml
|
|
143
|
-
version: "2"
|
|
144
|
-
sql:
|
|
145
|
-
- engine: "postgresql"
|
|
146
|
-
queries: "queries/"
|
|
147
|
-
schema: "schema/"
|
|
148
|
-
gen:
|
|
149
|
-
go:
|
|
150
|
-
package: "db"
|
|
151
|
-
out: "internal/db"
|
|
152
|
-
emit_json_tags: true
|
|
153
|
-
emit_interface: true
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
```sql
|
|
157
|
-
-- queries/users.sql
|
|
158
|
-
-- name: GetUser :one
|
|
159
|
-
SELECT * FROM users WHERE id = $1 LIMIT 1;
|
|
160
|
-
|
|
161
|
-
-- name: ListUsers :many
|
|
162
|
-
SELECT * FROM users ORDER BY created_at DESC LIMIT $1 OFFSET $2;
|
|
163
|
-
|
|
164
|
-
-- name: CreateUser :one
|
|
165
|
-
INSERT INTO users (name, email) VALUES ($1, $2) RETURNING *;
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
```go
|
|
169
|
-
// Generated type-safe Go code (used in handlers)
|
|
170
|
-
user, err := queries.GetUser(ctx, userID) // Fully typed!
|
|
171
|
-
users, err := queries.ListUsers(ctx, db.ListUsersParams{Limit: 20, Offset: 0})
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
### Concurrency Patterns
|
|
175
|
-
|
|
176
|
-
#### errgroup for Parallel Work
|
|
177
|
-
```go
|
|
178
|
-
import "golang.org/x/sync/errgroup"
|
|
179
|
-
|
|
180
|
-
g, ctx := errgroup.WithContext(context.Background())
|
|
181
|
-
|
|
182
|
-
g.Go(func() error { return fetchA(ctx) })
|
|
183
|
-
g.Go(func() error { return fetchB(ctx) })
|
|
184
|
-
|
|
185
|
-
if err := g.Wait(); err != nil {
|
|
186
|
-
// First error from any goroutine
|
|
187
|
-
return fmt.Errorf("parallel fetch: %w", err)
|
|
188
|
-
}
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
#### Worker Pool Pattern
|
|
192
|
-
```go
|
|
193
|
-
func workerPool(jobs <-chan Job, results chan<- Result, numWorkers int) {
|
|
194
|
-
var wg sync.WaitGroup
|
|
195
|
-
for range numWorkers {
|
|
196
|
-
wg.Add(1)
|
|
197
|
-
go func() {
|
|
198
|
-
defer wg.Done()
|
|
199
|
-
for job := range jobs {
|
|
200
|
-
results <- process(job)
|
|
201
|
-
}
|
|
202
|
-
}()
|
|
203
|
-
}
|
|
204
|
-
wg.Wait()
|
|
205
|
-
close(results)
|
|
206
|
-
}
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
### Testing Best Practices
|
|
210
|
-
```go
|
|
211
|
-
package user_test
|
|
212
|
-
|
|
213
|
-
import (
|
|
214
|
-
"testing"
|
|
215
|
-
"github.com/stretchr/testify/assert"
|
|
216
|
-
"github.com/stretchr/testify/require"
|
|
217
|
-
)
|
|
218
|
-
|
|
219
|
-
func TestGetUser(t *testing.T) {
|
|
220
|
-
t.Parallel() // Always parallelize independent tests
|
|
221
|
-
|
|
222
|
-
// Table-driven tests
|
|
223
|
-
tests := []struct{
|
|
224
|
-
name string
|
|
225
|
-
userID string
|
|
226
|
-
want *User
|
|
227
|
-
wantErr bool
|
|
228
|
-
}{
|
|
229
|
-
{"valid user", "user-123", &User{ID: "user-123"}, false},
|
|
230
|
-
{"not found", "missing", nil, true},
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
for _, tt := range tests {
|
|
234
|
-
t.Run(tt.name, func(t *testing.T) {
|
|
235
|
-
t.Parallel()
|
|
236
|
-
got, err := GetUser(context.Background(), tt.userID)
|
|
237
|
-
if tt.wantErr {
|
|
238
|
-
require.Error(t, err)
|
|
239
|
-
return
|
|
240
|
-
}
|
|
241
|
-
require.NoError(t, err)
|
|
242
|
-
assert.Equal(t, tt.want.ID, got.ID)
|
|
243
|
-
})
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
---
|
|
249
|
-
|
|
250
|
-
<a name="bahasa-indonesia"></a>
|
|
251
|
-
## Bahasa Indonesia
|
|
252
|
-
|
|
253
|
-
### Deskripsi
|
|
254
|
-
Panduan Go tingkat ahli untuk membangun microservices, API, dan CLI tool berkinerja tinggi. Mencakup fitur **Go 1.24** (range-over-func, generic type alias, weak pointer), structured logging dengan `slog`, ServeMux `net/http` dengan pola baru (Go 1.22+), framework Gin/Echo/Fiber, sqlc untuk SQL type-safe, gRPC, dan pola pengujian produksi.
|
|
255
|
-
|
|
256
|
-
### Kondisi Pemicu
|
|
257
|
-
- Menulis microservices atau API Go 1.23+/1.24+.
|
|
258
|
-
- Mengimplementasikan pola konkurensi dengan goroutine, channel, dan primitif `sync`.
|
|
259
|
-
- Menggunakan structured logging dengan `log/slog`.
|
|
260
|
-
- Membangun HTTP server dengan ServeMux `net/http` (Go 1.22+) atau Gin/Echo/Fiber.
|
|
261
|
-
- Menulis SQL type-safe dengan **sqlc** atau GORM.
|
|
262
|
-
- Mengimplementasikan layanan gRPC dengan protobuf.
|
|
263
|
-
|
|
264
|
-
### Go 1.24 — Fitur Utama
|
|
265
|
-
|
|
266
|
-
#### Range-Over-Func (Stabil di 1.24)
|
|
267
|
-
Go 1.24 menstabilkan range over iterator function — memungkinkan koleksi gaya fungsional yang idiomatis tanpa mengekspos slice internal.
|
|
268
|
-
|
|
269
|
-
#### Generic Type Alias
|
|
270
|
-
Go 1.24 memungkinkan alias tipe dengan parameter generic, meningkatkan komposibilitas tipe.
|
|
271
|
-
|
|
272
|
-
#### Weak Pointer
|
|
273
|
-
`weak.Make()` membuat pointer lemah yang tidak mencegah GC mengumpulkan objek — berguna untuk cache.
|
|
274
|
-
|
|
275
|
-
### Structured Logging dengan `log/slog`
|
|
276
|
-
Paket `log/slog` bawaan Go (sejak 1.21) mendukung output JSON terstruktur, level log, dan pengelompokan atribut. Gunakan sebagai standar logging di semua proyek Go baru.
|
|
277
|
-
|
|
278
|
-
### HTTP Server — net/http ServeMux (Go 1.22+)
|
|
279
|
-
ServeMux Go 1.22 mendukung pencocokan berdasarkan metode HTTP dan parameter path — mengurangi kebutuhan router eksternal untuk API sederhana.
|
|
280
|
-
|
|
281
|
-
### SQL Type-Safe dengan sqlc
|
|
282
|
-
`sqlc` menghasilkan kode Go yang fully typed dari query SQL dan skema database — menghilangkan kebutuhan ORM untuk sebagian besar kasus.
|
|
283
|
-
|
|
284
|
-
### Pola Konkurensi
|
|
285
|
-
|
|
286
|
-
#### errgroup
|
|
287
|
-
Gunakan `errgroup.WithContext()` dari `golang.org/x/sync/errgroup` untuk menjalankan goroutine paralel dan mengumpulkan error pertama secara aman.
|
|
288
|
-
|
|
289
|
-
#### Worker Pool
|
|
290
|
-
Gunakan pola worker pool dengan channel untuk memproses pekerjaan secara paralel dengan jumlah goroutine yang terkendali.
|
|
291
|
-
|
|
292
|
-
### Best Practices Pengujian
|
|
293
|
-
- Gunakan `t.Parallel()` untuk semua test independen.
|
|
294
|
-
- Gunakan table-driven tests untuk menguji banyak skenario dengan kode minimal.
|
|
295
|
-
- Gunakan `testify/assert` dan `testify/require` untuk assertion yang ekspresif.
|
|
1
|
+
---
|
|
2
|
+
name: go-programming-expert
|
|
3
|
+
description: "Expert-level skill for Go programming (Go 1.23/1.24+). Covers high-performance microservices, concurrency patterns, sqlc, net/http, Gin/Echo/Fiber, gRPC, and testing in English and Indonesian."
|
|
4
|
+
author: "Roedy Rustam"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Go Programming Expert (Go 1.24 Edition)
|
|
8
|
+
|
|
9
|
+
[English](#english) | [Bahasa Indonesia](#bahasa-indonesia)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
<a name="english"></a>
|
|
14
|
+
## English
|
|
15
|
+
|
|
16
|
+
### Description
|
|
17
|
+
Expert-level Go development for building high-performance microservices, APIs, and CLI tools. Covers **Go 1.24** features (range-over-func iterators, generic type aliases, weak pointers), structured logging with `slog`, `net/http` with the new ServeMux patterns, Gin/Echo/Fiber frameworks, sqlc for type-safe SQL, gRPC, and production testing patterns.
|
|
18
|
+
|
|
19
|
+
### Trigger Conditions
|
|
20
|
+
- Writing Go 1.23+ / 1.24+ microservices or APIs.
|
|
21
|
+
- Implementing concurrency patterns with goroutines, channels, and `sync` primitives.
|
|
22
|
+
- Using structured logging with `log/slog`.
|
|
23
|
+
- Building HTTP servers with `net/http` ServeMux (Go 1.22+) or Gin/Echo/Fiber.
|
|
24
|
+
- Writing type-safe SQL with **sqlc** or using **GORM**.
|
|
25
|
+
- Implementing gRPC services with protobuf.
|
|
26
|
+
- Writing Go tests with the standard `testing` package + `testify`.
|
|
27
|
+
|
|
28
|
+
### Go 1.24 — Key Features
|
|
29
|
+
|
|
30
|
+
#### Range-Over-Func (Go 1.22 → Stable in 1.24)
|
|
31
|
+
Range over custom iterators — enables functional-style collection operations:
|
|
32
|
+
```go
|
|
33
|
+
// Define an iterator function
|
|
34
|
+
func Fibonacci() iter.Seq[int] {
|
|
35
|
+
return func(yield func(int) bool) {
|
|
36
|
+
a, b := 0, 1
|
|
37
|
+
for {
|
|
38
|
+
if !yield(a) {
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
a, b = b, a+b
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Range over it naturally
|
|
47
|
+
for n := range Fibonacci() {
|
|
48
|
+
if n > 100 {
|
|
49
|
+
break
|
|
50
|
+
}
|
|
51
|
+
fmt.Println(n)
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
#### Generic Type Aliases (Go 1.24)
|
|
56
|
+
```go
|
|
57
|
+
// Type alias with generic parameters
|
|
58
|
+
type Set[T comparable] = map[T]struct{}
|
|
59
|
+
type Result[T any] = struct{ Value T; Err error }
|
|
60
|
+
|
|
61
|
+
// Usage
|
|
62
|
+
var s Set[string] = make(map[string]struct{})
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### Weak Pointers (Go 1.24)
|
|
66
|
+
```go
|
|
67
|
+
import "weak"
|
|
68
|
+
|
|
69
|
+
// Weak pointer — does not prevent GC collection
|
|
70
|
+
ptr := weak.Make(&myStruct{})
|
|
71
|
+
if val := ptr.Value(); val != nil {
|
|
72
|
+
// Still alive
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Structured Logging with `log/slog`
|
|
77
|
+
```go
|
|
78
|
+
package main
|
|
79
|
+
|
|
80
|
+
import (
|
|
81
|
+
"log/slog"
|
|
82
|
+
"os"
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
func main() {
|
|
86
|
+
// Production JSON logger
|
|
87
|
+
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
|
|
88
|
+
Level: slog.LevelInfo,
|
|
89
|
+
AddSource: true, // include file:line
|
|
90
|
+
}))
|
|
91
|
+
slog.SetDefault(logger)
|
|
92
|
+
|
|
93
|
+
slog.Info("server started", "port", 8080, "env", "production")
|
|
94
|
+
slog.Error("database connection failed", "error", err, "host", dbHost)
|
|
95
|
+
|
|
96
|
+
// Grouped context
|
|
97
|
+
reqLogger := logger.WithGroup("request").With(
|
|
98
|
+
"trace_id", traceID,
|
|
99
|
+
"user_id", userID,
|
|
100
|
+
)
|
|
101
|
+
reqLogger.Info("handler called", "method", r.Method, "path", r.URL.Path)
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### HTTP Server — net/http ServeMux (Go 1.22+)
|
|
106
|
+
Go 1.22 upgraded the standard ServeMux with method-based routing and path parameters — reducing the need for external routers:
|
|
107
|
+
```go
|
|
108
|
+
package main
|
|
109
|
+
|
|
110
|
+
import (
|
|
111
|
+
"encoding/json"
|
|
112
|
+
"net/http"
|
|
113
|
+
"log/slog"
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
func main() {
|
|
117
|
+
mux := http.NewServeMux()
|
|
118
|
+
|
|
119
|
+
// Method + path pattern matching (Go 1.22+)
|
|
120
|
+
mux.HandleFunc("GET /api/users", listUsers)
|
|
121
|
+
mux.HandleFunc("POST /api/users", createUser)
|
|
122
|
+
mux.HandleFunc("GET /api/users/{id}", getUser) // path params
|
|
123
|
+
mux.HandleFunc("DELETE /api/users/{id}", deleteUser)
|
|
124
|
+
|
|
125
|
+
slog.Info("starting server", "addr", ":8080")
|
|
126
|
+
http.ListenAndServe(":8080", mux)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
func getUser(w http.ResponseWriter, r *http.Request) {
|
|
130
|
+
id := r.PathValue("id") // Extract path parameter
|
|
131
|
+
// ...
|
|
132
|
+
w.Header().Set("Content-Type", "application/json")
|
|
133
|
+
json.NewEncoder(w).Encode(user)
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Type-Safe SQL with sqlc
|
|
138
|
+
```bash
|
|
139
|
+
# Install sqlc
|
|
140
|
+
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
|
|
141
|
+
|
|
142
|
+
# sqlc.yaml
|
|
143
|
+
version: "2"
|
|
144
|
+
sql:
|
|
145
|
+
- engine: "postgresql"
|
|
146
|
+
queries: "queries/"
|
|
147
|
+
schema: "schema/"
|
|
148
|
+
gen:
|
|
149
|
+
go:
|
|
150
|
+
package: "db"
|
|
151
|
+
out: "internal/db"
|
|
152
|
+
emit_json_tags: true
|
|
153
|
+
emit_interface: true
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
```sql
|
|
157
|
+
-- queries/users.sql
|
|
158
|
+
-- name: GetUser :one
|
|
159
|
+
SELECT * FROM users WHERE id = $1 LIMIT 1;
|
|
160
|
+
|
|
161
|
+
-- name: ListUsers :many
|
|
162
|
+
SELECT * FROM users ORDER BY created_at DESC LIMIT $1 OFFSET $2;
|
|
163
|
+
|
|
164
|
+
-- name: CreateUser :one
|
|
165
|
+
INSERT INTO users (name, email) VALUES ($1, $2) RETURNING *;
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
```go
|
|
169
|
+
// Generated type-safe Go code (used in handlers)
|
|
170
|
+
user, err := queries.GetUser(ctx, userID) // Fully typed!
|
|
171
|
+
users, err := queries.ListUsers(ctx, db.ListUsersParams{Limit: 20, Offset: 0})
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Concurrency Patterns
|
|
175
|
+
|
|
176
|
+
#### errgroup for Parallel Work
|
|
177
|
+
```go
|
|
178
|
+
import "golang.org/x/sync/errgroup"
|
|
179
|
+
|
|
180
|
+
g, ctx := errgroup.WithContext(context.Background())
|
|
181
|
+
|
|
182
|
+
g.Go(func() error { return fetchA(ctx) })
|
|
183
|
+
g.Go(func() error { return fetchB(ctx) })
|
|
184
|
+
|
|
185
|
+
if err := g.Wait(); err != nil {
|
|
186
|
+
// First error from any goroutine
|
|
187
|
+
return fmt.Errorf("parallel fetch: %w", err)
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
#### Worker Pool Pattern
|
|
192
|
+
```go
|
|
193
|
+
func workerPool(jobs <-chan Job, results chan<- Result, numWorkers int) {
|
|
194
|
+
var wg sync.WaitGroup
|
|
195
|
+
for range numWorkers {
|
|
196
|
+
wg.Add(1)
|
|
197
|
+
go func() {
|
|
198
|
+
defer wg.Done()
|
|
199
|
+
for job := range jobs {
|
|
200
|
+
results <- process(job)
|
|
201
|
+
}
|
|
202
|
+
}()
|
|
203
|
+
}
|
|
204
|
+
wg.Wait()
|
|
205
|
+
close(results)
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Testing Best Practices
|
|
210
|
+
```go
|
|
211
|
+
package user_test
|
|
212
|
+
|
|
213
|
+
import (
|
|
214
|
+
"testing"
|
|
215
|
+
"github.com/stretchr/testify/assert"
|
|
216
|
+
"github.com/stretchr/testify/require"
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
func TestGetUser(t *testing.T) {
|
|
220
|
+
t.Parallel() // Always parallelize independent tests
|
|
221
|
+
|
|
222
|
+
// Table-driven tests
|
|
223
|
+
tests := []struct{
|
|
224
|
+
name string
|
|
225
|
+
userID string
|
|
226
|
+
want *User
|
|
227
|
+
wantErr bool
|
|
228
|
+
}{
|
|
229
|
+
{"valid user", "user-123", &User{ID: "user-123"}, false},
|
|
230
|
+
{"not found", "missing", nil, true},
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
for _, tt := range tests {
|
|
234
|
+
t.Run(tt.name, func(t *testing.T) {
|
|
235
|
+
t.Parallel()
|
|
236
|
+
got, err := GetUser(context.Background(), tt.userID)
|
|
237
|
+
if tt.wantErr {
|
|
238
|
+
require.Error(t, err)
|
|
239
|
+
return
|
|
240
|
+
}
|
|
241
|
+
require.NoError(t, err)
|
|
242
|
+
assert.Equal(t, tt.want.ID, got.ID)
|
|
243
|
+
})
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
<a name="bahasa-indonesia"></a>
|
|
251
|
+
## Bahasa Indonesia
|
|
252
|
+
|
|
253
|
+
### Deskripsi
|
|
254
|
+
Panduan Go tingkat ahli untuk membangun microservices, API, dan CLI tool berkinerja tinggi. Mencakup fitur **Go 1.24** (range-over-func, generic type alias, weak pointer), structured logging dengan `slog`, ServeMux `net/http` dengan pola baru (Go 1.22+), framework Gin/Echo/Fiber, sqlc untuk SQL type-safe, gRPC, dan pola pengujian produksi.
|
|
255
|
+
|
|
256
|
+
### Kondisi Pemicu
|
|
257
|
+
- Menulis microservices atau API Go 1.23+/1.24+.
|
|
258
|
+
- Mengimplementasikan pola konkurensi dengan goroutine, channel, dan primitif `sync`.
|
|
259
|
+
- Menggunakan structured logging dengan `log/slog`.
|
|
260
|
+
- Membangun HTTP server dengan ServeMux `net/http` (Go 1.22+) atau Gin/Echo/Fiber.
|
|
261
|
+
- Menulis SQL type-safe dengan **sqlc** atau GORM.
|
|
262
|
+
- Mengimplementasikan layanan gRPC dengan protobuf.
|
|
263
|
+
|
|
264
|
+
### Go 1.24 — Fitur Utama
|
|
265
|
+
|
|
266
|
+
#### Range-Over-Func (Stabil di 1.24)
|
|
267
|
+
Go 1.24 menstabilkan range over iterator function — memungkinkan koleksi gaya fungsional yang idiomatis tanpa mengekspos slice internal.
|
|
268
|
+
|
|
269
|
+
#### Generic Type Alias
|
|
270
|
+
Go 1.24 memungkinkan alias tipe dengan parameter generic, meningkatkan komposibilitas tipe.
|
|
271
|
+
|
|
272
|
+
#### Weak Pointer
|
|
273
|
+
`weak.Make()` membuat pointer lemah yang tidak mencegah GC mengumpulkan objek — berguna untuk cache.
|
|
274
|
+
|
|
275
|
+
### Structured Logging dengan `log/slog`
|
|
276
|
+
Paket `log/slog` bawaan Go (sejak 1.21) mendukung output JSON terstruktur, level log, dan pengelompokan atribut. Gunakan sebagai standar logging di semua proyek Go baru.
|
|
277
|
+
|
|
278
|
+
### HTTP Server — net/http ServeMux (Go 1.22+)
|
|
279
|
+
ServeMux Go 1.22 mendukung pencocokan berdasarkan metode HTTP dan parameter path — mengurangi kebutuhan router eksternal untuk API sederhana.
|
|
280
|
+
|
|
281
|
+
### SQL Type-Safe dengan sqlc
|
|
282
|
+
`sqlc` menghasilkan kode Go yang fully typed dari query SQL dan skema database — menghilangkan kebutuhan ORM untuk sebagian besar kasus.
|
|
283
|
+
|
|
284
|
+
### Pola Konkurensi
|
|
285
|
+
|
|
286
|
+
#### errgroup
|
|
287
|
+
Gunakan `errgroup.WithContext()` dari `golang.org/x/sync/errgroup` untuk menjalankan goroutine paralel dan mengumpulkan error pertama secara aman.
|
|
288
|
+
|
|
289
|
+
#### Worker Pool
|
|
290
|
+
Gunakan pola worker pool dengan channel untuk memproses pekerjaan secara paralel dengan jumlah goroutine yang terkendali.
|
|
291
|
+
|
|
292
|
+
### Best Practices Pengujian
|
|
293
|
+
- Gunakan `t.Parallel()` untuk semua test independen.
|
|
294
|
+
- Gunakan table-driven tests untuk menguji banyak skenario dengan kode minimal.
|
|
295
|
+
- Gunakan `testify/assert` dan `testify/require` untuk assertion yang ekspresif.
|