-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnippets.go
More file actions
449 lines (442 loc) · 11.5 KB
/
snippets.go
File metadata and controls
449 lines (442 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
package schema
// Snippet represents a code snippet for IDE support.
// Body uses ${N:placeholder} VSCode-style syntax.
type Snippet struct {
Name string // human-readable name
Prefix string // trigger prefix / keyword
Description string // short description shown in IDE
Body []string // lines of the snippet body
}
// GetSnippets returns the canonical set of workflow configuration snippets.
func GetSnippets() []Snippet {
return []Snippet{
// ---------------------------------------------------------------
// Module snippets (10)
// ---------------------------------------------------------------
{
Name: "HTTP Server Module",
Prefix: "mod-http-server",
Description: "HTTP server module listening on a configurable address",
Body: []string{
"- name: ${1:server}",
" type: http.server",
" config:",
" address: ${2::8080}",
},
},
{
Name: "HTTP Router Module",
Prefix: "mod-http-router",
Description: "HTTP router module that dispatches requests to handlers",
Body: []string{
"- name: ${1:router}",
" type: http.router",
" dependsOn:",
" - ${2:server}",
},
},
{
Name: "SQLite Storage Module",
Prefix: "mod-sqlite",
Description: "SQLite database storage module",
Body: []string{
"- name: ${1:db}",
" type: storage.sqlite",
" config:",
" dbPath: ${2:data/app.db}",
" walMode: ${3:true}",
},
},
{
Name: "NoSQL Memory Module",
Prefix: "mod-nosql",
Description: "In-memory NoSQL document store",
Body: []string{
"- name: ${1:store}",
" type: nosql.memory",
" config:",
" collection: ${2:documents}",
},
},
{
Name: "JWT Auth Module",
Prefix: "mod-jwt",
Description: "JWT authentication module",
Body: []string{
"- name: ${1:auth}",
" type: auth.jwt",
" config:",
" secret: ${2:my-secret-key}",
" tokenExpiry: ${3:24h}",
" issuer: ${4:my-app}",
},
},
{
Name: "Messaging Broker Module",
Prefix: "mod-broker",
Description: "In-process messaging broker for pub/sub",
Body: []string{
"- name: ${1:broker}",
" type: messaging.broker",
" config:",
" maxQueueSize: ${2:1000}",
},
},
{
Name: "State Machine Module",
Prefix: "mod-statemachine",
Description: "State machine engine for workflow orchestration",
Body: []string{
"- name: ${1:state-engine}",
" type: statemachine.engine",
" config:",
" maxInstances: ${2:100}",
" instanceTTL: ${3:24h}",
},
},
{
Name: "OTEL Observability Module",
Prefix: "mod-otel",
Description: "OpenTelemetry observability module",
Body: []string{
"- name: ${1:otel}",
" type: observability.otel",
" config:",
" endpoint: ${2:localhost:4317}",
" serviceName: ${3:my-service}",
},
},
{
Name: "Cache Modular Module",
Prefix: "mod-cache",
Description: "Modular cache adapter",
Body: []string{
"- name: ${1:cache}",
" type: cache.modular",
},
},
{
Name: "Secrets Vault Module",
Prefix: "mod-secrets",
Description: "HashiCorp Vault secrets module",
Body: []string{
"- name: ${1:secrets}",
" type: secrets.vault",
" config:",
" mode: ${2:dev}",
" address: ${3:http://localhost:8200}",
" token: ${4:root}",
" mountPath: ${5:secret}",
},
},
// ---------------------------------------------------------------
// Pipeline scaffold (1)
// ---------------------------------------------------------------
{
Name: "Pipeline Scaffold",
Prefix: "pipeline",
Description: "Full pipeline definition with trigger and steps",
Body: []string{
"${1:my-pipeline}:",
" trigger:",
" type: ${2:http}",
" config:",
" path: ${3:/api/v1/resource}",
" method: ${4:POST}",
" steps:",
" - type: step.validate",
" config:",
" required:",
" - ${5:field}",
" - type: step.json_response",
" config:",
" status: ${6:200}",
" body: ${7:{ \"ok\": true }}",
},
},
// ---------------------------------------------------------------
// Step snippets (12+)
// ---------------------------------------------------------------
{
Name: "Step: Set Variable",
Prefix: "step-set",
Description: "Set a named variable in the pipeline context",
Body: []string{
"- type: step.set",
" config:",
" values:",
" ${1:key}: ${2:value}",
},
},
{
Name: "Step: HTTP Call",
Prefix: "step-http-call",
Description: "Make an outbound HTTP request",
Body: []string{
"- type: step.http_call",
" config:",
" url: ${1:https://api.example.com/endpoint}",
" method: ${2:POST}",
" headers:",
" Content-Type: application/json",
" body: ${3:{{ json . }}}",
" timeout: ${4:30s}",
},
},
{
Name: "Step: JSON Response",
Prefix: "step-json-response",
Description: "Return a JSON HTTP response",
Body: []string{
"- type: step.json_response",
" config:",
" status: ${1:200}",
" body:",
" ${2:message}: ${3:ok}",
},
},
{
Name: "Step: Validate",
Prefix: "step-validate",
Description: "Validate request data against rules",
Body: []string{
"- type: step.validate",
" config:",
" required:",
" - ${1:field1}",
" rules:",
" ${2:field1}: ${3:string}",
},
},
{
Name: "Step: Transform",
Prefix: "step-transform",
Description: "Transform data using a mapping template",
Body: []string{
"- type: step.transform",
" config:",
" mapping:",
" ${1:output_field}: ${2:{{ .input_field }}}",
},
},
{
Name: "Step: DB Query",
Prefix: "step-db-query",
Description: "Execute a read-only SQL query",
Body: []string{
"- type: step.db_query",
" config:",
" database: ${1:db}",
" query: ${2:SELECT * FROM ${3:table} WHERE id = ?}",
" params:",
" - ${4:{{ .id }}}",
},
},
{
Name: "Step: DB Exec",
Prefix: "step-db-exec",
Description: "Execute a SQL write statement",
Body: []string{
"- type: step.db_exec",
" config:",
" database: ${1:db}",
" query: ${2:INSERT INTO ${3:table} (col) VALUES (?)}",
" params:",
" - ${4:{{ .value }}}",
},
},
{
Name: "Step: Auth Required",
Prefix: "step-auth",
Description: "Require authentication and optional role/scope",
Body: []string{
"- type: step.auth_required",
" config:",
" roles:",
" - ${1:admin}",
},
},
{
Name: "Step: Cache Get",
Prefix: "step-cache-get",
Description: "Get a value from the cache",
Body: []string{
"- type: step.cache_get",
" config:",
" cache: ${1:cache}",
" key: ${2:{{ .id }}}",
" output: ${3:cached_result}",
},
},
{
Name: "Step: Cache Set",
Prefix: "step-cache-set",
Description: "Store a value in the cache with optional TTL",
Body: []string{
"- type: step.cache_set",
" config:",
" cache: ${1:cache}",
" key: ${2:{{ .id }}}",
" value: ${3:{{ .result }}}",
" ttl: ${4:5m}",
},
},
{
Name: "Step: Event Publish",
Prefix: "step-event-publish",
Description: "Publish a CloudEvents-formatted event to a message broker or EventPublisher",
Body: []string{
"- type: step.event_publish",
" config:",
" provider: ${1:broker}",
" stream: ${2:messaging.events}",
" event_type: ${3:resource.created}",
" source: ${4:/api/resource}",
" data:",
" id: ${5:{{ .id }}}",
},
},
{
Name: "Step: Log",
Prefix: "step-log",
Description: "Log a message at the specified level",
Body: []string{
"- type: step.log",
" config:",
" level: ${1:info}",
" message: ${2:Processing request: {{ .id }}}",
},
},
// ---------------------------------------------------------------
// Trigger snippets (3)
// ---------------------------------------------------------------
{
Name: "Trigger: HTTP",
Prefix: "trigger-http",
Description: "HTTP trigger for a specific path and method",
Body: []string{
"trigger:",
" type: http",
" config:",
" path: ${1:/api/v1/${2:resource}}",
" method: ${3:GET}",
},
},
{
Name: "Trigger: Schedule",
Prefix: "trigger-schedule",
Description: "Cron-based schedule trigger",
Body: []string{
"trigger:",
" type: schedule",
" config:",
" cron: ${1:0 * * * *}",
" timezone: ${2:UTC}",
},
},
{
Name: "Trigger: Event",
Prefix: "trigger-event",
Description: "Event-driven trigger subscribing to a topic",
Body: []string{
"trigger:",
" type: event",
" config:",
" topic: ${1:events.created}",
" broker: ${2:broker}",
},
},
// ---------------------------------------------------------------
// Workflow snippets (3)
// ---------------------------------------------------------------
{
Name: "Workflow: HTTP",
Prefix: "workflow-http",
Description: "HTTP workflow handler with route definitions",
Body: []string{
"workflows:",
" http:",
" routes:",
" - path: ${1:/api/v1/${2:resource}}",
" method: ${3:GET}",
" pipeline: ${4:get-resources}",
},
},
{
Name: "Workflow: Messaging",
Prefix: "workflow-messaging",
Description: "Messaging workflow handler with topic subscriptions",
Body: []string{
"workflows:",
" messaging:",
" subscriptions:",
" - topic: ${1:events.created}",
" pipeline: ${2:handle-created}",
},
},
{
Name: "Workflow: State Machine",
Prefix: "workflow-statemachine",
Description: "State machine workflow handler",
Body: []string{
"workflows:",
" statemachine:",
" engine: ${1:state-engine}",
" states:",
" - name: ${2:pending}",
" transitions:",
" - name: ${3:submit}",
" to: ${4:active}",
},
},
// ---------------------------------------------------------------
// Structural snippets (3)
// ---------------------------------------------------------------
{
Name: "App Structure",
Prefix: "app",
Description: "Full application config skeleton",
Body: []string{
"modules:",
" - name: ${1:server}",
" type: http.server",
" config:",
" address: ${2::8080}",
" - name: ${3:router}",
" type: http.router",
" dependsOn:",
" - ${1:server}",
"",
"workflows:",
" http:",
" routes: []",
"",
"triggers:",
" http:",
" port: ${4:8080}",
},
},
{
Name: "Requires Section",
Prefix: "requires",
Description: "Plugin and version dependency declarations",
Body: []string{
"requires:",
" version: ${1:v0.2.0}",
" plugins:",
" - ${2:storage}",
" - ${3:auth}",
},
},
{
Name: "Imports Section",
Prefix: "imports",
Description: "Import external configuration files",
Body: []string{
"imports:",
" - ${1:config/modules.yaml}",
" - ${2:config/workflows.yaml}",
},
},
}
}