-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
1374 lines (1300 loc) · 48 KB
/
init.go
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
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package wrapify
import (
"fmt"
"time"
"github.com/sivaosorg/unify4g"
)
// NewPagination creates a new instance of the `pagination` struct.
//
// This function initializes a `pagination` struct with its default values.
//
// Returns:
// - A pointer to a newly created `pagination` instance.
func NewPagination() *pagination {
p := &pagination{}
return p
}
// NewMeta creates a new instance of the `meta` struct.
//
// This function initializes a `meta` struct with its default values,
// including an empty `CustomFields` map.
//
// Returns:
// - A pointer to a newly created `meta` instance with initialized fields.
func NewMeta() *meta {
m := &meta{
customFields: map[string]interface{}{},
}
return m
}
// NewHeader creates a new instance of the `header` struct.
//
// This function initializes a `header` struct with its default values.
//
// Returns:
// - A pointer to a newly created `header` instance.
func NewHeader() *header {
h := &header{}
return h
}
// New creates a new instance of the `wrapper` struct.
//
// This function initializes a `wrapper` struct with its default values,
// including an empty map for the `Debug` field.
//
// Returns:
// - A pointer to a newly created `wrapper` instance with initialized fields.
func New() *wrapper {
w := &wrapper{
meta: NewMeta().
WithLocale("en_US"). // vi_VN, en_US
WithApiVersion("v0.0.1").
WithRequestedTime(time.Now()).
WithRequestID(unify4g.GenerateCryptoID()),
}
return w
}
// Json serializes the `wrapper` instance into a compact JSON string.
//
// This function uses the `unify4g.JsonN` utility to generate a JSON representation
// of the `wrapper` instance. The output is a compact JSON string with no additional
// whitespace or formatting.
//
// Returns:
// - A compact JSON string representation of the `wrapper` instance.
func (w *wrapper) Json() string {
return unify4g.JsonN(w.Respond())
}
// JsonPretty serializes the `wrapper` instance into a prettified JSON string.
//
// This function uses the `unify4g.JsonPrettyN` utility to generate a JSON representation
// of the `wrapper` instance. The output is a human-readable JSON string with
// proper indentation and formatting for better readability.
//
// Returns:
// - A prettified JSON string representation of the `wrapper` instance.
func (w *wrapper) JsonPretty() string {
return unify4g.JsonPrettyN(w.Respond())
}
// Json serializes the `pagination` instance into a compact JSON string.
//
// This function uses the `unify4g.JsonN` utility to generate a JSON representation
// of the `pagination` instance. The output is a compact JSON string with no additional
// whitespace or formatting, providing a minimalistic view of the pagination data.
//
// Returns:
// - A compact JSON string representation of the `pagination` instance.
func (p *pagination) Json() string {
return unify4g.JsonN(p.Respond())
}
// JsonPretty serializes the `pagination` instance into a prettified JSON string.
//
// This function uses the `unify4g.JsonPrettyN` utility to generate a JSON representation
// of the `pagination` instance. The output is a human-readable JSON string with
// proper indentation and formatting for better readability, which is helpful for
// inspecting pagination data during development or debugging.
//
// Returns:
// - A prettified JSON string representation of the `pagination` instance.
func (p *pagination) JsonPretty() string {
return unify4g.JsonPrettyN(p.Respond())
}
// Json serializes the `meta` instance into a compact JSON string.
//
// This function uses the `unify4g.JsonN` utility to create a compact JSON representation
// of the `meta` instance. The resulting string is formatted without additional whitespace,
// suitable for efficient storage or transmission of metadata.
//
// Returns:
// - A compact JSON string representation of the `meta` instance.
func (m *meta) Json() string {
return unify4g.JsonN(m.Respond())
}
// JsonPretty serializes the `meta` instance into a prettified JSON string.
//
// This function calls the `unify4g.JsonPrettyN` utility to produce a formatted, human-readable
// JSON string representation of the `meta` instance. The output is useful for debugging
// or inspecting metadata in a more structured format.
//
// Returns:
// - A prettified JSON string representation of the `meta` instance.
func (m *meta) JsonPretty() string {
return unify4g.JsonPrettyN(m.Respond())
}
// Json serializes the `header` instance into a compact JSON string.
//
// This function uses the `unify4g.JsonN` utility to create a compact JSON representation
// of the `header` instance. The resulting string contains only the key information, formatted
// with minimal whitespace, making it suitable for compact storage or transmission of header data.
//
// Returns:
// - A compact JSON string representation of the `header` instance.
func (h *header) Json() string {
return unify4g.JsonN(h.Respond())
}
// JsonPretty serializes the `header` instance into a prettified JSON string.
//
// This function uses the `unify4g.JsonPrettyN` utility to produce a formatted, human-readable
// JSON string representation of the `header` instance. The output is structured with indentation
// and newlines, making it ideal for inspecting header data in a clear, easy-to-read format, especially
// during debugging or development.
//
// Returns:
// - A prettified JSON string representation of the `header` instance, formatted for improved readability.
func (h *header) JsonPretty() string {
return unify4g.JsonPrettyN(h.Respond())
}
// WithPage sets the page number for the `pagination` instance.
//
// This function updates the `page` field of the `pagination` and
// returns the modified `pagination` instance to allow method chaining.
//
// Parameters:
// - `v`: An integer representing the page number to set.
//
// Returns:
// - A pointer to the modified `pagination` instance (enabling method chaining).
func (p *pagination) WithPage(v int) *pagination {
p.page = v
return p
}
// WithPerPage sets the number of items per page for the `pagination` instance.
//
// This function updates the `perPage` field of the `pagination` and
// returns the modified `pagination` instance to allow method chaining.
//
// Parameters:
// - `v`: An integer representing the number of items per page to set.
//
// Returns:
// - A pointer to the modified `pagination` instance (enabling method chaining).
func (p *pagination) WithPerPage(v int) *pagination {
p.perPage = v
return p
}
// WithTotalPages sets the total number of pages for the `pagination` instance.
//
// This function updates the `totalPages` field of the `pagination` and
// returns the modified `pagination` instance to allow method chaining.
//
// Parameters:
// - `v`: An integer representing the total number of pages to set.
//
// Returns:
// - A pointer to the modified `pagination` instance (enabling method chaining).
func (p *pagination) WithTotalPages(v int) *pagination {
p.totalPages = v
return p
}
// WithTotalItems sets the total number of items for the `pagination` instance.
//
// This function updates the `totalItems` field of the `pagination` and
// returns the modified `pagination` instance to allow method chaining.
//
// Parameters:
// - `v`: An integer representing the total number of items to set.
//
// Returns:
// - A pointer to the modified `pagination` instance (enabling method chaining).
func (p *pagination) WithTotalItems(v int) *pagination {
p.totalItems = v
return p
}
// WithIsLast sets whether this is the last page in the `pagination` instance.
//
// This function updates the `isLast` field of the `pagination` and
// returns the modified `pagination` instance to allow method chaining.
//
// Parameters:
// - `v`: A boolean value indicating whether this is the last page.
//
// Returns:
// - A pointer to the modified `pagination` instance (enabling method chaining).
func (p *pagination) WithIsLast(v bool) *pagination {
p.isLast = v
return p
}
// WithApiVersion sets the API version for the `meta` instance.
//
// This function updates the `apiVersion` field of the `meta` instance with the specified value
// and returns the updated `meta` instance for method chaining.
//
// Parameters:
// - `v`: A string representing the API version to set.
//
// Returns:
// - A pointer to the modified `meta` instance, enabling method chaining.
func (m *meta) WithApiVersion(v string) *meta {
m.apiVersion = v
return m
}
// WithApiVersionf sets the API version for the `meta` instance using a formatted string.
//
// This function constructs a formatted string for the API version using the provided `format` string
// and arguments (`args`). It then assigns the formatted value to the `apiVersion` field of the `meta` instance.
// The method supports method chaining by returning a pointer to the modified `meta` instance.
//
// Parameters:
// - format: A format string to construct the API version.
// - args: A variadic list of arguments to be interpolated into the format string.
//
// Returns:
// - A pointer to the modified `meta` instance, enabling method chaining.
func (m *meta) WithApiVersionf(format string, args ...interface{}) *meta {
return m.WithApiVersion(fmt.Sprintf(format, args...))
}
// WithRequestID sets the request ID for the `meta` instance.
//
// This function updates the `requestID` field of the `meta` instance with the specified value
// and returns the updated `meta` instance for method chaining.
//
// Parameters:
// - `v`: A string representing the request ID to set.
//
// Returns:
// - A pointer to the modified `meta` instance, enabling method chaining.
func (m *meta) WithRequestID(v string) *meta {
m.requestID = v
return m
}
// WithRequestIDf sets the request ID for the `meta` instance using a formatted string.
//
// This function constructs a formatted string for the request ID using the provided `format` string
// and arguments (`args`). It then assigns the formatted value to the `requestID` field of the `meta` instance.
// The method supports method chaining by returning a pointer to the modified `meta` instance.
//
// Parameters:
// - format: A format string to construct the request ID.
// - args: A variadic list of arguments to be interpolated into the format string.
//
// Returns:
// - A pointer to the modified `meta` instance, enabling method chaining.
func (m *meta) WithRequestIDf(format string, args ...interface{}) *meta {
return m.WithRequestID(fmt.Sprintf(format, args...))
}
// WithLocale sets the locale for the `meta` instance.
//
// This function updates the `locale` field of the `meta` instance with the specified value
// and returns the updated `meta` instance for method chaining.
//
// Parameters:
// - `v`: A string representing the locale to set.
//
// Returns:
// - A pointer to the modified `meta` instance, enabling method chaining.
func (m *meta) WithLocale(v string) *meta {
m.locale = v
return m
}
// WithRequestedTime sets the requested time for the `meta` instance.
//
// This function updates the `requestedTime` field of the `meta` instance with the specified value
// and returns the updated `meta` instance for method chaining.
//
// Parameters:
// - `v`: A `time.Time` object representing the requested time to set.
//
// Returns:
// - A pointer to the modified `meta` instance, enabling method chaining.
func (m *meta) WithRequestedTime(v time.Time) *meta {
m.requestedTime = v
return m
}
// WithCustomFields sets the custom fields for the `meta` instance.
//
// This function updates the `customFields` map of the `meta` instance with the provided values
// and returns the updated `meta` instance for method chaining.
//
// Parameters:
// - `values`: A map of string keys to interface{} values representing custom fields.
//
// Returns:
// - A pointer to the modified `meta` instance, enabling method chaining.
func (m *meta) WithCustomFields(values map[string]interface{}) *meta {
m.customFields = values
return m
}
// WithCustomFieldKV sets a specific custom field key-value pair for the `meta` instance.
//
// This function adds or updates a custom field in the `customFields` map of the `meta` instance.
// If the `customFields` map is empty, it is initialized first.
//
// Parameters:
// - `key`: A string representing the custom field key.
// - `value`: An interface{} representing the value to associate with the custom field key.
//
// Returns:
// - A pointer to the modified `meta` instance, enabling method chaining.
func (m *meta) WithCustomFieldKV(key string, value interface{}) *meta {
if !m.IsCustomFieldPresent() {
m.customFields = make(map[string]interface{})
}
m.customFields[key] = value
return m
}
// WithCustomFieldKVf sets a specific custom field key-value pair for the `meta` instance
// using a formatted value.
//
// This function creates a formatted string value using the provided `format` string and
// `args`. It then calls `WithCustomFieldKV` to add or update the custom field with the
// specified key and the formatted value. The modified `meta` instance is returned for
// method chaining.
//
// Parameters:
// - key: A string representing the key for the custom field.
// - format: A format string to construct the value.
// - args: A variadic list of arguments to be interpolated into the format string.
//
// Returns:
// - A pointer to the modified `meta` instance, enabling method chaining.
func (m *meta) WithCustomFieldKVf(key string, format string, args ...interface{}) *meta {
return m.WithCustomFieldKV(key, fmt.Sprintf(format, args...))
}
// WithCode sets the `code` field of the `header` instance.
//
// This function assigns the provided integer value to the `code` field of the `header`
// and returns the updated `header` instance, allowing for method chaining.
//
// Parameters:
// - `v`: The integer value to set as the HTTP status code.
//
// Returns:
// - The updated `header` instance with the `code` field set to the provided value.
func (h *header) WithCode(v int) *header {
h.code = v
return h
}
// WithText sets the `text` field of the `header` instance.
//
// This function assigns the provided string value to the `text` field of the `header`
// and returns the updated `header` instance, allowing for method chaining.
//
// Parameters:
// - `v`: The string value to set as the text message.
//
// Returns:
// - The updated `header` instance with the `text` field set to the provided value.
func (h *header) WithText(v string) *header {
h.text = v
return h
}
// WithType sets the `Type` field of the `header` instance.
//
// This function assigns the provided string value to the `Type` field of the `header`
// and returns the updated `header` instance, allowing for method chaining.
//
// Parameters:
// - `v`: The string value to set as the type of the header.
//
// Returns:
// - The updated `header` instance with the `Type` field set to the provided value.
func (h *header) WithType(v string) *header {
h.typez = v
return h
}
// WithDescription sets the `description` field of the `header` instance.
//
// This function assigns the provided string value to the `description` field of the `header`
// and returns the updated `header` instance, allowing for method chaining.
//
// Parameters:
// - `v`: The string value to set as the description of the header.
//
// Returns:
// - The updated `header` instance with the `description` field set to the provided value.
func (h *header) WithDescription(v string) *header {
h.description = v
return h
}
// WithStatusCode sets the HTTP status code for the `wrapper` instance.
//
// This function updates the `statusCode` field of the `wrapper` and
// returns the modified `wrapper` instance to allow method chaining.
//
// Parameters:
// - `code`: An integer representing the HTTP status code to set.
//
// Returns:
// - A pointer to the modified `wrapper` instance (enabling method chaining).
func (w *wrapper) WithStatusCode(code int) *wrapper {
w.statusCode = code
return w
}
// WithTotal sets the total number of items for the `wrapper` instance.
//
// This function updates the `total` field of the `wrapper` and
// returns the modified `wrapper` instance to allow method chaining.
//
// Parameters:
// - `total`: An integer representing the total number of items to set.
//
// Returns:
// - A pointer to the modified `wrapper` instance (enabling method chaining).
func (w *wrapper) WithTotal(total int) *wrapper {
w.total = total
return w
}
// WithMessage sets a message for the `wrapper` instance.
//
// This function updates the `message` field of the `wrapper` with the provided string
// and returns the modified `wrapper` instance to allow method chaining.
//
// Parameters:
// - `message`: A string message to be set in the `wrapper`.
//
// Returns:
// - A pointer to the modified `wrapper` instance (enabling method chaining).
func (w *wrapper) WithMessage(message string) *wrapper {
w.message = message
return w
}
// WithMessagef sets a formatted message for the `wrapper` instance.
//
// This function constructs a formatted string using the provided format string and arguments,
// assigns it to the `message` field of the `wrapper`, and returns the modified instance.
//
// Parameters:
// - message: A format string for constructing the message.
// - args: A variadic list of arguments to be interpolated into the format string.
//
// Returns:
// - A pointer to the modified `wrapper` instance, enabling method chaining.
func (w *wrapper) WithMessagef(message string, args ...interface{}) *wrapper {
w.message = fmt.Sprintf(message, args...)
return w
}
// WithBody sets the body data for the `wrapper` instance.
//
// This function updates the `data` field of the `wrapper` with the provided value
// and returns the modified `wrapper` instance to allow method chaining.
//
// Parameters:
// - `v`: The value to be set as the body data, which can be any type.
//
// Returns:
// - A pointer to the modified `wrapper` instance (enabling method chaining).
func (w *wrapper) WithBody(v interface{}) *wrapper {
w.data = v
return w
}
// WithPath sets the request path for the `wrapper` instance.
//
// This function updates the `path` field of the `wrapper` with the provided string
// and returns the modified `wrapper` instance to allow method chaining.
//
// Parameters:
// - `v`: A string representing the request path.
//
// Returns:
// - A pointer to the modified `wrapper` instance (enabling method chaining).
func (w *wrapper) WithPath(v string) *wrapper {
w.path = v
return w
}
// WithPathf sets a formatted request path for the `wrapper` instance.
//
// This function constructs a formatted string using the provided format string `v` and arguments `args`,
// assigns the resulting string to the `path` field of the `wrapper`, and returns the modified instance.
//
// Parameters:
// - v: A format string for constructing the request path.
// - args: A variadic list of arguments to be interpolated into the format string.
//
// Returns:
// - A pointer to the modified `wrapper` instance, enabling method chaining.
func (w *wrapper) WithPathf(v string, args ...interface{}) *wrapper {
w.path = fmt.Sprintf(v, args...)
return w
}
// WithHeader sets the header for the `wrapper` instance.
//
// This function updates the `header` field of the `wrapper` with the provided `header`
// instance and returns the modified `wrapper` instance to allow method chaining.
//
// Parameters:
// - `v`: A pointer to a `header` struct that will be set in the `wrapper`.
//
// Returns:
// - A pointer to the modified `wrapper` instance (enabling method chaining).
func (w *wrapper) WithHeader(v *header) *wrapper {
w.header = v
w.WithStatusCode(w.Header().Code())
return w
}
// WithMeta sets the metadata for the `wrapper` instance.
//
// This function updates the `meta` field of the `wrapper` with the provided `meta`
// instance and returns the modified `wrapper` instance to allow method chaining.
//
// Parameters:
// - `v`: A pointer to a `meta` struct that will be set in the `wrapper`.
//
// Returns:
// - A pointer to the modified `wrapper` instance (enabling method chaining).
func (w *wrapper) WithMeta(v *meta) *wrapper {
w.meta = v
return w
}
// WithPagination sets the pagination information for the `wrapper` instance.
//
// This function updates the `pagination` field of the `wrapper` with the provided `pagination`
// instance and returns the modified `wrapper` instance to allow method chaining.
//
// Parameters:
// - `v`: A pointer to a `pagination` struct that will be set in the `wrapper`.
//
// Returns:
// - A pointer to the modified `wrapper` instance (enabling method chaining).
func (w *wrapper) WithPagination(v *pagination) *wrapper {
w.pagination = v
return w
}
// WithDebugging sets the debugging information for the `wrapper` instance.
//
// This function updates the `debug` field of the `wrapper` with the provided map of debugging data
// and returns the modified `wrapper` instance to allow method chaining.
//
// Parameters:
// - `v`: A map containing debugging information to be set in the `wrapper`.
//
// Returns:
// - A pointer to the modified `wrapper` instance (enabling method chaining).
func (w *wrapper) WithDebugging(v map[string]interface{}) *wrapper {
w.debug = v
return w
}
// WithError sets an error for the `wrapper` instance.
//
// This function updates the `errors` field of the `wrapper` with the provided error
// and returns the modified `wrapper` instance to allow method chaining.
//
// Parameters:
// - `err`: An error object to be set in the `wrapper`.
//
// Returns:
// - A pointer to the modified `wrapper` instance (enabling method chaining).
// func (w *wrapper) WithError(err error) *wrapper {
// w.errors = err
// return w
// }
// WithError sets an error for the `wrapper` instance using a plain error message.
//
// This function creates an error object from the provided message, assigns it to
// the `errors` field of the `wrapper`, and returns the modified instance.
//
// Parameters:
// - message: A string containing the error message to be wrapped as an error object.
//
// Returns:
// - A pointer to the modified `wrapper` instance to support method chaining.
func (w *wrapper) WithError(message string) *wrapper {
w.errors = WithError(message)
return w
}
// WithErrorf sets a formatted error for the `wrapper` instance.
//
// This function uses a formatted string and arguments to construct an error object,
// assigns it to the `errors` field of the `wrapper`, and returns the modified instance.
//
// Parameters:
// - format: A format string for constructing the error message.
// - args: A variadic list of arguments to be interpolated into the format string.
//
// Returns:
// - A pointer to the modified `wrapper` instance to support method chaining.
func (w *wrapper) WithErrorf(format string, args ...interface{}) *wrapper {
w.errors = WithErrorf(format, args...)
return w
}
// WithErrSck sets an error with a stack trace for the `wrapper` instance.
//
// This function wraps the provided error with stack trace information, assigns it
// to the `errors` field of the `wrapper`, and returns the modified instance.
//
// Parameters:
// - err: The error object to be wrapped with stack trace information.
//
// Returns:
// - A pointer to the modified `wrapper` instance to support method chaining.
func (w *wrapper) WithErrSck(err error) *wrapper {
w.errors = WithErrStack(err)
return w
}
// WithErrWrap wraps an existing error with an additional message and sets it for the `wrapper` instance.
//
// This function adds context to the provided error by wrapping it with an additional message.
// The resulting error is assigned to the `errors` field of the `wrapper`.
//
// Parameters:
// - err: The original error to be wrapped.
// - message: A string message to add context to the error.
//
// Returns:
// - A pointer to the modified `wrapper` instance to support method chaining.
func (w *wrapper) WithErrWrap(err error, message string) *wrapper {
w.errors = WithErrWrap(err, message)
return w
}
// WithErrWrapf wraps an existing error with a formatted message and sets it for the `wrapper` instance.
//
// This function adds context to the provided error by wrapping it with a formatted message.
// The resulting error is assigned to the `errors` field of the `wrapper`.
//
// Parameters:
// - err: The original error to be wrapped.
// - format: A format string for constructing the contextual error message.
// - args: A variadic list of arguments to be interpolated into the format string.
//
// Returns:
// - A pointer to the modified `wrapper` instance to support method chaining.
func (w *wrapper) WithErrWrapf(err error, format string, args ...interface{}) *wrapper {
w.errors = WithErrWrapf(err, format, args...)
return w
}
// WithErrMessage adds a plain contextual message to an existing error and sets it for the `wrapper` instance.
//
// This function wraps the provided error with an additional plain message and assigns it
// to the `errors` field of the `wrapper`.
//
// Parameters:
// - err: The original error to be wrapped.
// - message: A plain string message to add context to the error.
//
// Returns:
// - A pointer to the modified `wrapper` instance to support method chaining.
func (w *wrapper) WithErrMessage(err error, message string) *wrapper {
w.errors = WithMessage(err, message)
return w
}
// WithErrMessagef adds a formatted contextual message to an existing error and sets it for the `wrapper` instance.
//
// This function wraps the provided error with an additional formatted message and assigns it
// to the `errors` field of the `wrapper`.
//
// Parameters:
// - err: The original error to be wrapped.
// - format: A format string for constructing the contextual error message.
// - args: A variadic list of arguments to be interpolated into the format string.
//
// Returns:
// - A pointer to the modified `wrapper` instance to support method chaining.
func (w *wrapper) WithErrMessagef(err error, format string, args ...interface{}) *wrapper {
w.errors = WithMessagef(err, format, args...)
return w
}
// WithDebuggingKV adds a key-value pair to the debugging information in the `wrapper` instance.
//
// This function checks if debugging information is already present. If it is not, it initializes
// an empty map. Then it adds the given key-value pair to the `debug` map and returns the modified
// `wrapper` instance to allow method chaining.
//
// Parameters:
// - `key`: The key for the debugging information to be added.
// - `value`: The value associated with the key to be added to the `debug` map.
//
// Returns:
// - A pointer to the modified `wrapper` instance (enabling method chaining).
func (w *wrapper) WithDebuggingKV(key string, value interface{}) *wrapper {
if !w.IsDebuggingPresent() {
w.debug = make(map[string]interface{})
}
w.debug[key] = value
return w
}
// WithDebuggingKVf adds a formatted key-value pair to the debugging information in the `wrapper` instance.
//
// This function creates a formatted string value using the provided `format` string and `args`,
// then delegates to `WithDebuggingKV` to add the resulting key-value pair to the `debug` map.
// It returns the modified `wrapper` instance for method chaining.
//
// Parameters:
// - key: A string representing the key for the debugging information.
// - format: A format string for constructing the value.
// - args: A variadic list of arguments to be interpolated into the format string.
//
// Returns:
// - A pointer to the modified `wrapper` instance, enabling method chaining.
func (w *wrapper) WithDebuggingKVf(key string, format string, args ...interface{}) *wrapper {
return w.WithDebuggingKV(key, fmt.Sprintf(format, args...))
}
// WithApiVersion sets the API version in the `meta` field of the `wrapper` instance.
//
// This function checks if the `meta` information is present in the `wrapper`. If it is not,
// a new `meta` instance is created. Then, it calls the `WithApiVersion` method on the `meta`
// instance to set the API version.
//
// Parameters:
// - `v`: A string representing the API version to set.
//
// Returns:
// - A pointer to the modified `wrapper` instance (enabling method chaining).
func (w *wrapper) WithApiVersion(v string) *wrapper {
if !w.IsMetaPresent() {
w.meta = NewMeta()
}
w.meta.WithApiVersion(v)
return w
}
// WithApiVersionf sets the API version in the `meta` field of the `wrapper` instance using a formatted string.
//
// This function ensures that the `meta` field in the `wrapper` is initialized. If the `meta`
// field is not present, a new `meta` instance is created using the `NewMeta` function.
// Once the `meta` instance is ready, it updates the API version using the `WithApiVersionf` method
// on the `meta` instance. The API version is constructed by interpolating the provided `format`
// string with the variadic arguments (`args`).
//
// Parameters:
// - format: A format string used to construct the API version.
// - args: A variadic list of arguments to be interpolated into the format string.
//
// Returns:
// - A pointer to the modified `wrapper` instance, enabling method chaining.
func (w *wrapper) WithApiVersionf(format string, args ...interface{}) *wrapper {
if !w.IsMetaPresent() {
w.meta = NewMeta()
}
w.meta.WithApiVersionf(format, args...)
return w
}
// WithRequestID sets the request ID in the `meta` field of the `wrapper` instance.
//
// This function ensures that if `meta` information is not already set in the `wrapper`, a new
// `meta` instance is created. Then, it calls the `WithRequestID` method on the `meta` instance
// to set the request ID.
//
// Parameters:
// - `v`: A string representing the request ID to set.
//
// Returns:
// - A pointer to the modified `wrapper` instance (enabling method chaining).
func (w *wrapper) WithRequestID(v string) *wrapper {
if !w.IsMetaPresent() {
w.meta = NewMeta()
}
w.meta.WithRequestID(v)
return w
}
// WithRequestIDf sets the request ID in the `meta` field of the `wrapper` instance using a formatted string.
//
// This function ensures that the `meta` field in the `wrapper` is initialized. If the `meta` field
// is not already present, a new `meta` instance is created using the `NewMeta` function.
// Once the `meta` instance is ready, it updates the request ID by calling the `WithRequestIDf`
// method on the `meta` instance. The request ID is constructed using the provided `format` string
// and the variadic `args`.
//
// Parameters:
// - format: A format string used to construct the request ID.
// - args: A variadic list of arguments to be interpolated into the format string.
//
// Returns:
// - A pointer to the modified `wrapper` instance, allowing for method chaining.
func (w *wrapper) WithRequestIDf(format string, args ...interface{}) *wrapper {
if !w.IsMetaPresent() {
w.meta = NewMeta()
}
w.meta.WithRequestIDf(format, args...)
return w
}
// WithLocale sets the locale in the `meta` field of the `wrapper` instance.
//
// This function ensures the `meta` field is present, creating a new instance if needed, and
// sets the locale in the `meta` using the `WithLocale` method.
//
// Parameters:
// - `v`: A string representing the locale to set.
//
// Returns:
// - A pointer to the modified `wrapper` instance (enabling method chaining).
func (w *wrapper) WithLocale(v string) *wrapper {
if !w.IsMetaPresent() {
w.meta = NewMeta()
}
w.meta.WithLocale(v)
return w
}
// WithRequestedTime sets the requested time in the `meta` field of the `wrapper` instance.
//
// This function ensures that the `meta` field exists, and if not, creates a new one. It then
// sets the requested time in the `meta` using the `WithRequestedTime` method.
//
// Parameters:
// - `v`: A `time.Time` value representing the requested time.
//
// Returns:
// - A pointer to the modified `wrapper` instance (enabling method chaining).
func (w *wrapper) WithRequestedTime(v time.Time) *wrapper {
if !w.IsMetaPresent() {
w.meta = NewMeta()
}
w.meta.WithRequestedTime(v)
return w
}
// WithCustomFields sets the custom fields in the `meta` field of the `wrapper` instance.
//
// This function checks if the `meta` field is present. If not, it creates a new `meta` instance
// and sets the provided custom fields using the `WithCustomFields` method.
//
// Parameters:
// - `values`: A map representing the custom fields to set in the `meta`.
//
// Returns:
// - A pointer to the modified `wrapper` instance (enabling method chaining).
func (w *wrapper) WithCustomFields(values map[string]interface{}) *wrapper {
if !w.IsMetaPresent() {
w.meta = NewMeta()
}
w.meta.WithCustomFields(values)
return w
}
// WithCustomFieldKV sets a specific custom field key-value pair in the `meta` field of the `wrapper` instance.
//
// This function ensures that if the `meta` field is not already set, a new `meta` instance is created.
// It then adds the provided key-value pair to the custom fields of `meta` using the `WithCustomFieldKV` method.
//
// Parameters:
// - `key`: A string representing the custom field key to set.
// - `value`: The value associated with the custom field key.
//
// Returns:
// - A pointer to the modified `wrapper` instance (enabling method chaining).
func (w *wrapper) WithCustomFieldKV(key string, value interface{}) *wrapper {
if !w.IsMetaPresent() {
w.meta = NewMeta()
}
w.meta.WithCustomFieldKV(key, value)
return w
}
// WithCustomFieldKVf sets a specific custom field key-value pair in the `meta` field of the `wrapper` instance
// using a formatted value.
//
// This function constructs a formatted string value using the provided `format` string and arguments (`args`).
// It then calls the `WithCustomFieldKV` method to add or update the custom field with the specified key and
// the formatted value. If the `meta` field of the `wrapper` instance is not initialized, it is created
// before setting the custom field.
//
// Parameters:
// - key: A string representing the key for the custom field.
// - format: A format string to construct the value.
// - args: A variadic list of arguments to be interpolated into the format string.
//
// Returns:
// - A pointer to the modified `wrapper` instance, enabling method chaining.
func (w *wrapper) WithCustomFieldKVf(key string, format string, args ...interface{}) *wrapper {
if !w.IsMetaPresent() {
w.meta = NewMeta()
}
w.meta.WithCustomFieldKVf(key, format, args...)
return w
}
// WithPage sets the current page number in the wrapper's pagination.
//
// If the pagination object is not already initialized, it creates a new one
// using the `NewPagination` function. The specified page number is then
// applied to the pagination instance.
//
// Parameters:
// - v: The page number to set.
//
// Returns:
// - A pointer to the updated `wrapper` instance.
func (w *wrapper) WithPage(v int) *wrapper {
if !w.IsPagingPresent() {
w.pagination = NewPagination()
}
w.pagination.WithPage(v)
return w
}
// WithPerPage sets the number of items per page in the wrapper's pagination.
//
// If the pagination object is not already initialized, it creates a new one
// using the `NewPagination` function. The specified items-per-page value
// is then applied to the pagination instance.
//
// Parameters:
// - v: The number of items per page to set.
//
// Returns:
// - A pointer to the updated `wrapper` instance.
func (w *wrapper) WithPerPage(v int) *wrapper {
if !w.IsPagingPresent() {
w.pagination = NewPagination()
}
w.pagination.WithPerPage(v)
return w
}
// WithTotalPages sets the total number of pages in the wrapper's pagination.
//
// If the pagination object is not already initialized, it creates a new one
// using the `NewPagination` function. The specified total pages value
// is then applied to the pagination instance.
//
// Parameters:
// - v: The total number of pages to set.
//
// Returns:
// - A pointer to the updated `wrapper` instance.