mirror of
https://github.com/opencontainers/runc.git
synced 2025-09-26 19:41:35 +08:00
Use any instead of interface{}
The keyword is available since Go 1.18 (see https://pkg.go.dev/builtin#any). Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -503,7 +503,7 @@ func (hooks *Hooks) MarshalJSON() ([]byte, error) {
|
|||||||
return serializableHooks
|
return serializableHooks
|
||||||
}
|
}
|
||||||
|
|
||||||
return json.Marshal(map[string]interface{}{
|
return json.Marshal(map[string]any{
|
||||||
"prestart": serialize((*hooks)[Prestart]),
|
"prestart": serialize((*hooks)[Prestart]),
|
||||||
"createRuntime": serialize((*hooks)[CreateRuntime]),
|
"createRuntime": serialize((*hooks)[CreateRuntime]),
|
||||||
"createContainer": serialize((*hooks)[CreateContainer]),
|
"createContainer": serialize((*hooks)[CreateContainer]),
|
||||||
|
@@ -81,7 +81,7 @@ func TestFactoryLoadContainer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func marshal(path string, v interface{}) error {
|
func marshal(path string, v any) error {
|
||||||
f, err := os.Create(path)
|
f, err := os.Create(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@@ -676,7 +676,7 @@ func TestInitSystemdProps(t *testing.T) {
|
|||||||
type expT struct {
|
type expT struct {
|
||||||
isErr bool
|
isErr bool
|
||||||
name string
|
name string
|
||||||
value interface{}
|
value any
|
||||||
}
|
}
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
@@ -24,7 +24,7 @@ func TestStateStatus(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testTransitions(t *testing.T, initialState containerState, valid []containerState) {
|
func testTransitions(t *testing.T, initialState containerState, valid []containerState) {
|
||||||
validMap := map[reflect.Type]interface{}{}
|
validMap := map[reflect.Type]any{}
|
||||||
for _, validState := range valid {
|
for _, validState := range valid {
|
||||||
validMap[reflect.TypeOf(validState)] = nil
|
validMap[reflect.TypeOf(validState)] = nil
|
||||||
t.Run(validState.status().String(), func(t *testing.T) {
|
t.Run(validState.status().String(), func(t *testing.T) {
|
||||||
|
@@ -113,7 +113,7 @@ func writeSync(pipe *syncSocket, sync syncType) error {
|
|||||||
return doWriteSync(pipe, syncT{Type: sync})
|
return doWriteSync(pipe, syncT{Type: sync})
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeSyncArg(pipe *syncSocket, sync syncType, arg interface{}) error {
|
func writeSyncArg(pipe *syncSocket, sync syncType, arg any) error {
|
||||||
argJSON, err := json.Marshal(arg)
|
argJSON, err := json.Marshal(arg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("writing sync %v: marshal argument failed: %w", sync, err)
|
return fmt.Errorf("writing sync %v: marshal argument failed: %w", sync, err)
|
||||||
|
@@ -27,7 +27,7 @@ func ExitStatus(status unix.WaitStatus) int {
|
|||||||
// without a trailing newline. This is used instead of json.Encoder because
|
// without a trailing newline. This is used instead of json.Encoder because
|
||||||
// there might be a problem in json decoder in some cases, see:
|
// there might be a problem in json decoder in some cases, see:
|
||||||
// https://github.com/docker/docker/issues/14203#issuecomment-174177790
|
// https://github.com/docker/docker/issues/14203#issuecomment-174177790
|
||||||
func WriteJSON(w io.Writer, v interface{}) error {
|
func WriteJSON(w io.Writer, v any) error {
|
||||||
data, err := json.Marshal(v)
|
data, err := json.Marshal(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
2
tty.go
2
tty.go
@@ -44,7 +44,7 @@ func setupProcessPipes(p *libcontainer.Process, rootuid, rootgid int) (*tty, err
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
// add the process's io to the post start closers if they support close
|
// add the process's io to the post start closers if they support close
|
||||||
for _, cc := range []interface{}{
|
for _, cc := range []any{
|
||||||
p.Stdin,
|
p.Stdin,
|
||||||
p.Stdout,
|
p.Stdout,
|
||||||
p.Stderr,
|
p.Stderr,
|
||||||
|
@@ -7,9 +7,9 @@ import (
|
|||||||
|
|
||||||
// Event struct for encoding the event data to json.
|
// Event struct for encoding the event data to json.
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Data interface{} `json:"data,omitempty"`
|
Data any `json:"data,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stats is the runc specific stats structure for stability when encoding and decoding stats.
|
// Stats is the runc specific stats structure for stability when encoding and decoding stats.
|
||||||
|
Reference in New Issue
Block a user