Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion dev-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export DEFAULTS_PATH=$DIR/data/defaults.yml
export FAVICON_PATH=$DIR/data/favicon.ico
export CONFIG_PATH=$DIR/.dev/config.yml
export TOKENS_PATH=$DIR/.dev/tokens
export TOKENS_DIR=$DIR/.dev/tokens

export API__URL=http://127.0.0.1:8881

export LOG_LEVEL=dev

Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/codeshelldev/gotl/pkg/configutils v0.0.5
github.com/codeshelldev/gotl/pkg/docker v0.0.2
github.com/codeshelldev/gotl/pkg/jsonutils v0.0.2
github.com/codeshelldev/gotl/pkg/logger v0.0.3
github.com/codeshelldev/gotl/pkg/logger v0.0.6
github.com/codeshelldev/gotl/pkg/pretty v0.0.8
github.com/codeshelldev/gotl/pkg/query v0.0.3
github.com/codeshelldev/gotl/pkg/request v0.0.3
Expand All @@ -15,8 +15,8 @@ require (
)

require (
github.com/codeshelldev/gotl/pkg/ioutils v0.0.2
github.com/knadh/koanf/parsers/yaml v1.1.0
go.uber.org/zap v1.27.1
golang.org/x/time v0.14.0
)

Expand All @@ -34,6 +34,7 @@ require (
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.1 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/sys v0.40.0 // indirect
)
14 changes: 4 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfatpWHKCs=
github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA=
github.com/clipperhouse/uax29/v2 v2.2.0 h1:ChwIKnQN3kcZteTXMgb1wztSgaU+ZemkgWdohwgs8tY=
github.com/clipperhouse/uax29/v2 v2.2.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM=
github.com/clipperhouse/uax29/v2 v2.3.1 h1:RjM8gnVbFbgI67SBekIC7ihFpyXwRPYWXn9BZActHbw=
github.com/clipperhouse/uax29/v2 v2.3.1/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
github.com/codeshelldev/gotl/pkg/configutils v0.0.4 h1:AHCCP+8FzFKP8lMtytWo98x0583bCPI7wykbw6z9pTs=
github.com/codeshelldev/gotl/pkg/configutils v0.0.4/go.mod h1:WoWMBB8+84ePRnI2m+kbq1Rw8F/9iCWLHkVBsun3Qjc=
github.com/codeshelldev/gotl/pkg/configutils v0.0.5 h1:Dv9PiiJhfRihnv0f2H8T4ebOBaA7SyISOK7ghJ6oA3k=
github.com/codeshelldev/gotl/pkg/configutils v0.0.5/go.mod h1:WoWMBB8+84ePRnI2m+kbq1Rw8F/9iCWLHkVBsun3Qjc=
github.com/codeshelldev/gotl/pkg/docker v0.0.2 h1:kpseReocEBoSzWe/tOhUrIrOYeAR/inw3EF2/d+N078=
github.com/codeshelldev/gotl/pkg/docker v0.0.2/go.mod h1:odNnlRw4aO1n2hSkDZIaiuSXIoFoVeatmXtF64Yd33U=
github.com/codeshelldev/gotl/pkg/ioutils v0.0.2 h1:IRcN2M6H4v59iodw1k7gFX9lirhbVy6RZ4yRtKNcFYg=
github.com/codeshelldev/gotl/pkg/ioutils v0.0.2/go.mod h1:WPQYglNqThBatoGaQK0OGx2bwzto1oi0zb1fB9gsaUU=
github.com/codeshelldev/gotl/pkg/jsonutils v0.0.2 h1:ERsjkaWVrsyUZoEunCEeNYDXhuaIvoSetB8e/zI4Tqo=
github.com/codeshelldev/gotl/pkg/jsonutils v0.0.2/go.mod h1:oxgKaAoMu6iYVHfgR7AhkK22xbYx4K0KCkyVEfYVoWs=
github.com/codeshelldev/gotl/pkg/logger v0.0.3 h1:M99fsH7SiIFS4jNRCNtu3BJNYdcPD+LbqJ7l5aBQeJ8=
github.com/codeshelldev/gotl/pkg/logger v0.0.3/go.mod h1:pL/I7KYxbGHhyedallZlCkBvoalv9gAWNEYVXbF9BoM=
github.com/codeshelldev/gotl/pkg/pretty v0.0.6 h1:b+1k4Sm6Do7TqUlOFQ5YjybyHJMXYs72GYYBJpSL5JQ=
github.com/codeshelldev/gotl/pkg/pretty v0.0.6/go.mod h1:2Gk6UBrtkIME2RCSNytS/RJ5lHXYL/MDx0rYRpknobM=
github.com/codeshelldev/gotl/pkg/logger v0.0.6 h1:heo6z6yZm5PpX78vxud9HJNfVU9J46HVlW8T4EOy9nQ=
github.com/codeshelldev/gotl/pkg/logger v0.0.6/go.mod h1:pL/I7KYxbGHhyedallZlCkBvoalv9gAWNEYVXbF9BoM=
github.com/codeshelldev/gotl/pkg/pretty v0.0.8 h1:buLobwNqZRlYGnfyFLi7A7z2m7362Wm9k5Y+Tv0tMsI=
github.com/codeshelldev/gotl/pkg/pretty v0.0.8/go.mod h1:2Gk6UBrtkIME2RCSNytS/RJ5lHXYL/MDx0rYRpknobM=
github.com/codeshelldev/gotl/pkg/query v0.0.3 h1:Zy8k0R5HcJS00OMPRHybgFEiwMg7ceLyv6bA0G7NOfs=
Expand All @@ -30,8 +26,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/go-viper/mapstructure/v2 v2.5.0 h1:vM5IJoUAy3d7zRSVtIwQgBj7BiWtMPfmPEgAXnvj1Ro=
github.com/go-viper/mapstructure/v2 v2.5.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/knadh/koanf/maps v0.1.2 h1:RBfmAW5CnZT+PJ1CVc1QSJKf4Xu9kxfQgYVQSu8hpbo=
Expand Down
28 changes: 6 additions & 22 deletions internals/proxy/middlewares/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/codeshelldev/gotl/pkg/logger"
"github.com/codeshelldev/gotl/pkg/request"
"go.uber.org/zap/zapcore"
)

var RequestLogger Middleware = Middleware{
Expand Down Expand Up @@ -50,29 +49,14 @@ func middlewareLoggerHandler(next http.Handler) http.Handler {

logLevel := conf.SERVICE.LOG_LEVEL

if strings.TrimSpace(logLevel) == "" {
logLevel = getConfig("").SERVICE.LOG_LEVEL
}

options := logger.DefaultOptions()
options.EncodeCaller = func(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder) {
var name string

if strings.TrimSpace(conf.NAME) != "" {
name = " " + conf.NAME
}
l := logger.Get()

enc.AppendString(caller.TrimmedPath() + name)
}

l, err := logger.New(logLevel, options)

if err != nil {
logger.Error("Could not create Middleware Logger: ", err.Error())
}
if strings.TrimSpace(logLevel) != "" {
l = logger.Get().Sub(logLevel)

if l == nil {
l = logger.Get()
l.SetTransform(func(content string) string {
return conf.NAME + "\t" + content
})
}

req = setContext(req, loggerKey, l)
Expand Down
29 changes: 28 additions & 1 deletion internals/proxy/proxy.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package proxy

import (
"bytes"
"log"
"net/http"
"net/http/httputil"
"net/url"
"strings"

"github.com/codeshelldev/gotl/pkg/ioutils"
"github.com/codeshelldev/gotl/pkg/logger"
m "github.com/codeshelldev/secured-signal-api/internals/proxy/middlewares"
)

Expand All @@ -13,10 +18,32 @@ type Proxy struct {
}

func Create(targetUrl string) Proxy {
url, _ := url.Parse(targetUrl)
if strings.TrimSpace(targetUrl) == "" {
logger.Fatal("Missing API URL")
return Proxy{Use: func() *httputil.ReverseProxy {return nil}}
}

url, err := url.Parse(targetUrl)

if err != nil {
logger.Fatal("Invalid API URL: ", targetUrl)
return Proxy{Use: func() *httputil.ReverseProxy {return nil}}
}

proxy := httputil.NewSingleHostReverseProxy(url)

w := &ioutils.InterceptWriter{
Writer: &bytes.Buffer{},
Hook: func(bytes []byte) {
msg := string(bytes)
msg = strings.TrimSuffix(msg, "\n")

logger.Error(msg)
},
}

proxy.ErrorLog = log.New(w, "", 0)

director := proxy.Director

proxy.Director = func(req *http.Request) {
Expand Down