Extract api types to version packages.

Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
David Calavera
2015-09-30 14:14:27 -04:00
parent 85244f80e3
commit 61634758c4
8 changed files with 82 additions and 51 deletions
-8
View File
@@ -96,14 +96,6 @@ type Stats struct {
BlkioStats BlkioStats `json:"blkio_stats,omitempty"`
}
// StatsJSONPre121 is a backcompatibility struct along with ContainerConfig
type StatsJSONPre121 struct {
Stats
// Network is for fallback stats where API Version < 1.21
Network NetworkStats `json:"network,omitempty"`
}
// StatsJSON is newly used Networks
type StatsJSON struct {
Stats
-35
View File
@@ -277,41 +277,6 @@ type ContainerJSON struct {
Config *runconfig.Config
}
// ContainerJSON120 is a backcompatibility struct along with ContainerConfig120.
type ContainerJSON120 struct {
*ContainerJSONBase
Mounts []MountPoint
Config *ContainerConfig120
}
// ContainerJSONPre120 is a backcompatibility struct along with ContainerConfigPre120.
// Note this is not used by the Windows daemon.
type ContainerJSONPre120 struct {
*ContainerJSONBase
Volumes map[string]string
VolumesRW map[string]bool
Config *ContainerConfigPre120
}
// ContainerConfigPre120 is a backcompatibility struct used in ContainerJSONPre120
type ContainerConfigPre120 struct {
*runconfig.Config
// backward compatibility, they now live in HostConfig
VolumeDriver string
Memory int64
MemorySwap int64
CPUShares int64 `json:"CpuShares"`
CPUSet string `json:"CpuSet"`
}
// ContainerConfig120 is a backcompatibility struct used in ContainerJSON120
type ContainerConfig120 struct {
*runconfig.Config
// backward compatibility, it lives now in HostConfig
VolumeDriver string
}
// MountPoint represents a mount point configuration inside the container.
type MountPoint struct {
Name string `json:",omitempty"`
+14
View File
@@ -0,0 +1,14 @@
## Legacy API type versions
This package includes types for legacy API versions. The stable version of the API types live in `api/types/*.go`.
Consider moving a type here when you need to keep backwards compatibility in the API. This legacy types are organized by the latest API version they appear in. For instance, types in the `v1p19` package are valid for API versions below or equal `1.19`. Types in the `v1p20` package are valid for the API version `1.20`, since the versions below that will use the legacy types in `v1p19`.
### Package name conventions
The package name convention is to use `v` as a prefix for the version number and `p`(patch) as a separator. We use this nomenclature due to a few restrictions in the Go package name convention:
1. We cannot use `.` because it's interpreted by the language, think of `v1.20.CallFunction`.
2. We cannot use `_` because golint complains abount it. The code is actually valid, but it looks probably more weird: `v1_20.CallFunction`.
For instance, if you want to modify a type that was available in the version `1.21` of the API but it will have different fields in the version `1.22`, you want to create a new package under `api/types/versions/v1p21`.
+28
View File
@@ -0,0 +1,28 @@
// Package v1p19 provides specific API types for the API version 1, patch 19.
package v1p19
import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/runconfig"
)
// ContainerJSON is a backcompatibility struct for APIs prior to 1.20.
// Note this is not used by the Windows daemon.
type ContainerJSON struct {
*types.ContainerJSONBase
Volumes map[string]string
VolumesRW map[string]bool
Config *ContainerConfig
}
// ContainerConfig is a backcompatibility struct for APIs prior to 1.20.
type ContainerConfig struct {
*runconfig.Config
// backward compatibility, they now live in HostConfig
VolumeDriver string
Memory int64
MemorySwap int64
CPUShares int64 `json:"CpuShares"`
CPUSet string `json:"CpuSet"`
}
+27
View File
@@ -0,0 +1,27 @@
// Package v1p20 provides specific API types for the API version 1, patch 20.
package v1p20
import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/runconfig"
)
// ContainerJSON is a backcompatibility struct for the API 1.20
type ContainerJSON struct {
*types.ContainerJSONBase
Mounts []types.MountPoint
Config *ContainerConfig
}
// ContainerConfig is a backcompatibility struct used in ContainerJSON for the API 1.20
type ContainerConfig struct {
*runconfig.Config
// backward compatibility, it lives now in HostConfig
VolumeDriver string
}
// StatsJSON is a backcompatibility struct used in Stats for API prior to 1.21
type StatsJSON struct {
types.Stats
Network types.NetworkStats `json:"network,omitempty"`
}