@rivascva/dt-idl 1.1.47 → 1.1.48

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.
@@ -6,10 +6,6 @@ import (
6
6
  "net/http"
7
7
  )
8
8
 
9
- type Response struct {
10
- StatusCode int
11
- }
12
-
13
9
  // Makes a GET request to the given url.
14
10
  //
15
11
  // Parses the JSON-encoded response and stores the result into v.
@@ -0,0 +1,6 @@
1
+ package fetch
2
+
3
+ // Base fetch response struct.
4
+ type Response struct {
5
+ StatusCode int
6
+ }
@@ -17,21 +17,21 @@ type Logger interface {
17
17
  Fatal(v ...any)
18
18
  }
19
19
 
20
- type logger struct {
20
+ type ConsoleLogger struct {
21
21
  prefix string
22
22
  info *log.Logger
23
23
  warn *log.Logger
24
24
  error *log.Logger
25
25
  }
26
26
 
27
- // Creates a new logger.
28
- func NewLogger() Logger {
29
- return NewLoggerWithPrefix("")
27
+ // Creates a new console logger.
28
+ func NewConsoleLogger() *ConsoleLogger {
29
+ return NewConsoleLoggerWithPrefix("")
30
30
  }
31
31
 
32
32
  // Creates a new logger with a custom prefix.
33
- func NewLoggerWithPrefix(prefix string) Logger {
34
- return &logger{
33
+ func NewConsoleLoggerWithPrefix(prefix string) *ConsoleLogger {
34
+ return &ConsoleLogger{
35
35
  prefix: prefix,
36
36
  info: log.New(os.Stdout, "[INFO] ", log.LstdFlags),
37
37
  warn: log.New(os.Stdout, "[WARN] ", log.LstdFlags),
@@ -39,18 +39,18 @@ func NewLoggerWithPrefix(prefix string) Logger {
39
39
  }
40
40
  }
41
41
 
42
- func (l *logger) Info(v ...any) {
42
+ func (l *ConsoleLogger) Info(v ...any) {
43
43
  l.info.Println(l.prefix, fmt.Sprint(v...))
44
44
  }
45
45
 
46
- func (l *logger) Warn(v ...any) {
46
+ func (l *ConsoleLogger) Warn(v ...any) {
47
47
  l.warn.Println(l.prefix, fmt.Sprint(v...))
48
48
  }
49
49
 
50
- func (l *logger) Error(v ...any) {
50
+ func (l *ConsoleLogger) Error(v ...any) {
51
51
  l.error.Println(l.prefix, fmt.Sprint(v...))
52
52
  }
53
53
 
54
- func (l *logger) Fatal(v ...any) {
54
+ func (l *ConsoleLogger) Fatal(v ...any) {
55
55
  l.error.Fatal(l.prefix, fmt.Sprint(v...))
56
56
  }
@@ -14,13 +14,13 @@ type Responder[T any] interface {
14
14
  WriteErrorWithCode(w http.ResponseWriter, status int, code T, message string)
15
15
  }
16
16
 
17
- type responder[T any] struct {
17
+ type StandardResponder[T any] struct {
18
18
  log logger.Logger
19
19
  baseErrorCode T
20
20
  }
21
21
 
22
- func NewResponder[T any](log logger.Logger, baseErrorCode T) Responder[T] {
23
- return &responder[T]{
22
+ func NewStandardResponder[T any](log logger.Logger, baseErrorCode T) *StandardResponder[T] {
23
+ return &StandardResponder[T]{
24
24
  log: log,
25
25
  baseErrorCode: baseErrorCode,
26
26
  }
@@ -29,7 +29,7 @@ func NewResponder[T any](log logger.Logger, baseErrorCode T) Responder[T] {
29
29
  // Writes a JSON response to the given response writer.
30
30
  //
31
31
  // The given data is converted to JSON. An error response is written if the marshal fails.
32
- func (r *responder[T]) Write(w http.ResponseWriter, status int, data any) {
32
+ func (r *StandardResponder[T]) Write(w http.ResponseWriter, status int, data any) {
33
33
  // encode the given data object
34
34
  out, err := json.Marshal(data)
35
35
  if err != nil {
@@ -49,7 +49,7 @@ func (r *responder[T]) Write(w http.ResponseWriter, status int, data any) {
49
49
  // Writes a JSON error response to the given response writer.
50
50
  //
51
51
  // The response is based on the generated "api.Error" schema.
52
- func (r *responder[T]) WriteError(w http.ResponseWriter, status int, message string) {
52
+ func (r *StandardResponder[T]) WriteError(w http.ResponseWriter, status int, message string) {
53
53
  r.WriteErrorWithCode(w, status, r.baseErrorCode, message)
54
54
  }
55
55
 
@@ -58,7 +58,7 @@ func (r *responder[T]) WriteError(w http.ResponseWriter, status int, message str
58
58
  // The code is based on the generated "api.ErrorCode" enum.
59
59
  //
60
60
  // The response is based on the generated "api.Error" schema.
61
- func (r *responder[T]) WriteErrorWithCode(w http.ResponseWriter, status int, code T, message string) {
61
+ func (r *StandardResponder[T]) WriteErrorWithCode(w http.ResponseWriter, status int, code T, message string) {
62
62
  // encode an error object with the given message
63
63
  out, err := json.Marshal(Error[T]{
64
64
  Status: int64(status),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rivascva/dt-idl",
3
- "version": "1.1.47",
3
+ "version": "1.1.48",
4
4
  "description": "Dream Trade - Interface Definition Language",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",