@@ -67,6 +67,11 @@ func (cmd *ServiceRunCommand) Run(app server.Cmd) error {
67
67
return err
68
68
}
69
69
70
+ endpoint , err := app .GetEndpoint ()
71
+ if err != nil {
72
+ return err
73
+ }
74
+
70
75
// Set the configuration
71
76
err = errors .Join (err , provider .Load ("log" , "main" , func (ctx context.Context , label string , config server.Plugin ) error {
72
77
logger := config .(* logger.Config )
@@ -75,14 +80,14 @@ func (cmd *ServiceRunCommand) Run(app server.Cmd) error {
75
80
}))
76
81
err = errors .Join (err , provider .Load ("httprouter" , "main" , func (ctx context.Context , label string , config server.Plugin ) error {
77
82
httprouter := config .(* httprouter.Config )
78
- httprouter .Prefix = types .NormalisePath (app . GetEndpoint () .Path )
83
+ httprouter .Prefix = types .NormalisePath (endpoint .Path )
79
84
httprouter .Origin = "*"
80
85
httprouter .Middleware = []string {"log.main" }
81
86
return nil
82
87
}))
83
88
err = errors .Join (err , provider .Load ("httpserver" , "main" , func (ctx context.Context , label string , config server.Plugin ) error {
84
89
httpserver := config .(* httpserver.Config )
85
- httpserver .Listen = app . GetEndpoint ()
90
+ httpserver .Listen = endpoint
86
91
87
92
// Set router
88
93
if router , ok := provider .Task (ctx , "httprouter.main" ).(http.Handler ); ! ok || router == nil {
@@ -232,169 +237,3 @@ func (cmd *ServiceRunCommand) Run(app server.Cmd) error {
232
237
// Run the provider
233
238
return provider .Run (app .Context ())
234
239
}
235
-
236
- /*
237
- type ServiceRunCommand struct {
238
- Router struct {
239
- httprouter.Config `embed:"" prefix:"router."` // Router configuration
240
- } `embed:"" prefix:""`
241
- Server struct {
242
- httpserver.Config `embed:"" prefix:"server."` // Server configuration
243
- } `embed:""`
244
- Auth struct {
245
- auth.Config `embed:"" prefix:"auth."` // Auth configuration
246
- } `embed:""`
247
- PGPool struct {
248
- pg.Config `embed:"" prefix:"pg."` // Postgresql configuration
249
- } `embed:""`
250
- PGQueue struct {
251
- pgqueue.Config `embed:"" prefix:"pgqueue."` // Postgresql queue configuration
252
- } `embed:""`
253
- CertManager struct {
254
- cert.Config `embed:"" prefix:"cert."` // Certificate manager configuration
255
- } `embed:""`
256
- Log struct {
257
- logger.Config `embed:"" prefix:"log."` // Logger configuration
258
- } `embed:""`
259
- }
260
- */
261
-
262
- /*
263
- func (cmd *ServiceRunCommand) Run(app server.Cmd) error {
264
- // Set the server listener and router prefix
265
- cmd.Server.Listen = app.GetEndpoint()
266
- cmd.Router.Prefix = types.NormalisePath(cmd.Server.Listen.Path)
267
-
268
- // Create a provider and resolve references
269
- provider, err := provider.New(func(ctx context.Context, label string, plugin server.Plugin) (server.Plugin, error) {
270
- ref.Log(ctx).Debugf(ctx, "Resolving %q", label)
271
- switch label {
272
- case "log":
273
- config := plugin.(logger.Config)
274
- config.Debug = app.GetDebug() >= server.Debug
275
- return config, nil
276
-
277
- case "certmanager":
278
- config := plugin.(cert.Config)
279
-
280
- // Set the router
281
- if router, ok := ref.Provider(ctx).Task(ctx, "httprouter").(server.HTTPRouter); !ok || router == nil {
282
- return nil, httpresponse.ErrInternalError.Withf("Invalid router %q", "httprouter")
283
- } else {
284
- config.Router = router
285
- }
286
-
287
- // Set the connection pool
288
- if pool, ok := ref.Provider(ctx).Task(ctx, "pgpool").(server.PG); !ok || pool == nil {
289
- return nil, httpresponse.ErrInternalError.Withf("Invalid connection pool %q", "pgpool")
290
- } else {
291
- config.Pool = pool
292
- }
293
-
294
- // Set the queue
295
- if queue, ok := ref.Provider(ctx).Task(ctx, "pgqueue").(server.PGQueue); !ok || queue == nil {
296
- return nil, httpresponse.ErrInternalError.Withf("Invalid connection pool %q", "pgqueue")
297
- } else {
298
- config.Queue = queue
299
- }
300
-
301
- return config, nil
302
-
303
- case "httpserver":
304
- config := plugin.(httpserver.Config)
305
-
306
- // Set the router
307
- if router, ok := ref.Provider(ctx).Task(ctx, "httprouter").(http.Handler); !ok || router == nil {
308
- return nil, httpresponse.ErrInternalError.Withf("Invalid router %q", "httprouter")
309
- } else {
310
- config.Router = router
311
- }
312
-
313
- // Return the new configuration with the router
314
- return config, nil
315
-
316
- case "httprouter":
317
- config := plugin.(httprouter.Config)
318
-
319
- // Set the middleware
320
- config.Middleware = []string{}
321
-
322
- // Return the new configuration with the router
323
- return config, nil
324
-
325
- case "auth":
326
- config := plugin.(auth.Config)
327
-
328
- // Set the router
329
- if router, ok := ref.Provider(ctx).Task(ctx, "httprouter").(server.HTTPRouter); !ok || router == nil {
330
- return nil, httpresponse.ErrInternalError.Withf("Invalid router %q", "httprouter")
331
- } else {
332
- config.Router = router
333
- }
334
-
335
- // Set the connection pool
336
- if pool, ok := ref.Provider(ctx).Task(ctx, "pgpool").(server.PG); !ok || pool == nil {
337
- return nil, httpresponse.ErrInternalError.Withf("Invalid connection pool %q", "pgpool")
338
- } else {
339
- config.Pool = pool
340
- }
341
-
342
- // Return the new configuration
343
- return config, nil
344
-
345
- case "pgqueue":
346
- config := plugin.(pgqueue.Config)
347
-
348
- // Set the router
349
- if router, ok := ref.Provider(ctx).Task(ctx, "httprouter").(server.HTTPRouter); !ok || router == nil {
350
- return nil, httpresponse.ErrInternalError.Withf("Invalid router %q", "httprouter")
351
- } else {
352
- config.Router = router
353
- }
354
-
355
- // Set the connection pool
356
- if pool, ok := ref.Provider(ctx).Task(ctx, "pgpool").(server.PG); !ok || pool == nil {
357
- return nil, httpresponse.ErrInternalError.Withf("Invalid connection pool %q", "pgpool")
358
- } else {
359
- config.Pool = pool
360
- }
361
-
362
- // Return the new configuration
363
- return config, nil
364
-
365
- case "pgpool":
366
- config := plugin.(pg.Config)
367
-
368
- // Set the router
369
- if router, ok := ref.Provider(ctx).Task(ctx, "httprouter").(server.HTTPRouter); !ok || router == nil {
370
- return nil, httpresponse.ErrInternalError.Withf("Invalid router %q", "httprouter")
371
- } else {
372
- config.Router = router
373
- }
374
-
375
- // Set trace
376
- if app.GetDebug() == server.Trace {
377
- config.Trace = func(ctx context.Context, query string, args any, err error) {
378
- if err != nil {
379
- ref.Log(ctx).With("args", args).Print(ctx, err, " ON ", query)
380
- } else {
381
- ref.Log(ctx).With("args", args).Debug(ctx, query)
382
- }
383
- }
384
- }
385
-
386
- // Return the new configuration with the router
387
- return config, nil
388
- }
389
-
390
- // No-op
391
- return plugin, nil
392
- }, cmd.Log.Config, cmd.Router.Config, cmd.Server.Config, cmd.Auth.Config, cmd.PGPool.Config, cmd.PGQueue.Config, cmd.CertManager.Config)
393
- if err != nil {
394
- return err
395
- }
396
-
397
- // Run the provider
398
- return provider.Run(app.Context())
399
- }
400
- */
0 commit comments