Installation steps
Install Atatus Go Agent and framework module
copygo get go.atatus.com/agent go get go.atatus.com/agent/module/atrestful
Set up tracer and add Atatus middleware
copyimport ( "github.com/emicklei/go-restful" "go.atatus.com/agent" "go.atatus.com/agent/module/atrestful" ) func main() { // Initialize Atatus tracer using environment variables tracer := atatus.DefaultTracer tracer.Service.LicenseKey = os.Getenv("ATATUS_LICENSE_KEY") tracer.Service.AppName = os.Getenv("ATATUS_APP_NAME") tracer.Service.Tracing = os.Getenv("ATATUS_TRACING") tracer.Service.Analytics = os.Getenv("ATATUS_ANALYTICS") // Apply Atatus filter middleware restful.Filter(atrestful.Filter()) // Setup WebService and route var ws restful.WebService ws.Path("/things") ws.Route(ws.GET().To(handleRequest)) // Add WebService to default container restful.Add(&ws) // Start HTTP server (example on port 8080) http.ListenAndServe(":8080", nil) } func handleRequest(req *restful.Request, resp *restful.Response) { // The context from req.Request.Context() should be propagated to downstream operations, // such as database queries and external HTTP API calls. ctx:= req.Request.Context() _ = db.QueryContext(ctx, "SELECT 'Atatus!'").Scan(&greeting) }
Clean Up and Sync Dependencies
copygo mod tidy
Run the Application
copygo run main.go