diff --git a/api/server.go b/api/server.go index 3387ce9..8d08859 100644 --- a/api/server.go +++ b/api/server.go @@ -2,6 +2,7 @@ package api import ( "fmt" + "net/http" "time" "github.com/gin-contrib/cors" @@ -53,6 +54,11 @@ func (server *Server) setupRouter() { router.GET("/docs/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) + // Ping pong tutorial prometheus + http.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) { + fmt.Print(w, "pong") + }) + router.POST("/users", server.createUser) router.POST("/users/login", server.loginUser) // Question diff --git a/pkg/tutorial.go b/pkg/tutorial.go new file mode 100644 index 0000000..2a553d8 --- /dev/null +++ b/pkg/tutorial.go @@ -0,0 +1,20 @@ +package metric + +import ( + "fmt" + "net/http" + + "github.com/prometheus/client_golang/prometheus" +) + +func ping(w http.ResponseWriter, req *http.Request) { + pingCounter.Inc() + fmt.Fprintf(w, "pong") +} + +var pingCounter = prometheus.NewCounter( + prometheus.CounterOpts{ + Name: "ping_request_count", + Help: "No of request handled by Ping handler", + }, +)