Skip to content

Commit 09980d9

Browse files
xlog: pointer slice (#5)
1 parent 98bceef commit 09980d9

File tree

6 files changed

+328
-86
lines changed

6 files changed

+328
-86
lines changed

.github/workflows/go.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# This workflow will build a golang project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
3+
4+
name: Go
5+
6+
on:
7+
push:
8+
branches: [ "master" ]
9+
pull_request:
10+
branches: [ "master" ]
11+
12+
jobs:
13+
test:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
- name: Set up Go
19+
uses: actions/setup-go@v4
20+
with:
21+
go-version-file: 'go.mod'
22+
23+
- name: Build
24+
run: go build -v ./...
25+
26+
- name: Test
27+
run: go test -v ./...
28+
29+
golangci:
30+
name: lint
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v4
34+
- uses: actions/setup-go@v5
35+
with:
36+
go-version: stable
37+
- name: golangci-lint
38+
uses: golangci/golangci-lint-action@v7
39+
with:
40+
version: v2.0

.golangci.yml

Lines changed: 62 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,72 @@
1-
linters:
2-
# Disable all linters.
3-
disable-all: true
4-
# Enable specific linter
5-
enable:
6-
- sloglint
7-
- errcheck
8-
- gci
9-
- wrapcheck
10-
1+
version: "2"
112
run:
12-
# Number of operating system threads (`GOMAXPROCS`) that can execute golangci-lint simultaneously.
13-
# If it is explicitly set to 0 (i.e. not the default) then golangci-lint will automatically set the value to match Linux container CPU quota.
14-
# Default: the number of logical CPUs in the machine
153
concurrency: 8
16-
# Timeout for analysis, e.g. 30s, 5m.
17-
# Default: 1m
18-
timeout: 5m
19-
go: '1.22.0'
20-
4+
go: 1.22.0
215
output:
22-
# Show statistics per linter.
23-
show-stats: true
24-
# Sort results by the order defined in `sort-order`.
25-
sort-results: true
26-
# Order to use when sorting results.
27-
# Require `sort-results` to `true`.
28-
# Possible values: `file`, `linter`, and `severity`.
29-
#
30-
# If the severity values are inside the following list, they are ordered in this order:
31-
# 1. error
32-
# 2. warning
33-
# 3. high
34-
# 4. medium
35-
# 5. low
36-
# Either they are sorted alphabetically.
376
sort-order:
387
- linter
398
- file
409
- severity
41-
10+
linters:
11+
default: none
12+
enable:
13+
- errcheck
14+
- sloglint
15+
- wrapcheck
16+
settings:
17+
errcheck:
18+
exclude-functions:
19+
- (net/http.ResponseWriter).Write
20+
sloglint:
21+
attr-only: true
22+
exclusions:
23+
generated: lax
24+
presets:
25+
- comments
26+
- common-false-positives
27+
- legacy
28+
- std-error-handling
29+
rules:
30+
- linters:
31+
- lll
32+
source: '^//go:generate '
33+
paths:
34+
- .*\.gen\.go$
35+
- .*\.ridl$
36+
- vendor
37+
- tools
38+
- scripts
39+
- bin
40+
- .buildkite
41+
- etc
42+
- third_party$
43+
- builtin$
44+
- examples$
4245
issues:
43-
# Maximum issues count per one linter.
44-
# Set to 0 to disable.
45-
# Default: 50
4646
max-issues-per-linter: 0
47-
# Maximum count of issues with the same text.
48-
# Set to 0 to disable.
49-
# Default: 3
5047
max-same-issues: 0
51-
exclude-rules:
52-
- linters:
53-
- lll
54-
source: "^//go:generate "
55-
exclude-dirs:
56-
- "vendor"
57-
- "tools"
58-
- "scripts"
59-
- "bin"
60-
- ".buildkite"
61-
- "etc"
62-
exclude-files:
63-
- ".*\\.gen\\.go$"
64-
- ".*\\.ridl$"
65-
66-
linters-settings:
67-
sloglint:
68-
# Enforce using attributes only (overrides no-mixed-args, incompatible with kv-only).
69-
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#attributes-only
70-
attr-only: true
71-
errcheck:
72-
# List of functions to exclude from checking, where each entry is a single function to exclude.
73-
# See https://github.com/kisielk/errcheck#excluding-functions for details.
74-
exclude-functions:
75-
- (net/http.ResponseWriter).Write
76-
77-
gci:
78-
# Section configuration to compare against.
79-
# Section names are case-insensitive and may contain parameters in ().
80-
# The default order of sections is `standard > default > custom > blank > dot > alias > localmodule`,
81-
# If `custom-order` is `true`, it follows the order of `sections` option.
82-
# Default: ["standard", "default"]
83-
sections:
84-
- standard # Standard section: captures all standard packages.
85-
- default # Default section: contains all imports that could not be matched to another section type.
86-
- prefix(github.com/0xsequence/go-libs) # Custom section: groups all imports with the specified Prefix.
87-
# Skip generated files.
88-
# Default: true
89-
skip-generated: true
90-
# Enable custom order of sections.
91-
# If `true`, make the section order the same as the order of `sections`.
92-
# Default: false
93-
custom-order: true
94-
# Drops lexical ordering for custom sections.
95-
# Default: false
96-
no-lex-order: false
48+
formatters:
49+
enable:
50+
- gci
51+
settings:
52+
gci:
53+
sections:
54+
- standard
55+
- default
56+
- prefix(github.com/0xsequence/go-libs)
57+
custom-order: true
58+
no-lex-order: false
59+
exclusions:
60+
generated: lax
61+
paths:
62+
- .*\.gen\.go$
63+
- .*\.ridl$
64+
- vendor
65+
- tools
66+
- scripts
67+
- bin
68+
- .buildkite
69+
- etc
70+
- third_party$
71+
- builtin$
72+
- examples$

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.23.4
55
require (
66
github.com/0xsequence/ethkit v1.29.7
77
github.com/0xsequence/go-sequence v0.43.6
8+
github.com/test-go/testify v1.1.4
89
)
910

1011
require (
@@ -14,6 +15,7 @@ require (
1415
github.com/consensys/bavard v0.1.22 // indirect
1516
github.com/consensys/gnark-crypto v0.14.0 // indirect
1617
github.com/crate-crypto/go-kzg-4844 v1.1.0 // indirect
18+
github.com/davecgh/go-spew v1.1.1 // indirect
1719
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
1820
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
1921
github.com/ethereum/c-kzg-4844/bindings/go v0.0.0-20230126171313-363c7d7593b4 // indirect
@@ -24,6 +26,7 @@ require (
2426
github.com/goware/superr v0.0.2 // indirect
2527
github.com/holiman/uint256 v1.3.1 // indirect
2628
github.com/mmcloughlin/addchain v0.4.0 // indirect
29+
github.com/pmezard/go-difflib v1.0.0 // indirect
2730
github.com/supranational/blst v0.3.13 // indirect
2831
golang.org/x/crypto v0.28.0 // indirect
2932
golang.org/x/net v0.29.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
6767
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
6868
github.com/supranational/blst v0.3.13 h1:AYeSxdOMacwu7FBmpfloBz5pbFXDmJL33RuwnKtmTjk=
6969
github.com/supranational/blst v0.3.13/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw=
70+
github.com/test-go/testify v1.1.4 h1:Tf9lntrKUMHiXQ07qBScBTSA0dhYQlu83hswqelv1iE=
71+
github.com/test-go/testify v1.1.4/go.mod h1:rH7cfJo/47vWGdi4GPj16x3/t1xGOj2YxzmNQzk2ghU=
7072
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
7173
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
7274
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=

xlog/xlog.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"log/slog"
77
"math/big"
88
"strconv"
9+
"strings"
910

1011
"github.com/0xsequence/go-sequence/lib/prototyp"
1112

@@ -119,3 +120,24 @@ func ProjectID(projectID uint64) slog.Attr {
119120
func Stringer[T fmt.Stringer](k string, v T) slog.Attr {
120121
return slog.String(k, v.String())
121122
}
123+
124+
func PointerSlice[T any](key string, slice []*T) slog.Attr {
125+
var b strings.Builder
126+
b.WriteString("[")
127+
128+
for i, item := range slice {
129+
if i > 0 {
130+
b.WriteString(" ")
131+
}
132+
133+
if item == nil {
134+
b.WriteString("<nil>")
135+
} else {
136+
b.WriteString(fmt.Sprintf("&%+v", *item))
137+
}
138+
}
139+
140+
b.WriteString("]")
141+
142+
return slog.String(key, b.String())
143+
}

0 commit comments

Comments
 (0)