Created
December 5, 2020 00:45
-
-
Save adityarama1210/8f1a4ab1645c29786b448dc167c22f78 to your computer and use it in GitHub Desktop.
go elastic main function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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