mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
chore: modernize the codebase using go 1.26 (#278)
This runs: ``` go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix ./... ``` over the codebase, as this is using go 1.26, it can also use the new new() functionallity so AsPtr and boolPtr is are needed anymore. Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
+3
-1
@@ -62,6 +62,8 @@ type VolumeClient interface {
|
||||
}
|
||||
|
||||
// AsPtr returns a pointer to the given value. Useful for optional fields in API structs.
|
||||
//
|
||||
//go:fix inline
|
||||
func AsPtr[T any](v T) *T {
|
||||
return &v
|
||||
return new(v)
|
||||
}
|
||||
|
||||
@@ -8,11 +8,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// uint64Ptr is a convenience function to create a pointer to a uint64 value
|
||||
func uint64Ptr(v uint64) *uint64 {
|
||||
return &v
|
||||
}
|
||||
|
||||
func TestConfigMount_GetNumericUid(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -30,12 +25,12 @@ func TestConfigMount_GetNumericUid(t *testing.T) {
|
||||
{
|
||||
name: "valid numeric uid",
|
||||
uid: "1000",
|
||||
expected: uint64Ptr(1000),
|
||||
expected: new(uint64(1000)),
|
||||
},
|
||||
{
|
||||
name: "zero uid",
|
||||
uid: "0",
|
||||
expected: uint64Ptr(0),
|
||||
expected: new(uint64(0)),
|
||||
},
|
||||
{
|
||||
name: "invalid non-numeric uid",
|
||||
@@ -96,12 +91,12 @@ func TestConfigMount_GetNumericGid(t *testing.T) {
|
||||
{
|
||||
name: "valid numeric gid",
|
||||
gid: "1000",
|
||||
expected: uint64Ptr(1000),
|
||||
expected: new(uint64(1000)),
|
||||
},
|
||||
{
|
||||
name: "zero gid",
|
||||
gid: "0",
|
||||
expected: uint64Ptr(0),
|
||||
expected: new(uint64(0)),
|
||||
},
|
||||
{
|
||||
name: "invalid non-numeric gid",
|
||||
|
||||
+3
-7
@@ -73,7 +73,7 @@ type ServiceSpec struct {
|
||||
// Default is 10 seconds if not specified.
|
||||
StopGracePeriod *time.Duration `json:",omitempty"`
|
||||
// UpdateConfig configures how the service is updated during a deployment.
|
||||
UpdateConfig UpdateConfig `json:",omitempty"`
|
||||
UpdateConfig UpdateConfig
|
||||
// Volumes is list of data volumes that can be mounted into the container.
|
||||
Volumes []VolumeSpec
|
||||
}
|
||||
@@ -348,9 +348,7 @@ func (s *ContainerSpec) Clone() ContainerSpec {
|
||||
}
|
||||
if s.Env != nil {
|
||||
spec.Env = make(EnvVars, len(s.Env))
|
||||
for k, v := range s.Env {
|
||||
spec.Env[k] = v
|
||||
}
|
||||
maps.Copy(spec.Env, s.Env)
|
||||
}
|
||||
if s.Healthcheck != nil {
|
||||
hc := *s.Healthcheck
|
||||
@@ -380,9 +378,7 @@ func (s *ContainerSpec) Clone() ContainerSpec {
|
||||
}
|
||||
if s.Sysctls != nil {
|
||||
spec.Sysctls = make(map[string]string, len(s.Sysctls))
|
||||
for k, v := range s.Sysctls {
|
||||
spec.Sysctls[k] = v
|
||||
}
|
||||
maps.Copy(spec.Sysctls, s.Sysctls)
|
||||
}
|
||||
if s.Resources.Ulimits != nil {
|
||||
spec.Resources.Ulimits = maps.Clone(s.Resources.Ulimits)
|
||||
|
||||
@@ -9,12 +9,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// boolPtr is a convenience function to create a pointer to a uint64 value
|
||||
// TODO: Make this a generic function that works for any type
|
||||
func boolPtr(b bool) *bool {
|
||||
return &b
|
||||
}
|
||||
|
||||
func TestServiceSpec_Validate_CaddyAndPorts(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -219,7 +213,7 @@ func TestContainerSpec_Clone(t *testing.T) {
|
||||
"BAZ": "qux",
|
||||
},
|
||||
Image: "nginx:latest",
|
||||
Init: boolPtr(true),
|
||||
Init: new(true),
|
||||
LogDriver: &LogDriver{
|
||||
Name: "json-file",
|
||||
Options: map[string]string{
|
||||
|
||||
+3
-6
@@ -2,6 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"maps"
|
||||
"reflect"
|
||||
"slices"
|
||||
"sort"
|
||||
@@ -165,18 +166,14 @@ func (v *VolumeSpec) Clone() VolumeSpec {
|
||||
driver := *v.VolumeOptions.Driver
|
||||
if driver.Options != nil {
|
||||
driver.Options = make(map[string]string, len(v.VolumeOptions.Driver.Options))
|
||||
for k, val := range v.VolumeOptions.Driver.Options {
|
||||
driver.Options[k] = val
|
||||
}
|
||||
maps.Copy(driver.Options, v.VolumeOptions.Driver.Options)
|
||||
}
|
||||
opts.Driver = &driver
|
||||
}
|
||||
|
||||
if opts.Labels != nil {
|
||||
opts.Labels = make(map[string]string, len(v.VolumeOptions.Labels))
|
||||
for k, val := range v.VolumeOptions.Labels {
|
||||
opts.Labels[k] = val
|
||||
}
|
||||
maps.Copy(opts.Labels, v.VolumeOptions.Labels)
|
||||
}
|
||||
|
||||
spec.VolumeOptions = &opts
|
||||
|
||||
Reference in New Issue
Block a user