Skip to content

Commit

Permalink
Drop support for Go 1.21 in dice example (#5800)
Browse files Browse the repository at this point in the history
Resolves #5359
  • Loading branch information
MrAlias authored Sep 10, 2024
1 parent e9ac0d2 commit cdd2dbb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 78 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Removed

- Drop support for [Go 1.21]. (#5736, #5740)
- Drop support for [Go 1.21]. (#5736, #5740, #5800)

<!-- Released section -->
<!-- Don't change this section unless doing release -->
Expand Down
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 cdd2dbb

Please sign in to comment.