Skip to content

Commit

Permalink
Merge pull request #23 from trojanh/patch-1
Browse files Browse the repository at this point in the history
Update krakend.json
  • Loading branch information
kpacha authored Jul 13, 2022
2 parents 09af893 + cb5ed11 commit 2aaa781
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
33 changes: 20 additions & 13 deletions example/krakend.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
{
"version": 2,
"version": 3,
"name": "My lovely gateway",
"port": 8080,
"cache_ttl": 3600,
"timeout": "3s",
"extra_config": {
"github_com/devopsfaith/krakend-gologging": {
"level": "DEBUG",
"prefix": "[KRAKEND]",
"syslog": false,
"stdout": true
}
"github_com/devopsfaith/krakend-gologging": {
"level": "DEBUG",
"prefix": "[KRAKEND]",
"syslog": false,
"stdout": true
}
},
"endpoints": [
{
"endpoint": "/supu",
"method": "GET",
"backend": [
{
"method": "GET",
"host": [
"http://127.0.0.1:8000"
"https://api.github.com"
],
"url_pattern": "/__debug/supu",
"url_pattern": "/users/devopsfaith",
"extra_config": {
"github.com/devopsfaith/krakend-martian": {
"fifo.Group": {
"scope": ["request", "response"],
"scope": [
"request",
"response"
],
"aggregateErrors": true,
"modifiers": [
{
"body.Modifier": {
"scope": ["request","response"],
"scope": [
"request",
"response"
],
"body": "eyJtc2ciOiJ5b3Ugcm9jayEifQ=="
}
}
Expand All @@ -56,7 +63,7 @@
"request",
"response"
],
"rootPath": "/etc/krakend/static",
"rootPath": "example/static",
"explicitPaths": {
"/": "/health.json"
}
Expand All @@ -67,4 +74,4 @@
]
}
]
}
}
25 changes: 20 additions & 5 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"context"
"flag"
"log"
"os"
"os/signal"
"syscall"

"github.com/gin-gonic/gin"
gologging "github.com/krakendio/krakend-gologging/v2"
Expand All @@ -12,6 +15,7 @@ import (
"github.com/luraproject/lura/v2/proxy"
krakendgin "github.com/luraproject/lura/v2/router/gin"
"github.com/luraproject/lura/v2/transport/http/client"
"github.com/luraproject/lura/v2/transport/http/server"
)

func main() {
Expand All @@ -35,20 +39,31 @@ func main() {
log.Fatal("ERROR:", err.Error())
}

logger.Debug("config:", serviceConfig)

ctx, cancel := context.WithCancel(context.Background())

backendFactory := martian.NewBackendFactory(logger, client.DefaultHTTPRequestExecutor(client.NewHTTPClient))

routerFactory := krakendgin.NewFactory(krakendgin.Config{
Engine: gin.Default(),
Logger: logger,
HandlerFactory: krakendgin.EndpointHandler,
ProxyFactory: proxy.NewDefaultFactory(backendFactory, logger),
RunServer: server.RunServer,
})

sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

go func() {
select {
case sig := <-sigs:
logger.Info("Signal intercepted:", sig)
cancel()
case <-ctx.Done():
}
}()

routerFactory.NewWithContext(ctx).Run(serviceConfig)

cancel()
// cancel()
}

0 comments on commit 2aaa781

Please sign in to comment.