Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix update version go and interface{} to any #365

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ crane_linux_amd64
crane_linux_arm
crane_linux_arm64
crane_windows_amd64.exe
.idea
10 changes: 5 additions & 5 deletions crane/build_parameters.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package crane

type BuildParameters struct {
RawContext string `json:"context" yaml:"context"`
RawFile string `json:"file" yaml:"file"`
RawDockerfile string `json:"dockerfile" yaml:"dockerfile"`
RawBuildArgs interface{} `json:"build-arg" yaml:"build-arg"`
RawArgs interface{} `json:"args" yaml:"args"`
RawContext string `json:"context" yaml:"context"`
RawFile string `json:"file" yaml:"file"`
RawDockerfile string `json:"dockerfile" yaml:"dockerfile"`
RawBuildArgs any `json:"build-arg" yaml:"build-arg"`
RawArgs any `json:"args" yaml:"args"`
}

func (b BuildParameters) Context() string {
Expand Down
4 changes: 2 additions & 2 deletions crane/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ type Config interface {
}

type config struct {
RawPrefix interface{} `json:"prefix" yaml:"prefix"`
RawPrefix any `json:"prefix" yaml:"prefix"`
RawContainers map[string]*container `json:"services" yaml:"services"`
RawGroups map[string][]string `json:"groups" yaml:"groups"`
RawHooks map[string]hooks `json:"hooks" yaml:"hooks"`
RawNetworks map[string]*network `json:"networks" yaml:"networks"`
RawVolumes map[string]*volume `json:"volumes" yaml:"volumes"`
RawCmds map[string]interface{} `json:"commands" yaml:"commands"`
RawCmds map[string]any `json:"commands" yaml:"commands"`
RawAcceleratedMounts map[string]*acceleratedMount `json:"accelerated-mounts" yaml:"accelerated-mounts"`
RawMacSyncs map[string]*acceleratedMount `json:"mac-syncs" yaml:"mac-syncs"`
containerMap ContainerMap
Expand Down
50 changes: 25 additions & 25 deletions crane/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ type container struct {
RawDNSSearch []string `json:"dns-search" yaml:"dns-search"`
RawDNS_Search []string `json:"dns_search" yaml:"dns_search"`
RawEntrypoint string `json:"entrypoint" yaml:"entrypoint"`
RawEnv interface{} `json:"env" yaml:"env"`
RawEnvironment interface{} `json:"environment" yaml:"environment"`
RawEnv any `json:"env" yaml:"env"`
RawEnvironment any `json:"environment" yaml:"environment"`
RawEnvFile []string `json:"env-file" yaml:"env-file"`
RawEnv_File []string `json:"env_file" yaml:"env_file"`
RawExpose []string `json:"expose" yaml:"expose"`
Expand All @@ -109,8 +109,8 @@ type container struct {
RawIPC string `json:"ipc" yaml:"ipc"`
RawIsolation string `json:"isolation" yaml:"isolation"`
RawKernelMemory string `json:"kernel-memory" yaml:"kernel-memory"`
RawLabel interface{} `json:"label" yaml:"label"`
RawLabels interface{} `json:"labels" yaml:"labels"`
RawLabel any `json:"label" yaml:"label"`
RawLabels any `json:"labels" yaml:"labels"`
RawLabelFile []string `json:"label-file" yaml:"label-file"`
RawLink []string `json:"link" yaml:"link"`
RawLinks []string `json:"links" yaml:"links"`
Expand All @@ -128,7 +128,7 @@ type container struct {
RawNet string `json:"net" yaml:"net"`
RawNetwork_Mode string `json:"network_mode" yaml:"network_mode"`
RawNetAlias []string `json:"net-alias" yaml:"net-alias"`
RawNetworks interface{} `json:"networks" yaml:"networks"`
RawNetworks any `json:"networks" yaml:"networks"`
NoHealthcheck bool `json:"no-healthcheck" yaml:"no-healthcheck"`
OomKillDisable bool `json:"oom-kill-disable" yaml:"oom-kill-disable"`
RawOomScoreAdj string `json:"oom-score-adj" yaml:"oom-score-adj"`
Expand All @@ -152,8 +152,8 @@ type container struct {
RawStop_Signal string `json:"stop_signal" yaml:"stop_signal"`
RawStopTimeout string `json:"stop-timeout" yaml:"stop-timeout"`
RawStop_Grace_Period string `json:"stop_grace_period" yaml:"stop_grace_period"`
RawSysctl interface{} `json:"sysctl" yaml:"sysctl"`
RawSysctls interface{} `json:"sysctls" yaml:"sysctls"`
RawSysctl any `json:"sysctl" yaml:"sysctl"`
RawSysctls any `json:"sysctls" yaml:"sysctls"`
RawTmpfs []string `json:"tmpfs" yaml:"tmpfs"`
Tty bool `json:"tty" yaml:"tty"`
RawUlimit []string `json:"ulimit" yaml:"ulimit"`
Expand All @@ -169,8 +169,8 @@ type container struct {
RawVolumes_From []string `json:"volumes_from" yaml:"volumes_from"`
RawWorkdir string `json:"workdir" yaml:"workdir"`
RawWorking_Dir string `json:"working_dir" yaml:"working_dir"`
RawCmd interface{} `json:"cmd" yaml:"cmd"`
RawCommand interface{} `json:"command" yaml:"command"`
RawCmd any `json:"cmd" yaml:"cmd"`
RawCommand any `json:"command" yaml:"command"`
hooks hooks
networks map[string]NetworkParameters
stdout io.Writer
Expand All @@ -193,7 +193,7 @@ type LogSource struct {
Name string
}

func (o *OptInt) UnmarshalYAML(unmarshal func(interface{}) error) error {
func (o *OptInt) UnmarshalYAML(unmarshal func(any) error) error {
if err := unmarshal(&o.Value); err != nil {
return err
}
Expand All @@ -209,7 +209,7 @@ func (o *OptInt) UnmarshalJSON(b []byte) (err error) {
return
}

func (o *OptBool) UnmarshalYAML(unmarshal func(interface{}) error) error {
func (o *OptBool) UnmarshalYAML(unmarshal func(any) error) error {
if err := unmarshal(&o.Value); err != nil {
return err
}
Expand Down Expand Up @@ -646,18 +646,18 @@ func (c *container) Networks() map[string]NetworkParameters {
value := c.RawNetworks
if value != nil {
switch concreteValue := value.(type) {
case []interface{}: // YAML or JSON: array
case []any: // YAML or JSON: array
for _, v := range concreteValue {
c.networks[v.(string)] = NetworkParameters{}
}
case map[interface{}]interface{}: // YAML: hash
case map[any]any: // YAML: hash
for k, v := range concreteValue {
if v == nil {
c.networks[k.(string)] = NetworkParameters{}
} else {
switch concreteParams := v.(type) {
case map[interface{}]interface{}:
stringMap := make(map[string]interface{})
case map[any]any:
stringMap := make(map[string]any)
for x, y := range concreteParams {
stringMap[x.(string)] = y
}
Expand All @@ -667,13 +667,13 @@ func (c *container) Networks() map[string]NetworkParameters {
}
}
}
case map[string]interface{}: // JSON: hash
case map[string]any: // JSON: hash
for k, v := range concreteValue {
if v == nil {
c.networks[k] = NetworkParameters{}
} else {
switch concreteParams := v.(type) {
case map[string]interface{}:
case map[string]any:
c.networks[k] = createNetworkParemetersFromMap(concreteParams)
default:
panic(StatusError{fmt.Errorf("unknown type: %v", v), 65})
Expand Down Expand Up @@ -1711,31 +1711,31 @@ func containerReference(reference string) (name string) {
}

// Transform an unmarshalled payload (YAML or JSON) of type slice or map to a slice of env-expanded "K=V" strings
func sliceOrMap2ExpandedSlice(value interface{}) []string {
func sliceOrMap2ExpandedSlice(value any) []string {
var result []string
expandedStringOrPanic := func(v interface{}) string {
expandedStringOrPanic := func(v any) string {
switch concreteValue := v.(type) {
case []interface{}: // YAML or JSON
case []any: // YAML or JSON
panic(StatusError{fmt.Errorf("unknown type: %v", v), 65})
case map[interface{}]interface{}: // YAML
case map[any]any: // YAML
panic(StatusError{fmt.Errorf("unknown type: %v", v), 65})
case map[string]interface{}: // JSON
case map[string]any: // JSON
panic(StatusError{fmt.Errorf("unknown type: %v", v), 65})
default:
return expandEnv(fmt.Sprintf("%v", concreteValue))
}
}
if value != nil {
switch concreteValue := value.(type) {
case []interface{}: // YAML or JSON: array
case []any: // YAML or JSON: array
for _, v := range concreteValue {
result = append(result, expandedStringOrPanic(v))
}
case map[interface{}]interface{}: // YAML: hash
case map[any]any: // YAML: hash
for k, v := range concreteValue {
result = append(result, expandedStringOrPanic(k)+"="+expandedStringOrPanic(v))
}
case map[string]interface{}: // JSON: hash
case map[string]any: // JSON: hash
for k, v := range concreteValue {
result = append(result, expandEnv(k)+"="+expandedStringOrPanic(v))
}
Expand Down
4 changes: 2 additions & 2 deletions crane/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func TestCmd(t *testing.T) {
// Array
os.Clearenv()
os.Setenv("CMD", "1")
c = &container{RawCmd: []interface{}{"echo", "$CMD", "$$CMD"}}
c = &container{RawCmd: []any{"echo", "$CMD", "$$CMD"}}
assert.Equal(t, []string{"echo", "1", "$CMD"}, c.Cmd())
}

Expand Down Expand Up @@ -317,7 +317,7 @@ func TestOptBoolYAML(t *testing.T) {

func TestBuildArgs(t *testing.T) {
var c *container
c = &container{RawBuild: BuildParameters{RawBuildArgs: []interface{}{"key1=value1"}}}
c = &container{RawBuild: BuildParameters{RawBuildArgs: []any{"key1=value1"}}}
cfg = &config{path: "foo"}
assert.Equal(t, "key1=value1", c.BuildParams().BuildArgs()[0])
}
14 changes: 7 additions & 7 deletions crane/crane.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
shlex "github.com/flynn/go-shlex"
)

var printSuccessf func(format string, a ...interface{})
var printInfof func(format string, a ...interface{})
var printNoticef func(format string, a ...interface{})
var printErrorf func(format string, a ...interface{})
var printSuccessf func(format string, a ...any)
var printInfof func(format string, a ...any)
var printNoticef func(format string, a ...any)
var printErrorf func(format string, a ...any)

func init() {
color.Output = os.Stderr
Expand All @@ -33,7 +33,7 @@ type StatusError struct {
status int
}

func handleRecoveredError(recovered interface{}) {
func handleRecoveredError(recovered any) {
if recovered == nil {
return
}
Expand Down Expand Up @@ -98,7 +98,7 @@ func checkDockerClient() {
}

// Assemble slice of strings from slice or string with spaces
func stringSlice(sliceLike interface{}) []string {
func stringSlice(sliceLike any) []string {
var strSlice []string
switch sl := sliceLike.(type) {
case string:
Expand All @@ -109,7 +109,7 @@ func stringSlice(sliceLike interface{}) []string {
}
strSlice = append(strSlice, parts...)
}
case []interface{}:
case []any:
parts := make([]string, len(sl))
for i, v := range sl {
parts[i] = expandEnv(fmt.Sprintf("%v", v))
Expand Down
4 changes: 2 additions & 2 deletions crane/logging_parameters.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package crane

type LoggingParameters struct {
RawDriver string `json:"driver" yaml:"driver"`
RawOptions interface{} `json:"options" yaml:"options"`
RawDriver string `json:"driver" yaml:"driver"`
RawOptions any `json:"options" yaml:"options"`
}

func (l LoggingParameters) Options() []string {
Expand Down
18 changes: 9 additions & 9 deletions crane/network_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package crane
import "fmt"

type NetworkParameters struct {
RawAlias interface{} `json:"alias" yaml:"alias"`
RawAliases interface{} `json:"aliases" yaml:"aliases"`
RawIp string `json:"ip" yaml:"ip"`
RawIpv4Address string `json:"ipv4_address" yaml:"ipv4_address"`
RawIp6 string `json:"ip6" yaml:"ip6"`
RawIpv6Address string `json:"ipv6_address" yaml:"ipv6_address"`
RawAlias any `json:"alias" yaml:"alias"`
RawAliases any `json:"aliases" yaml:"aliases"`
RawIp string `json:"ip" yaml:"ip"`
RawIpv4Address string `json:"ipv4_address" yaml:"ipv4_address"`
RawIp6 string `json:"ip6" yaml:"ip6"`
RawIpv6Address string `json:"ipv6_address" yaml:"ipv6_address"`
}

// If aliases are not defined in the config,
Expand All @@ -26,7 +26,7 @@ func (n NetworkParameters) Alias(containerName string) []string {
aliases = append(aliases, containerName)
} else {
switch concreteValue := rawAliases.(type) {
case []interface{}:
case []any:
for _, v := range concreteValue {
aliases = append(aliases, expandEnv(v.(string)))
}
Expand All @@ -49,14 +49,14 @@ func (n NetworkParameters) Ip6() string {
return expandEnv(n.RawIpv6Address)
}

func createNetworkParemetersFromMap(val map[string]interface{}) NetworkParameters {
func createNetworkParemetersFromMap(val map[string]any) NetworkParameters {
var params NetworkParameters
if val == nil {
params = NetworkParameters{}
} else {
for k, v := range val {
if k == "alias" || k == "aliases" {
params.RawAlias = v.([]interface{})
params.RawAlias = v.([]any)
} else if k == "ip" || k == "ipv4_address" {
params.RawIp = v.(string)
} else if k == "ip6" || k == "ipv6_address" {
Expand Down
2 changes: 1 addition & 1 deletion crane/unit_of_work.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (uow *UnitOfWork) Generate(templateFile string, output string) {
return
}

executeTemplate := func(outputFile string, templateInfo interface{}) {
executeTemplate := func(outputFile string, templateInfo any) {
writer := os.Stdout
if len(outputFile) > 0 {
writer, _ = os.Create(outputFile)
Expand Down
17 changes: 10 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ module github.com/michaelsauter/crane/v3

require (
github.com/alecthomas/kingpin v2.2.6+incompatible
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect
github.com/bjaglin/multiplexio v0.0.0-20141123221749-7477705f395a
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.7.0
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568
github.com/hashicorp/go-uuid v1.0.0
github.com/imdario/mergo v0.3.6
github.com/stretchr/testify v1.2.2
gopkg.in/yaml.v2 v2.2.2
)

require (
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/mattn/go-colorable v0.0.9 // indirect
github.com/mattn/go-isatty v0.0.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.2.2
gopkg.in/yaml.v2 v2.2.2
golang.org/x/sys v0.6.0 // indirect
)

go 1.16
go 1.19
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/hashicorp/go-uuid v1.0.0 h1:RS8zrF7PhGwyNPOtxSClXXj9HA8feRnJzgnI1RJCSnM=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28=
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
Expand All @@ -24,6 +22,9 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=