Skip to content

Commit a6dfe1a

Browse files
committed
added MESSAGE_ALIASES to ENV
1 parent ceb4bb4 commit a6dfe1a

File tree

3 files changed

+60
-44
lines changed

3 files changed

+60
-44
lines changed

internals/proxy/middlewares/log.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func (data LogMiddleware) Use() http.Handler {
1414
next := data.Next
1515

1616
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
17-
log.Info("Request:", req.Method, req.URL.Path)
17+
log.Info(req.Method, req.URL.Path, "?", req.URL.RawQuery)
1818

1919
next.ServeHTTP(w, req)
2020
})

main.go

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,44 +28,7 @@ func main() {
2828

2929
body_m4 := BodyMiddleware{
3030
Next: initHandler,
31-
MessageAliases: []MessageAlias{
32-
{
33-
Alias: "msg",
34-
Priority: 100,
35-
},
36-
{
37-
Alias: "content",
38-
Priority: 99,
39-
},
40-
{
41-
Alias: "description",
42-
Priority: 98,
43-
},
44-
{
45-
Alias: "text",
46-
Priority: 20,
47-
},
48-
{
49-
Alias: "body",
50-
Priority: 15,
51-
},
52-
{
53-
Alias: "summary",
54-
Priority: 10,
55-
},
56-
{
57-
Alias: "details",
58-
Priority: 9,
59-
},
60-
{
61-
Alias: "payload",
62-
Priority: 2,
63-
},
64-
{
65-
Alias: "data",
66-
Priority: 1,
67-
},
68-
},
31+
MessageAliases: ENV.MESSAGE_ALIASES,
6932
}
7033

7134
temp_m3 := TemplateMiddleware{

utils/env/env.go

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ import (
44
"encoding/json"
55
"os"
66

7+
middlewares "github.com/codeshelldev/secured-signal-api/internals/proxy/middlewares"
78
log "github.com/codeshelldev/secured-signal-api/utils/logger"
89
)
910

1011
type ENV_ struct {
11-
PORT string
12-
API_URL string
13-
API_TOKEN string
14-
BLOCKED_ENDPOINTS []string
15-
VARIABLES map[string]any
12+
PORT string
13+
API_URL string
14+
API_TOKEN string
15+
BLOCKED_ENDPOINTS []string
16+
VARIABLES map[string]any
17+
MESSAGE_ALIASES []middlewares.MessageAlias
1618
}
1719

1820
var ENV ENV_ = ENV_{
@@ -30,6 +32,44 @@ var ENV ENV_ = ENV_{
3032
"RECIPIENTS": []string{},
3133
"NUMBER": os.Getenv("SENDER"),
3234
},
35+
MESSAGE_ALIASES: []middlewares.MessageAlias{
36+
{
37+
Alias: "msg",
38+
Priority: 100,
39+
},
40+
{
41+
Alias: "content",
42+
Priority: 99,
43+
},
44+
{
45+
Alias: "description",
46+
Priority: 98,
47+
},
48+
{
49+
Alias: "text",
50+
Priority: 20,
51+
},
52+
{
53+
Alias: "body",
54+
Priority: 15,
55+
},
56+
{
57+
Alias: "summary",
58+
Priority: 10,
59+
},
60+
{
61+
Alias: "details",
62+
Priority: 9,
63+
},
64+
{
65+
Alias: "payload",
66+
Priority: 2,
67+
},
68+
{
69+
Alias: "data",
70+
Priority: 1,
71+
},
72+
},
3373
}
3474

3575
func Load() {
@@ -40,6 +80,7 @@ func Load() {
4080

4181
blockedEndpointJSON := os.Getenv("BLOCKED_ENDPOINTS")
4282
recipientsJSON := os.Getenv("DEFAULT_RECIPIENTS")
83+
messageAliasesJSON := os.Getenv("MESSAGE_ALIASES")
4384
variablesJSON := os.Getenv("VARIABLES")
4485

4586
log.Info("Loaded Environment Variables")
@@ -64,6 +105,18 @@ func Load() {
64105
ENV.BLOCKED_ENDPOINTS = blockedEndpoints
65106
}
66107

108+
if messageAliasesJSON != "" {
109+
var msgAliases []middlewares.MessageAlias
110+
111+
err := json.Unmarshal([]byte(messageAliasesJSON), &msgAliases)
112+
113+
if err != nil {
114+
log.Error("Could not decode Message Aliases ", variablesJSON)
115+
}
116+
117+
ENV.MESSAGE_ALIASES = msgAliases
118+
}
119+
67120
if variablesJSON != "" {
68121
var variables map[string]interface{}
69122

0 commit comments

Comments
 (0)