Skip to content

Commit 7839e08

Browse files
authored
migrate: to gotl (#136)
1 parent 89d1d0b commit 7839e08

File tree

30 files changed

+88
-1627
lines changed

30 files changed

+88
-1627
lines changed

.dockerignore

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
# Ignore all
2+
*
3+
14
# env file
25
*.env
36

47
# Exclude git folders
58
.git*
6-
!.github
9+
.github
710

811
# Ignore yml files
912
*.yaml
@@ -14,3 +17,12 @@
1417

1518
# Include data/
1619
!data/*
20+
21+
# Ignore source files
22+
*.go
23+
go.mod
24+
go.sum
25+
26+
# Include build
27+
!app
28+
!dist/*

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ COPY . .
2222

2323
COPY dist/${TARGETOS}/${TARGETARCH}/app .
2424

25+
RUN rm dist/ -r
26+
2527
CMD ["./app"]

go.mod

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
module github.com/codeshelldev/secured-signal-api
22

3-
go 1.25.3
3+
go 1.25.4
44

5-
require go.uber.org/zap v1.27.0
5+
require github.com/codeshelldev/gotl v0.0.2
6+
7+
require go.uber.org/zap v1.27.0 // indirect
68

79
require (
810
github.com/fsnotify/fsnotify v1.9.0 // indirect
911
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
1012
github.com/knadh/koanf/maps v0.1.2 // indirect
1113
github.com/knadh/koanf/parsers/yaml v1.1.0
12-
github.com/knadh/koanf/providers/confmap v1.0.0
13-
github.com/knadh/koanf/providers/env/v2 v2.0.0
14-
github.com/knadh/koanf/providers/file v1.2.0
15-
github.com/knadh/koanf/v2 v2.3.0
14+
github.com/knadh/koanf/providers/confmap v1.0.0 // indirect
15+
github.com/knadh/koanf/providers/env/v2 v2.0.0 // indirect
16+
github.com/knadh/koanf/providers/file v1.2.0 // indirect
17+
github.com/knadh/koanf/v2 v2.3.0 // indirect
1618
github.com/mitchellh/copystructure v1.2.0 // indirect
1719
github.com/mitchellh/reflectwalk v1.0.2 // indirect
1820
go.uber.org/multierr v1.11.0 // indirect
1921
go.yaml.in/yaml/v3 v3.0.4 // indirect
20-
golang.org/x/sys v0.37.0 // indirect
22+
golang.org/x/sys v0.38.0 // indirect
2123
)

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/codeshelldev/gotl v0.0.2 h1:PQbipYHut3DNvwcrdkQmIGo2p6X6a889Glmba/KIeFQ=
2+
github.com/codeshelldev/gotl v0.0.2/go.mod h1:OzawxKcFw9QEgbeR5H2UXryhYeeLo8xSLme1r8viE+U=
13
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
24
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
35
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
@@ -36,8 +38,8 @@ go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
3638
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
3739
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
3840
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
39-
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
40-
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
41+
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
42+
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
4143
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
4244
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
4345
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

internals/config/loader.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
"strconv"
88
"strings"
99

10+
"github.com/codeshelldev/gotl/pkg/configutils"
11+
log "github.com/codeshelldev/gotl/pkg/logger"
12+
"github.com/codeshelldev/gotl/pkg/stringutils"
1013
"github.com/codeshelldev/secured-signal-api/internals/config/structure"
11-
"github.com/codeshelldev/secured-signal-api/utils/configutils"
12-
log "github.com/codeshelldev/secured-signal-api/utils/logger"
1314

1415
"github.com/knadh/koanf/parsers/yaml"
1516
)
@@ -41,7 +42,7 @@ func Load() {
4142

4243
LoadTokens()
4344

44-
userConf.LoadEnv()
45+
userConf.LoadEnv(normalizeEnv)
4546

4647
NormalizeConfig(defaultsConf)
4748
NormalizeConfig(userConf)
@@ -110,18 +111,19 @@ func Normalize(config *configutils.Config, path string, structure any) {
110111
// Load temporary config back into paths
111112
config.Layer.Delete(path)
112113

113-
config.Load(tmpConf.Layer.Get("").(map[string]any), path)
114+
config.Load(tmpConf.Layer.Raw(), path)
114115
}
115116

116117
func InitReload() {
117-
reload := func() {
118+
reload := func(path string) {
119+
log.Debug(path, " changed, reloading...")
118120
Load()
119121
Log()
120122
}
121123

122-
defaultsConf.OnLoad(reload)
123-
userConf.OnLoad(reload)
124-
tokenConf.OnLoad(reload)
124+
defaultsConf.OnReload(reload)
125+
userConf.OnReload(reload)
126+
tokenConf.OnReload(reload)
125127
}
126128

127129
func InitEnv() {
@@ -139,6 +141,7 @@ func InitEnv() {
139141
}
140142

141143
func LoadDefaults() {
144+
log.Debug("Loading defaults ", ENV.DEFAULTS_PATH)
142145
_, err := defaultsConf.LoadFile(ENV.DEFAULTS_PATH, yaml.Parser())
143146

144147
if err != nil {
@@ -147,6 +150,7 @@ func LoadDefaults() {
147150
}
148151

149152
func LoadConfig() {
153+
log.Debug("Loading Config ", ENV.CONFIG_PATH)
150154
_, err := userConf.LoadFile(ENV.CONFIG_PATH, yaml.Parser())
151155

152156
if err != nil {
@@ -161,3 +165,11 @@ func LoadConfig() {
161165
log.Error("Could not Load Config ", ENV.CONFIG_PATH, ": ", err.Error())
162166
}
163167
}
168+
169+
func normalizeEnv(key string, value string) (string, any) {
170+
key = strings.ToLower(key)
171+
key = strings.ReplaceAll(key, "__", ".")
172+
key = strings.ReplaceAll(key, "_", "")
173+
174+
return key, stringutils.ToType(value)
175+
}

internals/config/tokens.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package config
33
import (
44
"strconv"
55

6+
"github.com/codeshelldev/gotl/pkg/configutils"
7+
log "github.com/codeshelldev/gotl/pkg/logger"
68
"github.com/codeshelldev/secured-signal-api/internals/config/structure"
7-
"github.com/codeshelldev/secured-signal-api/utils/configutils"
8-
log "github.com/codeshelldev/secured-signal-api/utils/logger"
99
"github.com/knadh/koanf/parsers/yaml"
1010
)
1111

@@ -31,17 +31,15 @@ func NormalizeTokens() {
3131

3232
for _, config := range tokenConf.Layer.Slices("tokenconfigs") {
3333
tmpConf := configutils.New()
34-
tmpConf.Load(config.Get("").(map[string]any), "")
34+
tmpConf.Load(config.Raw(), "")
3535

3636
Normalize(tmpConf, "overrides", &structure.SETTINGS{})
3737

38-
data = append(data, tmpConf.Layer.Get("").(map[string]any))
38+
data = append(data, tmpConf.Layer.Raw())
3939
}
4040

4141
// Merge token configs together into new temporary config
42-
tokenConf.Load(map[string]any{
43-
"tokenconfigs": data,
44-
}, "")
42+
tokenConf.Load(data, "tokenconfigs")
4543
}
4644

4745
func InitTokens() {

internals/proxy/middlewares/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"slices"
88
"strings"
99

10+
log "github.com/codeshelldev/gotl/pkg/logger"
1011
"github.com/codeshelldev/secured-signal-api/internals/config"
11-
log "github.com/codeshelldev/secured-signal-api/utils/logger"
1212
)
1313

1414
var Auth Middleware = Middleware{

internals/proxy/middlewares/endpoints.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package middlewares
22

33
import (
44
"net/http"
5+
"path"
56
"slices"
67
"strings"
7-
"path"
88

9-
log "github.com/codeshelldev/secured-signal-api/utils/logger"
9+
log "github.com/codeshelldev/gotl/pkg/logger"
1010
)
1111

1212
var Endpoints Middleware = Middleware{

internals/proxy/middlewares/log.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package middlewares
33
import (
44
"net/http"
55

6-
log "github.com/codeshelldev/secured-signal-api/utils/logger"
7-
"github.com/codeshelldev/secured-signal-api/utils/request"
6+
log "github.com/codeshelldev/gotl/pkg/logger"
7+
"github.com/codeshelldev/gotl/pkg/request"
88
)
99

1010
var Logging Middleware = Middleware{

internals/proxy/middlewares/mapping.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package middlewares
33
import (
44
"net/http"
55

6+
jsonutils "github.com/codeshelldev/gotl/pkg/jsonutils"
7+
log "github.com/codeshelldev/gotl/pkg/logger"
8+
request "github.com/codeshelldev/gotl/pkg/request"
69
"github.com/codeshelldev/secured-signal-api/internals/config/structure"
7-
jsonutils "github.com/codeshelldev/secured-signal-api/utils/jsonutils"
8-
log "github.com/codeshelldev/secured-signal-api/utils/logger"
9-
request "github.com/codeshelldev/secured-signal-api/utils/request"
1010
)
1111

1212
var Mapping Middleware = Middleware{

0 commit comments

Comments
 (0)