Skip to content

Commit 196d9c7

Browse files
authored
Merge pull request #433 from ryanfowler/go-fix
Run go fix
2 parents 1c25e7b + d72271e commit 196d9c7

15 files changed

Lines changed: 111 additions & 139 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Lint
3434
uses: dominikh/staticcheck-action@v1.4.0
3535
with:
36-
version: "2025.1.1"
36+
version: "2026.1"
3737
install-go: false
3838

3939
test:

integration/integration_test.go

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ import (
3434
"testing"
3535
"time"
3636

37-
"github.com/ryanfowler/fetch/internal/core"
38-
3937
"github.com/coder/websocket"
4038
"github.com/klauspost/compress/gzip"
4139
"github.com/klauspost/compress/zstd"
@@ -750,7 +748,7 @@ func TestMain(t *testing.T) {
750748
t.Run("range request", func(t *testing.T) {
751749
t.Parallel()
752750
var expectedRange atomic.Pointer[string]
753-
expectedRange.Store(core.PointerTo(""))
751+
expectedRange.Store(new(""))
754752
server := startServer(func(w http.ResponseWriter, r *http.Request) {
755753
exp := expectedRange.Load()
756754
if r.Header.Get("Range") != *exp {
@@ -769,22 +767,22 @@ func TestMain(t *testing.T) {
769767
assertExitCode(t, 0, res)
770768

771769
// Range header with no start.
772-
expectedRange.Store(core.PointerTo("bytes=-1023"))
770+
expectedRange.Store(new("bytes=-1023"))
773771
res = runFetch(t, fetchPath, server.URL, "--range", "-1023")
774772
assertExitCode(t, 0, res)
775773

776774
// Range header with no end.
777-
expectedRange.Store(core.PointerTo("bytes=1023-"))
775+
expectedRange.Store(new("bytes=1023-"))
778776
res = runFetch(t, fetchPath, server.URL, "--range", "1023-")
779777
assertExitCode(t, 0, res)
780778

781779
// Range header with start and end.
782-
expectedRange.Store(core.PointerTo("bytes=0-1023"))
780+
expectedRange.Store(new("bytes=0-1023"))
783781
res = runFetch(t, fetchPath, server.URL, "--range", "0-1023")
784782
assertExitCode(t, 0, res)
785783

786784
// Multiple ranges.
787-
expectedRange.Store(core.PointerTo("bytes=0-1023, 2047-3070"))
785+
expectedRange.Store(new("bytes=0-1023, 2047-3070"))
788786
res = runFetch(t, fetchPath, server.URL, "-r", "0-1023", "-r", "2047-3070")
789787
assertExitCode(t, 0, res)
790788
})
@@ -1092,39 +1090,39 @@ func TestMain(t *testing.T) {
10921090
fds := &descriptorpb.FileDescriptorSet{
10931091
File: []*descriptorpb.FileDescriptorProto{
10941092
{
1095-
Name: strPtr("stream.proto"),
1096-
Package: strPtr("streampkg"),
1097-
Syntax: strPtr("proto3"),
1093+
Name: new("stream.proto"),
1094+
Package: new("streampkg"),
1095+
Syntax: new("proto3"),
10981096
MessageType: []*descriptorpb.DescriptorProto{
10991097
{
1100-
Name: strPtr("StreamRequest"),
1098+
Name: new("StreamRequest"),
11011099
Field: []*descriptorpb.FieldDescriptorProto{
11021100
{
1103-
Name: strPtr("value"),
1104-
Number: int32Ptr(1),
1101+
Name: new("value"),
1102+
Number: new(int32(1)),
11051103
Type: &strType,
11061104
},
11071105
},
11081106
},
11091107
{
1110-
Name: strPtr("StreamResponse"),
1108+
Name: new("StreamResponse"),
11111109
Field: []*descriptorpb.FieldDescriptorProto{
11121110
{
1113-
Name: strPtr("count"),
1114-
Number: int32Ptr(1),
1111+
Name: new("count"),
1112+
Number: new(int32(1)),
11151113
Type: &int64Type,
11161114
},
11171115
},
11181116
},
11191117
},
11201118
Service: []*descriptorpb.ServiceDescriptorProto{
11211119
{
1122-
Name: strPtr("StreamService"),
1120+
Name: new("StreamService"),
11231121
Method: []*descriptorpb.MethodDescriptorProto{
11241122
{
1125-
Name: strPtr("ClientStream"),
1126-
InputType: strPtr(".streampkg.StreamRequest"),
1127-
OutputType: strPtr(".streampkg.StreamResponse"),
1123+
Name: new("ClientStream"),
1124+
InputType: new(".streampkg.StreamRequest"),
1125+
OutputType: new(".streampkg.StreamResponse"),
11281126
ClientStreaming: &boolTrue,
11291127
},
11301128
},
@@ -3196,6 +3194,3 @@ func startMTLSServer(t *testing.T, certPath, keyPath, caCertPath string) *httpte
31963194
server.StartTLS()
31973195
return server
31983196
}
3199-
3200-
func strPtr(s string) *string { return &s }
3201-
func int32Ptr(i int32) *int32 { return &i }

internal/cli/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ func (a *App) parseRangeFlag(value string) error {
536536

537537
func (a *App) parseVerboseFlag(string) error {
538538
if a.Cfg.Verbosity == nil {
539-
a.Cfg.Verbosity = core.PointerTo(1)
539+
a.Cfg.Verbosity = new(1)
540540
} else {
541541
(*a.Cfg.Verbosity)++
542542
}

internal/cli/cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ func (a *App) applyFromCurl(r *curl.Result) error {
680680
a.Cfg.Retry = &r.Retry
681681
}
682682
if r.RetryDelay > 0 {
683-
a.Cfg.RetryDelay = core.PointerTo(time.Duration(float64(time.Second) * r.RetryDelay))
683+
a.Cfg.RetryDelay = new(time.Duration(float64(time.Second) * r.RetryDelay))
684684
}
685685

686686
// Ranges.

internal/cli/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func ptrBoolFlag(target **bool, long, short, desc string) Flag {
2828
return *target != nil
2929
},
3030
Fn: func(string) error {
31-
*target = core.PointerTo(true)
31+
*target = new(true)
3232
return nil
3333
},
3434
}

internal/config/config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ func (c *Config) ParseAutoUpdate(value string) error {
207207
v, err := strconv.ParseBool(value)
208208
if err == nil {
209209
if v {
210-
c.AutoUpdate = core.PointerTo(24 * time.Hour)
210+
c.AutoUpdate = new(24 * time.Hour)
211211
} else {
212-
c.AutoUpdate = core.PointerTo(time.Duration(-1))
212+
c.AutoUpdate = new(time.Duration(-1))
213213
}
214214
return nil
215215
}
@@ -310,7 +310,7 @@ func (c *Config) ParseConnectTimeout(value string) error {
310310
if err != nil || secs < 0 {
311311
return core.NewValueError("connect-timeout", value, "must be a non-negative number", c.isFile)
312312
}
313-
c.ConnectTimeout = core.PointerTo(time.Duration(float64(time.Second) * secs))
313+
c.ConnectTimeout = new(time.Duration(float64(time.Second) * secs))
314314
return nil
315315
}
316316

@@ -501,7 +501,7 @@ func (c *Config) ParseRetryDelay(value string) error {
501501
if err != nil || secs < 0 {
502502
return core.NewValueError("retry-delay", value, "must be a non-negative number", c.isFile)
503503
}
504-
c.RetryDelay = core.PointerTo(time.Duration(float64(time.Second) * secs))
504+
c.RetryDelay = new(time.Duration(float64(time.Second) * secs))
505505
return nil
506506
}
507507

@@ -528,7 +528,7 @@ func (c *Config) ParseTimeout(value string) error {
528528
if err != nil {
529529
return core.NewValueError("timeout", value, "must be a valid number", c.isFile)
530530
}
531-
c.Timeout = core.PointerTo(time.Duration(float64(time.Second) * secs))
531+
c.Timeout = new(time.Duration(float64(time.Second) * secs))
532532
return nil
533533
}
534534

internal/config/file_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestParseFile(t *testing.T) {
2626
Hosts: map[string]*Config{
2727
"*.example.com": {
2828
isFile: true,
29-
Insecure: core.PointerTo(true),
29+
Insecure: new(true),
3030
},
3131
},
3232
Path: "test/config",
@@ -60,8 +60,8 @@ func TestParseFile(t *testing.T) {
6060
expFile: &File{
6161
Global: &Config{
6262
isFile: true,
63-
Timeout: core.PointerTo(10 * time.Second),
64-
TLS: core.PointerTo(uint16(tls.VersionTLS13)),
63+
Timeout: new(10 * time.Second),
64+
TLS: new(uint16(tls.VersionTLS13)),
6565
},
6666
Path: "test/config",
6767
},
@@ -82,16 +82,16 @@ func TestParseFile(t *testing.T) {
8282
Global: &Config{
8383
isFile: true,
8484
Color: core.ColorOff,
85-
NoPager: core.PointerTo(true),
85+
NoPager: new(true),
8686
},
8787
Hosts: map[string]*Config{
8888
"example.com": {
8989
isFile: true,
90-
Insecure: core.PointerTo(true),
90+
Insecure: new(true),
9191
},
9292
"anotherhost.com": {
9393
isFile: true,
94-
IgnoreStatus: core.PointerTo(true),
94+
IgnoreStatus: new(true),
9595
},
9696
},
9797
Path: "test/config",
@@ -127,9 +127,9 @@ func TestParseFile(t *testing.T) {
127127
}
128128

129129
func TestFileHostConfig(t *testing.T) {
130-
exactCfg := &Config{isFile: true, Insecure: core.PointerTo(true)}
131-
wildcardCfg := &Config{isFile: true, Insecure: core.PointerTo(false)}
132-
specificWildcardCfg := &Config{isFile: true, NoPager: core.PointerTo(true)}
130+
exactCfg := &Config{isFile: true, Insecure: new(true)}
131+
wildcardCfg := &Config{isFile: true, Insecure: new(false)}
132+
specificWildcardCfg := &Config{isFile: true, NoPager: new(true)}
133133

134134
f := &File{
135135
Global: &Config{isFile: true},

internal/core/core.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ type KeyVal[T any] struct {
7373
Val T
7474
}
7575

76-
// PointerTo returns a pointer to the value provided.
77-
func PointerTo[T any](t T) *T {
78-
return &t
79-
}
80-
8176
// CutTrimmed splits s around the first instance of sep, returning the
8277
// trimmed text before and after sep.
8378
func CutTrimmed(s, sep string) (string, string, bool) {

internal/fetch/print_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ func TestPrintRequestMetadataPrefixes(t *testing.T) {
5656
printRequestMetadata(p, req, core.HTTPDefault, core.VDebug)
5757
out := string(p.Bytes())
5858

59-
lines := strings.Split(strings.TrimRight(out, "\n"), "\n")
60-
for _, line := range lines {
59+
lines := strings.SplitSeq(strings.TrimRight(out, "\n"), "\n")
60+
for line := range lines {
6161
if !strings.HasPrefix(line, "> ") {
6262
t.Errorf("expected '> ' prefix on line %q", line)
6363
}
@@ -111,8 +111,8 @@ func TestPrintResponseMetadataPrefixes(t *testing.T) {
111111
printResponseMetadata(p, core.VDebug, resp)
112112
out := string(p.Bytes())
113113

114-
lines := strings.Split(strings.TrimRight(out, "\n"), "\n")
115-
for _, line := range lines {
114+
lines := strings.SplitSeq(strings.TrimRight(out, "\n"), "\n")
115+
for line := range lines {
116116
if !strings.HasPrefix(line, "< ") {
117117
t.Errorf("expected '< ' prefix on line %q", line)
118118
}
@@ -157,8 +157,8 @@ func TestPrintResponseHeadersPrefix(t *testing.T) {
157157
printResponseHeaders(p, resp, true)
158158
out := string(p.Bytes())
159159

160-
lines := strings.Split(strings.TrimRight(out, "\n"), "\n")
161-
for _, line := range lines {
160+
lines := strings.SplitSeq(strings.TrimRight(out, "\n"), "\n")
161+
for line := range lines {
162162
if !strings.HasPrefix(line, "< ") {
163163
t.Errorf("expected '< ' prefix on line %q", line)
164164
}

internal/fetch/proto_test.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,21 @@ func testMessageDescriptor(t *testing.T) protoreflect.MessageDescriptor {
9696
fds := &descriptorpb.FileDescriptorSet{
9797
File: []*descriptorpb.FileDescriptorProto{
9898
{
99-
Name: strp("test.proto"),
100-
Package: strp("testpkg"),
101-
Syntax: strp("proto3"),
99+
Name: new("test.proto"),
100+
Package: new("testpkg"),
101+
Syntax: new("proto3"),
102102
MessageType: []*descriptorpb.DescriptorProto{
103103
{
104-
Name: strp("TestMessage"),
104+
Name: new("TestMessage"),
105105
Field: []*descriptorpb.FieldDescriptorProto{
106106
{
107-
Name: strp("id"),
108-
Number: int32p(1),
107+
Name: new("id"),
108+
Number: new(int32(1)),
109109
Type: &int64Type,
110110
},
111111
{
112-
Name: strp("name"),
113-
Number: int32p(2),
112+
Name: new("name"),
113+
Number: new(int32(2)),
114114
Type: &strType,
115115
},
116116
},
@@ -154,6 +154,3 @@ func readAllFrames(t *testing.T, r io.Reader) [][]byte {
154154
}
155155
return frames
156156
}
157-
158-
func strp(s string) *string { return &s }
159-
func int32p(i int32) *int32 { return &i }

0 commit comments

Comments
 (0)