File tree Expand file tree Collapse file tree 3 files changed +62
-20
lines changed
Expand file tree Collapse file tree 3 files changed +62
-20
lines changed Original file line number Diff line number Diff line change 1+ name : Go Build, Test, and Format
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+ - ' v[0-9]+.[0-9]+.[0-9]+'
8+ pull_request :
9+ branches :
10+ - main
11+ - ' v[0-9]+.[0-9]+.[0-9]+'
12+
13+ jobs :
14+ build-test :
15+ name : Build and Test on ${{ matrix.os }}
16+ runs-on : ${{ matrix.os }}
17+ strategy :
18+ matrix :
19+ os : [ubuntu-latest, macos-latest, windows-latest]
20+
21+ steps :
22+ - name : Checkout code
23+ uses : actions/checkout@v4
24+
25+ - name : Set up Go
26+ uses : actions/setup-go@v5
27+ with :
28+ go-version : ' 1.24.4'
29+
30+ - name : Build
31+ run : go build ./...
32+
33+ - name : Run Tests
34+ run : go test ./...
35+
36+ format :
37+ name : Format
38+ runs-on : ubuntu-latest
39+ if : github.event_name == 'push' # only format on push events (not PRs from forks)
40+
41+ steps :
42+ - name : Checkout code
43+ uses : actions/checkout@v4
44+
45+ - name : Set up Go
46+ uses : actions/setup-go@v5
47+ with :
48+ go-version : ' 1.24.4'
49+
50+ - name : Auto-format code with gofmt and commit changes
51+ run : |
52+ gofmt -w .
53+ if [ -n "$(git status --porcelain)" ]; then
54+ echo "Code was not formatted. Applying gofmt and committing changes..."
55+ git config user.name "github-actions"
56+ git config user.email "github-actions@github.com"
57+ git add .
58+ git commit -m "chore: auto-format Go code via gofmt"
59+ git push
60+ else
61+ echo "Code already properly formatted."
62+ fi
Original file line number Diff line number Diff line change @@ -3,11 +3,9 @@ package log
33
44import (
55 "context"
6- "fmt"
76 "log/slog"
87 "os"
98 "sync"
10- "time"
119
1210 "gopkg.in/natefinch/lumberjack.v2"
1311)
@@ -103,11 +101,6 @@ func Fatal(msg string, args ...any) {
103101 os .Exit (1 )
104102}
105103
106- // Request ID utilities
107- func GenerateRequestID () string {
108- return fmt .Sprintf ("req_%d" , time .Now ().UnixNano ())
109- }
110-
111104type contextKey string
112105
113106const requestIDKey contextKey = "request_id"
Original file line number Diff line number Diff line change 44 "context"
55 "log/slog"
66 "os"
7- "strings"
87 "testing"
98)
109
@@ -47,18 +46,6 @@ func TestInitialize(t *testing.T) {
4746}
4847
4948func TestRequestIDFunctions (t * testing.T ) {
50- t .Run ("generates unique request IDs" , func (t * testing.T ) {
51- id1 := GenerateRequestID ()
52- id2 := GenerateRequestID ()
53-
54- if id1 == id2 {
55- t .Error ("IDs should be unique" )
56- }
57- if ! strings .HasPrefix (id1 , "req_" ) {
58- t .Error ("ID should have req_ prefix" )
59- }
60- })
61-
6249 t .Run ("context request ID functions" , func (t * testing.T ) {
6350 ctx := ContextWithRequestID (context .Background (), "test123" )
6451 retrieved := RequestIDFromContext (ctx )
You can’t perform that action at this time.
0 commit comments