S SmartDocs
Série: Go go 30 linhas · Atualizado 2026-04-18

router.go

Go/payment-gateway-challenge/internal/router/router.go

// Package router configures Echo middlewares and REST routes.
package router

import (
	"payment-gateway-challenge/internal/handlers"

	"github.com/labstack/echo/v4"
	echomw "github.com/labstack/echo/v4/middleware"
	echoSwagger "github.com/swaggo/echo-swagger"
)

// NewEcho builds the HTTP server with routes registered on the official path
// prefix /api/payments (matching the reference Go template style).
func NewEcho(api *handlers.PaymentAPI) *echo.Echo {
	e := echo.New()
	e.HideBanner = true

	e.Use(echomw.Recover())
	e.Use(echomw.Logger())

	e.GET("/ping", handlers.Ping)

	// OpenAPI UI (generated by swag — run `make swagger` after changing annotations).
	e.GET("/swagger/*", echoSwagger.WrapHandler)

	e.POST("/api/payments", api.ProcessPayment)
	e.GET("/api/payments/:id", api.GetPayment)

	return e
}

Artigos relacionados