Skip to content

Commit 3384f7e

Browse files
authored
feat(fxhttpserver): Provided module (ankorstore#42)
1 parent eb89939 commit 3384f7e

File tree

3 files changed

+40
-26
lines changed

3 files changed

+40
-26
lines changed

fxhttpserver/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ func TestSomeHandler(t *testing.T) {
648648
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
649649
"level": "info",
650650
"service": "test",
651-
"system": "fx-httpserver",
651+
"module": "httpserver",
652652
"method": "GET",
653653
"uri": "/test",
654654
"status": 200,
@@ -667,15 +667,15 @@ func TestSomeHandler(t *testing.T) {
667667
668668
// assertion on the metrics registry
669669
expectedMetric := `
670-
# HELP app_fx_httpserver_requests_total Number of processed HTTP requests
671-
# TYPE app_fx_httpserver_requests_total counter
672-
app_fx_httpserver_requests_total{handler="/test",method="GET",status="2xx"} 1
670+
# HELP app_httpserver_requests_total Number of processed HTTP requests
671+
# TYPE app_httpserver_requests_total counter
672+
app_httpserver_requests_total{handler="/test",method="GET",status="2xx"} 1
673673
`
674674
675675
err := testutil.GatherAndCompare(
676676
metricsRegistry,
677677
strings.NewReader(expectedMetric),
678-
"app_fx_httpserver_requests_total",
678+
"app_httpserver_requests_total",
679679
)
680680
assert.NoError(t, err)
681681
}

fxhttpserver/module.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
)
1919

2020
const (
21-
ModuleName = "fx-httpserver"
21+
ModuleName = "httpserver"
2222
DefaultPort = 8080
2323
)
2424

@@ -58,7 +58,7 @@ func NewFxHttpServer(p FxHttpServerParam) (*echo.Echo, error) {
5858

5959
// logger
6060
echoLogger := httpserver.NewEchoLogger(
61-
log.FromZerolog(p.Logger.ToZerolog().With().Str("system", ModuleName).Logger()),
61+
log.FromZerolog(p.Logger.ToZerolog().With().Str("module", ModuleName).Logger()),
6262
)
6363

6464
// renderer

fxhttpserver/module_test.go

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func TestModuleWithAutowiredResources(t *testing.T) {
123123
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
124124
"level": "info",
125125
"service": "test",
126-
"system": "fx-httpserver",
126+
"module": "httpserver",
127127
"requestID": testRequestId,
128128
"traceID": testTraceId,
129129
"foo": "foo",
@@ -133,7 +133,7 @@ func TestModuleWithAutowiredResources(t *testing.T) {
133133
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
134134
"level": "info",
135135
"service": "test",
136-
"system": "fx-httpserver",
136+
"module": "httpserver",
137137
"requestID": testRequestId,
138138
"traceID": testTraceId,
139139
"foo": "foo",
@@ -143,7 +143,7 @@ func TestModuleWithAutowiredResources(t *testing.T) {
143143
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
144144
"level": "info",
145145
"service": "test",
146-
"system": "fx-httpserver",
146+
"module": "httpserver",
147147
"requestID": testRequestId,
148148
"traceID": testTraceId,
149149
"foo": "foo",
@@ -153,7 +153,7 @@ func TestModuleWithAutowiredResources(t *testing.T) {
153153
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
154154
"level": "info",
155155
"service": "test",
156-
"system": "fx-httpserver",
156+
"module": "httpserver",
157157
"method": "GET",
158158
"uri": "/bar",
159159
"status": 200,
@@ -198,7 +198,7 @@ func TestModuleWithAutowiredResources(t *testing.T) {
198198
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
199199
"level": "info",
200200
"service": "test",
201-
"system": "fx-httpserver",
201+
"module": "httpserver",
202202
"requestID": testRequestId,
203203
"traceID": testTraceId,
204204
"foo": "foo",
@@ -208,7 +208,7 @@ func TestModuleWithAutowiredResources(t *testing.T) {
208208
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
209209
"level": "info",
210210
"service": "test",
211-
"system": "fx-httpserver",
211+
"module": "httpserver",
212212
"requestID": testRequestId,
213213
"traceID": testTraceId,
214214
"foo": "foo",
@@ -218,7 +218,7 @@ func TestModuleWithAutowiredResources(t *testing.T) {
218218
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
219219
"level": "info",
220220
"service": "test",
221-
"system": "fx-httpserver",
221+
"module": "httpserver",
222222
"requestID": testRequestId,
223223
"traceID": testTraceId,
224224
"foo": "foo",
@@ -228,7 +228,7 @@ func TestModuleWithAutowiredResources(t *testing.T) {
228228
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
229229
"level": "info",
230230
"service": "test",
231-
"system": "fx-httpserver",
231+
"module": "httpserver",
232232
"method": "GET",
233233
"uri": "/baz",
234234
"status": 200,
@@ -273,7 +273,7 @@ func TestModuleWithAutowiredResources(t *testing.T) {
273273
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
274274
"level": "info",
275275
"service": "test",
276-
"system": "fx-httpserver",
276+
"module": "httpserver",
277277
"requestID": testRequestId,
278278
"traceID": testTraceId,
279279
"foo": "foo",
@@ -283,7 +283,7 @@ func TestModuleWithAutowiredResources(t *testing.T) {
283283
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
284284
"level": "info",
285285
"service": "test",
286-
"system": "fx-httpserver",
286+
"module": "httpserver",
287287
"requestID": testRequestId,
288288
"traceID": testTraceId,
289289
"foo": "foo",
@@ -293,7 +293,7 @@ func TestModuleWithAutowiredResources(t *testing.T) {
293293
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
294294
"level": "info",
295295
"service": "test",
296-
"system": "fx-httpserver",
296+
"module": "httpserver",
297297
"requestID": testRequestId,
298298
"traceID": testTraceId,
299299
"foo": "foo",
@@ -303,7 +303,7 @@ func TestModuleWithAutowiredResources(t *testing.T) {
303303
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
304304
"level": "info",
305305
"service": "test",
306-
"system": "fx-httpserver",
306+
"module": "httpserver",
307307
"requestID": testRequestId,
308308
"traceID": testTraceId,
309309
"foo": "foo",
@@ -313,7 +313,7 @@ func TestModuleWithAutowiredResources(t *testing.T) {
313313
logtest.AssertHasNotLogRecord(t, logBuffer, map[string]interface{}{
314314
"level": "info",
315315
"service": "test",
316-
"system": "fx-httpserver",
316+
"module": "httpserver",
317317
"method": "GET",
318318
"uri": "/foo/bar",
319319
"status": 200,
@@ -359,7 +359,7 @@ func TestModuleWithAutowiredResources(t *testing.T) {
359359
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
360360
"level": "info",
361361
"service": "test",
362-
"system": "fx-httpserver",
362+
"module": "httpserver",
363363
"requestID": testRequestId,
364364
"traceID": testTraceId,
365365
"foo": "foo",
@@ -369,7 +369,7 @@ func TestModuleWithAutowiredResources(t *testing.T) {
369369
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
370370
"level": "info",
371371
"service": "test",
372-
"system": "fx-httpserver",
372+
"module": "httpserver",
373373
"requestID": testRequestId,
374374
"traceID": testTraceId,
375375
"foo": "foo",
@@ -379,7 +379,7 @@ func TestModuleWithAutowiredResources(t *testing.T) {
379379
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
380380
"level": "info",
381381
"service": "test",
382-
"system": "fx-httpserver",
382+
"module": "httpserver",
383383
"requestID": testRequestId,
384384
"traceID": testTraceId,
385385
"foo": "foo",
@@ -389,7 +389,7 @@ func TestModuleWithAutowiredResources(t *testing.T) {
389389
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
390390
"level": "info",
391391
"service": "test",
392-
"system": "fx-httpserver",
392+
"module": "httpserver",
393393
"requestID": testRequestId,
394394
"traceID": testTraceId,
395395
"foo": "foo",
@@ -399,7 +399,7 @@ func TestModuleWithAutowiredResources(t *testing.T) {
399399
logtest.AssertHasNotLogRecord(t, logBuffer, map[string]interface{}{
400400
"level": "info",
401401
"service": "test",
402-
"system": "fx-httpserver",
402+
"module": "httpserver",
403403
"method": "GET",
404404
"uri": "/foo/baz",
405405
"status": 200,
@@ -439,7 +439,7 @@ func TestModuleWithAutowiredResources(t *testing.T) {
439439
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
440440
"level": "warn",
441441
"service": "test",
442-
"system": "fx-httpserver",
442+
"module": "httpserver",
443443
"method": "GET",
444444
"uri": "/invalid",
445445
"status": 404,
@@ -503,27 +503,31 @@ func TestModuleWithConcreteResources(t *testing.T) {
503503
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
504504
"level": "info",
505505
"service": "test",
506+
"module": "httpserver",
506507
"requestID": testRequestId,
507508
"traceID": testTraceId,
508509
"message": "CONCRETE GLOBAL middleware",
509510
})
510511
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
511512
"level": "info",
512513
"service": "test",
514+
"module": "httpserver",
513515
"requestID": testRequestId,
514516
"traceID": testTraceId,
515517
"message": "CONCRETE HANDLER middleware",
516518
})
517519
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
518520
"level": "info",
519521
"service": "test",
522+
"module": "httpserver",
520523
"requestID": testRequestId,
521524
"traceID": testTraceId,
522525
"message": "in concrete handler",
523526
})
524527
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
525528
"level": "info",
526529
"service": "test",
530+
"module": "httpserver",
527531
"method": "GET",
528532
"uri": "/concrete",
529533
"status": 200,
@@ -555,34 +559,39 @@ func TestModuleWithConcreteResources(t *testing.T) {
555559
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
556560
"level": "info",
557561
"service": "test",
562+
"module": "httpserver",
558563
"requestID": testRequestId,
559564
"traceID": testTraceId,
560565
"message": "CONCRETE GLOBAL middleware",
561566
})
562567
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
563568
"level": "info",
564569
"service": "test",
570+
"module": "httpserver",
565571
"requestID": testRequestId,
566572
"traceID": testTraceId,
567573
"message": "CONCRETE GROUP middleware",
568574
})
569575
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
570576
"level": "info",
571577
"service": "test",
578+
"module": "httpserver",
572579
"requestID": testRequestId,
573580
"traceID": testTraceId,
574581
"message": "CONCRETE HANDLER middleware",
575582
})
576583
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
577584
"level": "info",
578585
"service": "test",
586+
"module": "httpserver",
579587
"requestID": testRequestId,
580588
"traceID": testTraceId,
581589
"message": "in concrete handler",
582590
})
583591
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
584592
"level": "info",
585593
"service": "test",
594+
"module": "httpserver",
586595
"method": "GET",
587596
"uri": "/group/concrete",
588597
"status": 200,
@@ -613,6 +622,7 @@ func TestModuleWithConcreteResources(t *testing.T) {
613622
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
614623
"level": "warn",
615624
"service": "test",
625+
"module": "httpserver",
616626
"method": "GET",
617627
"uri": "/invalid",
618628
"error": "code=404, message=Not Found",
@@ -726,12 +736,14 @@ func TestModuleWithMetrics(t *testing.T) {
726736
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
727737
"level": "info",
728738
"service": "test",
739+
"module": "httpserver",
729740
"message": "in bar handler",
730741
})
731742

732743
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
733744
"level": "info",
734745
"service": "test",
746+
"module": "httpserver",
735747
"method": "GET",
736748
"uri": "/bar",
737749
"status": 200,
@@ -800,12 +812,14 @@ func TestModuleWithTemplates(t *testing.T) {
800812
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
801813
"level": "info",
802814
"service": "test",
815+
"module": "httpserver",
803816
"message": "in template handler",
804817
})
805818

806819
logtest.AssertHasLogRecord(t, logBuffer, map[string]interface{}{
807820
"level": "info",
808821
"service": "test",
822+
"module": "httpserver",
809823
"method": "GET",
810824
"uri": "/template",
811825
"status": 200,

0 commit comments

Comments
 (0)