Anúncio
Anúncio

Mais conteúdo relacionado

Anúncio

Mais de tdc-globalcode(20)

Anúncio

TDC2018SP | Trilha Go - Case Easylocus

  1. AS AVENTURAS QUE RESULTARAM NA NOSSA API DE ENDEREÇOS EM GO Case EasyLocus
  2. @PAULOELR EASY @HENRIQUEHOLANDA EASY
  3. OBJETIVOS
  4. O PROBLEMA
  5. BEEGO
  6. GO PURO
  7. ESCALABILIDADE
  8. GERENCIAMENTO DE DEPENDÊNCIAS
  9. MIDDLEWARES
  10. package middlewares import ( "easytaxi/easylocus/entities" "net/http" ) type NotFoundMiddleware struct { Next http.Handler } func (controller NotFoundMiddleware) ServeHTTP(writer http.ResponseWriter, request *http.Request) { path := request.URL.Path routes := entities.Routes for _, route := range routes { if route.Path == path { controller.Next.ServeHTTP(writer, request) return } } http.NotFound(writer, request) } MIDDLEWARES
  11. package middlewares import ( NewRelicService "easytaxi/easylocus/services/newrelic" "github.com/newrelic/go-agent" "net/http" ) type NewRelicMiddleware struct { Next http.Handler } func (controller NewRelicMiddleware) ServeHTTP(writer http.ResponseWriter, request *http.Request) { if NewRelicService.Agent != nil { _, newRelicHandler := newrelic.WrapHandle( NewRelicService.Agent, request.URL.Path, http.Handler(controller.Next), ) newRelicHandler.ServeHTTP(writer, request) return } controller.Next.ServeHTTP(writer, request) } MIDDLEWARES
  12. func main() { http.Handle( entities.RootEndpoint, middlewares.NotFoundMiddleware{ middlewares.NewRelicMiddleware{ controllers.IndexController{}, }, }, ) http.Handle( entities.PlaceEndpoint, middlewares.NotFoundMiddleware{ middlewares.NewRelicMiddleware{ middlewares.AuthenticationMiddleware{ controllers.PlaceController{}, }, }, }, ) log.Fatal(http.ListenAndServe(":"+conf.GetConfigs().Port, nil)) } ROUTES
  13. METRICAS
  14. METRICAS
  15. METRICAS
  16. AUTENTICAÇÃO
  17. LOGS
  18. CONCLUSÃO
  19. OBRIGADO
Anúncio