Skip to content

Commit

Permalink
parameter to disable request tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
psycofdj committed Mar 12, 2021
1 parent dcbc406 commit fec61b2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/cmd/aggregadantur/aggregadantur
/*.json
config.yml
/aggregadantur
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ func main() {
}))

// create a router, and add it a session store, here it is a cookie store, it is for saving session with token.
rtr := aggregadantur.NewRouter(sessions.NewCookieStore([]byte(myConfig.SessionKey)))
sess := sessions.NewCookieStore([]byte(myConfig.SessionKey))
rtr := aggregadantur.NewRouter(sess)
// add you aggregate route
err = rtr.AddMuxRoute(aggrRoute)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion cmd/aggregadantur/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ func main() {
return
}

router := aggregadantur.NewRouter(sessions.NewCookieStore([]byte(c.Server.SessionKey)))
sess := sessions.NewCookieStore([]byte(c.Server.SessionKey))
router := aggregadantur.NewRouter(sess)
err = router.AddMuxRoutes(c.Routes...)
if err != nil {
log.Fatal("Error loading routes: ", err.Error())
Expand Down
19 changes: 14 additions & 5 deletions routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,23 @@ import (
)

type Router struct {
rtr *mux.Router
store sessions.Store
rtr *mux.Router
store sessions.Store
tracer bool
}

func NewRouter(store sessions.Store) *Router {
return &Router{
rtr: mux.NewRouter(),
store: store,
rtr: mux.NewRouter(),
store: store,
tracer: true,
}
}

func (r Router) DisableTracer() {
r.tracer = false
}

func (r Router) AddMuxRoute(route *models.AggregateRoute) error {
httpClient := makeHttpClient(route.InsecureSkipVerify)
var handler http.Handler
Expand All @@ -41,7 +47,10 @@ func (r Router) AddMuxRoute(route *models.AggregateRoute) error {

handler = NewAggregateHandler(handler, route, httpClient)
handler = NewAuthHandler(handler, route, httpClient, r.store)
handler, err = trace.New(handler, log.StandardLogger().Out)
if r.tracer {
handler, err = trace.New(handler, log.StandardLogger().Out)
}

if err != nil {
return err
}
Expand Down

0 comments on commit fec61b2

Please sign in to comment.