- Add bootstrap package to initialize application components including logger, tracer, and HTTP server. - Create config package to load runtime settings from environment variables. - Implement observability features including logging, metrics, and tracing. - Add health check and hello use cases with corresponding HTTP handlers. - Introduce middleware for request ID, access logging, metrics, and recovery. - Set up HTTP router with defined routes for health and hello endpoints. - Include tests for health and hello endpoints to ensure proper functionality. - Add OpenTelemetry collector configuration for trace exporting.
26 lines
481 B
Go
26 lines
481 B
Go
package handlers
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type HelloUsecase interface {
|
|
Message(ctx context.Context) string
|
|
}
|
|
|
|
type HelloHandler struct {
|
|
helloUsecase HelloUsecase
|
|
}
|
|
|
|
func NewHelloHandler(helloUsecase HelloUsecase) *HelloHandler {
|
|
return &HelloHandler{helloUsecase: helloUsecase}
|
|
}
|
|
|
|
func (h *HelloHandler) Hello(c *gin.Context) {
|
|
message := h.helloUsecase.Message(c.Request.Context())
|
|
c.JSON(http.StatusOK, gin.H{"message": message})
|
|
}
|