Skip to content

Commit

Permalink
Merge pull request #7 from devopsfaith/ce
Browse files Browse the repository at this point in the history
customized ce example added
  • Loading branch information
kpacha authored Jan 26, 2021
2 parents d8b6501 + cab88af commit afcb8b0
Show file tree
Hide file tree
Showing 3 changed files with 2,228 additions and 1 deletion.
69 changes: 69 additions & 0 deletions ce/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// ce is an example of how to customize a complete KrakenD API Gateway.
//
// this example adds a dummy gin middleware.

package main

import (
"context"
"fmt"
"log"
"os"
"os/signal"
"syscall"

krakend "github.com/devopsfaith/krakend-ce"
cmd "github.com/devopsfaith/krakend-cobra"
flexibleconfig "github.com/devopsfaith/krakend-flexibleconfig"
viper "github.com/devopsfaith/krakend-viper"
"github.com/devopsfaith/krakend/config"
"github.com/gin-gonic/gin"
)

const (
fcPartials = "FC_PARTIALS"
fcTemplates = "FC_TEMPLATES"
fcSettings = "FC_SETTINGS"
fcPath = "FC_OUT"
fcEnable = "FC_ENABLE"
)

func main() {
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:
log.Println("Signal intercepted:", sig)
cancel()
case <-ctx.Done():
}
}()

krakend.RegisterEncoders()

var cfg config.Parser
cfg = viper.New()
if os.Getenv(fcEnable) != "" {
cfg = flexibleconfig.NewTemplateParser(flexibleconfig.Config{
Parser: cfg,
Partials: os.Getenv(fcPartials),
Settings: os.Getenv(fcSettings),
Path: os.Getenv(fcPath),
Templates: os.Getenv(fcTemplates),
})
}

eb := krakend.ExecutorBuilder{
Middlewares: []gin.HandlerFunc{func(c *gin.Context) {
fmt.Println("dummy mw executed for req", c.Request.URL.String())
// TODO: do semthing useful here
c.Next()
}},
}

cmd.Execute(cfg, eb.NewCmdExecutor(ctx))
}
10 changes: 9 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ go 1.15

require (
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b // indirect
github.com/devopsfaith/krakend v1.2.0
github.com/devopsfaith/krakend v1.2.1-0.20210125222339-1e35b1a8bb02
github.com/devopsfaith/krakend-ce v1.2.1-0.20210119172711-9a10ec2ef213
github.com/devopsfaith/krakend-cobra v0.0.0-20200317174411-3518505e8cd2
github.com/devopsfaith/krakend-flexibleconfig v0.0.0-20190408143848-fc4ef2b4d5cf
github.com/devopsfaith/krakend-jose v1.1.1-0.20210119142416-ee6196d50d07 // indirect
github.com/devopsfaith/krakend-opencensus v1.1.1-0.20201119132304-815fbc5addba // indirect
github.com/devopsfaith/krakend-viper v0.0.0-20200605164302-854fa4ff4a66
github.com/garyburd/redigo v1.6.2 // indirect
github.com/gin-gonic/contrib v0.0.0-20201101042839-6a891bf89f19
github.com/gin-gonic/gin v1.6.3
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79
github.com/robfig/go-cache v0.0.0-20130306151617-9fc39e0dbf62 // indirect
github.com/spf13/cobra v1.1.1
github.com/spf13/viper v1.7.1
)
Loading

0 comments on commit afcb8b0

Please sign in to comment.