Skip to content

Commit

Permalink
Drop support for Go 1.21 in dice example
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Sep 10, 2024
1 parent e9ac0d2 commit c6283ff
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 77 deletions.
31 changes: 31 additions & 0 deletions example/dice/rolldice.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
package main

import (
"fmt"
"io"
"math/rand"
"net/http"
"strconv"

"go.opentelemetry.io/contrib/bridges/otelslog"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
)

Expand All @@ -27,3 +34,27 @@ func init() {
panic(err)
}
}

func rolldice(w http.ResponseWriter, r *http.Request) {
ctx, span := tracer.Start(r.Context(), "roll")
defer span.End()

roll := 1 + rand.Intn(6)

var msg string
if player := r.PathValue("player"); player != "" {
msg = fmt.Sprintf("%s is rolling the dice", player)
} else {
msg = "Anonymous player is rolling the dice"
}
logger.InfoContext(ctx, msg, "result", roll)

rollValueAttr := attribute.Int("roll.value", roll)
span.SetAttributes(rollValueAttr)
rollCnt.Add(ctx, 1, metric.WithAttributes(rollValueAttr))

resp := strconv.Itoa(roll) + "\n"
if _, err := io.WriteString(w, resp); err != nil {
logger.ErrorContext(ctx, "Write failed", "error", err)
}
}
35 changes: 0 additions & 35 deletions example/dice/rolldice_go1.21.go

This file was deleted.

42 changes: 0 additions & 42 deletions example/dice/rolldice_go1.22.go

This file was deleted.

0 comments on commit c6283ff

Please sign in to comment.