Skip to content

Instantly share code, notes, and snippets.

@adityarama1210
Created December 5, 2020 00:45
Show Gist options
  • Save adityarama1210/8f1a4ab1645c29786b448dc167c22f78 to your computer and use it in GitHub Desktop.
Save adityarama1210/8f1a4ab1645c29786b448dc167c22f78 to your computer and use it in GitHub Desktop.
go elastic main function
package main
import (
"context"
"encoding/json"
"log"
"net/http"
"time"
"github.com/gin-gonic/gin"
"go.elastic.co/apm"
"go.elastic.co/apm/module/apmgin"
)
func main() {
r := gin.Default()
r.Use(apmgin.Middleware(r))
r.GET("/example", func(c *gin.Context) {
span, ctx := apm.StartSpan(c.Request.Context(), "PingHandler", "request")
defer span.End()
processingRequest(ctx)
todo, err := getTodoFromAPI(ctx)
if err != nil {
log.Println(err)
}
c.JSON(http.StatusOK, gin.H{
"todo": todo,
})
})
r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment