package main

import (
	"context"
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/tidbcloud/tiinf/monitor/tilog"
	"github.com/tidbcloud/tiinf/monitor/titracing"
	"github.com/tidbcloud/tiinf/transport/http/tigin"
	"go.uber.org/zap"
)

func main() {
	// SHOULD be integrated with `titracing`
	_, err := titracing.InitJaeger("exmaple")
	if err != nil {
		tilog.Panic(context.TODO(), "failed to init jaeger", zap.Error(err))
	}

	// `tigin` has integrated `otelgin`
	engine := tigin.Default()

	engine.GET("/example", func(c *gin.Context) {
		ctx := c.Request.Context()
		// You can directly call the function provided by `tilog` and pass the context to it
		tilog.Info(ctx, "This is INFO", zap.String("test", "1"))
		tilog.Warn(ctx, "This is WARN", zap.String("test", "2"))
		tilog.Error(ctx, "This is ERROR", zap.String("test", "3"))
		tilog.Panic(ctx, "This is PANIC", zap.String("test", "4"))

		c.String(http.StatusOK, "Hello World")
	})

	engine.Run() //nolint:errcheck
}
