package middleware

import (
	"context"
	"github.com/gin-gonic/gin"
	"github.com/google/uuid"
	"go-admin/logger"
)

type Trace struct {
}

func (t Trace) Handle() gin.HandlerFunc {
	return func(ctx *gin.Context) {
		traceId := uuid.New().String()
		logger.WithContext(context.WithValue(ctx, logger.TraceIdKey, traceId))

		ctx.Header("trace_id", traceId)
		ctx.Next()
	}
}
