diff options
Diffstat (limited to 'pkg')
142 files changed, 583 insertions, 5186 deletions
diff --git a/pkg/api/handlers/compat/containers_archive.go b/pkg/api/handlers/compat/containers_archive.go index 083c72ce8..55bd62f90 100644 --- a/pkg/api/handlers/compat/containers_archive.go +++ b/pkg/api/handlers/compat/containers_archive.go @@ -62,7 +62,7 @@ func handleHeadAndGet(w http.ResponseWriter, r *http.Request, decoder *schema.De w.Header().Add(copy.XDockerContainerPathStatHeader, statHeader) } - if errors.Cause(err) == define.ErrNoSuchCtr || errors.Cause(err) == copy.ENOENT { + if errors.Cause(err) == define.ErrNoSuchCtr || errors.Cause(err) == copy.ErrENOENT { // 404 is returned for an absent container and path. The // clients must deal with it accordingly. utils.Error(w, "Not found.", http.StatusNotFound, err) diff --git a/pkg/api/handlers/compat/containers_create.go b/pkg/api/handlers/compat/containers_create.go index 6e85872b2..4a39e9563 100644 --- a/pkg/api/handlers/compat/containers_create.go +++ b/pkg/api/handlers/compat/containers_create.go @@ -47,6 +47,7 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) { rtc, err := runtime.GetConfig() if err != nil { utils.Error(w, "unable to obtain runtime config", http.StatusInternalServerError, errors.Wrap(err, "unable to get runtime config")) + return } newImage, err := runtime.ImageRuntime().NewFromLocal(body.Config.Image) diff --git a/pkg/api/handlers/compat/events.go b/pkg/api/handlers/compat/events.go index 82a74e419..7dad5f566 100644 --- a/pkg/api/handlers/compat/events.go +++ b/pkg/api/handlers/compat/events.go @@ -111,7 +111,6 @@ func GetEvents(w http.ResponseWriter, r *http.Request) { Until: query.Until, } errorChannel <- runtime.Events(r.Context(), readOpts) - }() var flush = func() {} diff --git a/pkg/api/handlers/compat/images.go b/pkg/api/handlers/compat/images.go index 0ae0f3bcf..0d75d1a94 100644 --- a/pkg/api/handlers/compat/images.go +++ b/pkg/api/handlers/compat/images.go @@ -10,7 +10,6 @@ import ( "strings" "github.com/containers/buildah" - "github.com/containers/common/pkg/config" "github.com/containers/image/v5/manifest" "github.com/containers/podman/v2/libpod" image2 "github.com/containers/podman/v2/libpod/image" @@ -18,6 +17,7 @@ import ( "github.com/containers/podman/v2/pkg/api/handlers/utils" "github.com/containers/podman/v2/pkg/auth" "github.com/containers/podman/v2/pkg/domain/entities" + "github.com/containers/podman/v2/pkg/util" "github.com/gorilla/schema" "github.com/opencontainers/go-digest" "github.com/pkg/errors" @@ -202,7 +202,6 @@ func CreateImageFromSrc(w http.ResponseWriter, r *http.Request) { ProgressDetail: map[string]string{}, Id: iid, }) - } func CreateImageFromImage(w http.ResponseWriter, r *http.Request) { @@ -237,16 +236,6 @@ func CreateImageFromImage(w http.ResponseWriter, r *http.Request) { if sys := runtime.SystemContext(); sys != nil { registryOpts.DockerCertPath = sys.DockerCertPath } - rtc, err := runtime.GetConfig() - if err != nil { - utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Decode()")) - return - } - pullPolicy, err := config.ValidatePullPolicy(rtc.Engine.PullPolicy) - if err != nil { - utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Decode()")) - return - } img, err := runtime.ImageRuntime().New(r.Context(), fromImage, "", // signature policy @@ -255,7 +244,7 @@ func CreateImageFromImage(w http.ResponseWriter, r *http.Request) { ®istryOpts, image2.SigningOptions{}, nil, // label - pullPolicy, + util.PullImageAlways, ) if err != nil { utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err) @@ -265,12 +254,12 @@ func CreateImageFromImage(w http.ResponseWriter, r *http.Request) { // Success utils.WriteResponse(w, http.StatusOK, struct { Status string `json:"status"` - Error string `json:"error"` + Error string `json:"error,omitempty"` Progress string `json:"progress"` ProgressDetail map[string]string `json:"progressDetail"` Id string `json:"id"` // nolint }{ - Status: fmt.Sprintf("pulling image (%s) from %s", img.Tag, strings.Join(img.Names(), ", ")), + Status: fmt.Sprintf("pulling image (%s) from %s (Download complete)", img.Tag, strings.Join(img.Names(), ", ")), ProgressDetail: map[string]string{}, Id: img.ID(), }) diff --git a/pkg/api/handlers/compat/images_build.go b/pkg/api/handlers/compat/images_build.go index 415ff85cd..0f27a090f 100644 --- a/pkg/api/handlers/compat/images_build.go +++ b/pkg/api/handlers/compat/images_build.go @@ -60,29 +60,39 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { }() query := struct { - BuildArgs string `schema:"buildargs"` - CacheFrom string `schema:"cachefrom"` - CpuPeriod uint64 `schema:"cpuperiod"` // nolint - CpuQuota int64 `schema:"cpuquota"` // nolint - CpuSetCpus string `schema:"cpusetcpus"` // nolint - CpuShares uint64 `schema:"cpushares"` // nolint - Dockerfile string `schema:"dockerfile"` - ExtraHosts string `schema:"extrahosts"` - ForceRm bool `schema:"forcerm"` - HTTPProxy bool `schema:"httpproxy"` - Labels string `schema:"labels"` - Layers bool `schema:"layers"` - MemSwap int64 `schema:"memswap"` - Memory int64 `schema:"memory"` - NetworkMode string `schema:"networkmode"` - NoCache bool `schema:"nocache"` - Outputs string `schema:"outputs"` - Platform string `schema:"platform"` - Pull bool `schema:"pull"` - Quiet bool `schema:"q"` - Registry string `schema:"registry"` - Remote string `schema:"remote"` - Rm bool `schema:"rm"` + AddHosts string `schema:"extrahosts"` + AdditionalCapabilities string `schema:"addcaps"` + Annotations string `schema:"annotations"` + BuildArgs string `schema:"buildargs"` + CacheFrom string `schema:"cachefrom"` + ConfigureNetwork int64 `schema:"networkmode"` + CpuPeriod uint64 `schema:"cpuperiod"` // nolint + CpuQuota int64 `schema:"cpuquota"` // nolint + CpuSetCpus string `schema:"cpusetcpus"` // nolint + CpuShares uint64 `schema:"cpushares"` // nolint + Devices string `schema:"devices"` + Dockerfile string `schema:"dockerfile"` + DropCapabilities string `schema:"dropcaps"` + ForceRm bool `schema:"forcerm"` + From string `schema:"from"` + HTTPProxy bool `schema:"httpproxy"` + Isolation int64 `schema:"isolation"` + Jobs uint64 `schema:"jobs"` // nolint + Labels string `schema:"labels"` + Layers bool `schema:"layers"` + LogRusage bool `schema:"rusage"` + Manifest string `schema:"manifest"` + MemSwap int64 `schema:"memswap"` + Memory int64 `schema:"memory"` + NoCache bool `schema:"nocache"` + OutputFormat string `schema:"outputformat"` + Platform string `schema:"platform"` + Pull bool `schema:"pull"` + Quiet bool `schema:"q"` + Registry string `schema:"registry"` + Rm bool `schema:"rm"` + //FIXME SecurityOpt in remote API is not handled + SecurityOpt string `schema:"securityopt"` ShmSize int `schema:"shmsize"` Squash bool `schema:"squash"` Tag []string `schema:"t"` @@ -101,14 +111,57 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { return } + // convert label formats + var addCaps = []string{} + if _, found := r.URL.Query()["addcaps"]; found { + var m = []string{} + if err := json.Unmarshal([]byte(query.AdditionalCapabilities), &m); err != nil { + utils.BadRequest(w, "addcaps", query.AdditionalCapabilities, err) + return + } + addCaps = m + } + addhosts := []string{} + if _, found := r.URL.Query()["extrahosts"]; found { + if err := json.Unmarshal([]byte(query.AddHosts), &addhosts); err != nil { + utils.BadRequest(w, "extrahosts", query.AddHosts, err) + return + } + } + + // convert label formats + var dropCaps = []string{} + if _, found := r.URL.Query()["dropcaps"]; found { + var m = []string{} + if err := json.Unmarshal([]byte(query.DropCapabilities), &m); err != nil { + utils.BadRequest(w, "dropcaps", query.DropCapabilities, err) + return + } + dropCaps = m + } + + // convert label formats + var devices = []string{} + if _, found := r.URL.Query()["devices"]; found { + var m = []string{} + if err := json.Unmarshal([]byte(query.DropCapabilities), &m); err != nil { + utils.BadRequest(w, "devices", query.DropCapabilities, err) + return + } + devices = m + } + var output string if len(query.Tag) > 0 { output = query.Tag[0] } - - var additionalNames []string + format := buildah.Dockerv2ImageManifest + if utils.IsLibpodRequest(r) { + format = query.OutputFormat + } + var additionalTags []string if len(query.Tag) > 1 { - additionalNames = query.Tag[1:] + additionalTags = query.Tag[1:] } var buildArgs = map[string]string{} @@ -120,17 +173,21 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { } // convert label formats + var annotations = []string{} + if _, found := r.URL.Query()["annotations"]; found { + if err := json.Unmarshal([]byte(query.Annotations), &annotations); err != nil { + utils.BadRequest(w, "annotations", query.Annotations, err) + return + } + } + + // convert label formats var labels = []string{} if _, found := r.URL.Query()["labels"]; found { - var m = map[string]string{} - if err := json.Unmarshal([]byte(query.Labels), &m); err != nil { + if err := json.Unmarshal([]byte(query.Labels), &labels); err != nil { utils.BadRequest(w, "labels", query.Labels, err) return } - - for k, v := range m { - labels = append(labels, k+"="+v) - } } pullPolicy := buildah.PullIfMissing @@ -160,27 +217,14 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { reporter := channel.NewWriter(make(chan []byte, 1)) defer reporter.Close() + buildOptions := imagebuildah.BuildOptions{ - ContextDirectory: contextDirectory, - PullPolicy: pullPolicy, - Registry: query.Registry, - IgnoreUnrecognizedInstructions: true, - Quiet: query.Quiet, - Layers: query.Layers, - Isolation: buildah.IsolationChroot, - Compression: archive.Gzip, - Args: buildArgs, - Output: output, - AdditionalTags: additionalNames, - Out: stdout, - Err: auxout, - ReportWriter: reporter, - OutputFormat: buildah.Dockerv2ImageManifest, - SystemContext: &types.SystemContext{ - AuthFilePath: authfile, - DockerAuthConfig: creds, - }, + AddCapabilities: addCaps, + AdditionalTags: additionalTags, + Annotations: annotations, + Args: buildArgs, CommonBuildOpts: &buildah.CommonBuildOptions{ + AddHost: addhosts, CPUPeriod: query.CpuPeriod, CPUQuota: query.CpuQuota, CPUShares: query.CpuShares, @@ -190,12 +234,37 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { MemorySwap: query.MemSwap, ShmSize: strconv.Itoa(query.ShmSize), }, - Squash: query.Squash, - Labels: labels, - NoCache: query.NoCache, - RemoveIntermediateCtrs: query.Rm, - ForceRmIntermediateCtrs: query.ForceRm, - Target: query.Target, + Compression: archive.Gzip, + ConfigureNetwork: buildah.NetworkConfigurationPolicy(query.ConfigureNetwork), + ContextDirectory: contextDirectory, + Devices: devices, + DropCapabilities: dropCaps, + Err: auxout, + ForceRmIntermediateCtrs: query.ForceRm, + From: query.From, + IgnoreUnrecognizedInstructions: true, + // FIXME, This is very broken. Buildah will only work with chroot + // Isolation: buildah.Isolation(query.Isolation), + Isolation: buildah.IsolationChroot, + + Labels: labels, + Layers: query.Layers, + Manifest: query.Manifest, + NoCache: query.NoCache, + Out: stdout, + Output: output, + OutputFormat: format, + PullPolicy: pullPolicy, + Quiet: query.Quiet, + Registry: query.Registry, + RemoveIntermediateCtrs: query.Rm, + ReportWriter: reporter, + Squash: query.Squash, + SystemContext: &types.SystemContext{ + AuthFilePath: authfile, + DockerAuthConfig: creds, + }, + Target: query.Target, } runtime := r.Context().Value("runtime").(*libpod.Runtime) diff --git a/pkg/api/handlers/compat/images_history.go b/pkg/api/handlers/compat/images_history.go index 3b72798e4..174bc6234 100644 --- a/pkg/api/handlers/compat/images_history.go +++ b/pkg/api/handlers/compat/images_history.go @@ -17,7 +17,6 @@ func HistoryImage(w http.ResponseWriter, r *http.Request) { if err != nil { utils.Error(w, "Something went wrong.", http.StatusNotFound, errors.Wrapf(err, "failed to find image %s", name)) return - } history, err := newImage.History(r.Context()) if err != nil { diff --git a/pkg/api/handlers/compat/images_remove.go b/pkg/api/handlers/compat/images_remove.go index 9731c521c..dd2d96bbb 100644 --- a/pkg/api/handlers/compat/images_remove.go +++ b/pkg/api/handlers/compat/images_remove.go @@ -54,5 +54,4 @@ func RemoveImage(w http.ResponseWriter, r *http.Request) { } utils.WriteResponse(w, http.StatusOK, response) - } diff --git a/pkg/api/handlers/compat/networks.go b/pkg/api/handlers/compat/networks.go index f0b922885..95cb06189 100644 --- a/pkg/api/handlers/compat/networks.go +++ b/pkg/api/handlers/compat/networks.go @@ -277,10 +277,10 @@ func CreateNetwork(w http.ResponseWriter, r *http.Request) { return } body := struct { - Id string + ID string `json:"Id"` Warning []string }{ - Id: net.ID, + ID: net.ID, } utils.WriteResponse(w, http.StatusCreated, body) } diff --git a/pkg/api/handlers/compat/system.go b/pkg/api/handlers/compat/system.go index e21ae160a..66b4236f9 100644 --- a/pkg/api/handlers/compat/system.go +++ b/pkg/api/handlers/compat/system.go @@ -19,6 +19,7 @@ func GetDiskUsage(w http.ResponseWriter, r *http.Request) { df, err := ic.SystemDf(r.Context(), options) if err != nil { utils.InternalServerError(w, err) + return } imgs := make([]*docker.ImageSummary, len(df.Images)) diff --git a/pkg/api/handlers/decoder.go b/pkg/api/handlers/decoder.go index 54087168a..123d325aa 100644 --- a/pkg/api/handlers/decoder.go +++ b/pkg/api/handlers/decoder.go @@ -6,6 +6,7 @@ import ( "syscall" "time" + "github.com/containers/podman/v2/libpod/define" "github.com/containers/podman/v2/pkg/util" "github.com/gorilla/schema" "github.com/sirupsen/logrus" @@ -19,6 +20,7 @@ func NewAPIDecoder() *schema.Decoder { d.IgnoreUnknownKeys(true) d.RegisterConverter(map[string][]string{}, convertURLValuesString) d.RegisterConverter(time.Time{}, convertTimeString) + d.RegisterConverter(define.ContainerStatus(0), convertContainerStatusString) var Signal syscall.Signal d.RegisterConverter(Signal, convertSignal) @@ -46,6 +48,19 @@ func convertURLValuesString(query string) reflect.Value { return reflect.ValueOf(f) } +func convertContainerStatusString(query string) reflect.Value { + result, err := define.StringToContainerStatus(query) + if err != nil { + logrus.Infof("convertContainerStatusString: Failed to parse %s: %s", query, err.Error()) + + // We return nil here instead of result because reflect.ValueOf().IsValid() will be true + // in github.com/gorilla/schema's decoder, which means there's no parsing error + return reflect.ValueOf(nil) + } + + return reflect.ValueOf(result) +} + // isZero() can be used to determine if parsing failed. func convertTimeString(query string) reflect.Value { var ( diff --git a/pkg/api/handlers/libpod/containers.go b/pkg/api/handlers/libpod/containers.go index 619cbfd8b..4e79e4a42 100644 --- a/pkg/api/handlers/libpod/containers.go +++ b/pkg/api/handlers/libpod/containers.go @@ -48,7 +48,6 @@ func ContainerExists(w http.ResponseWriter, r *http.Request) { } utils.InternalServerError(w, err) return - } if report.Value { utils.WriteResponse(w, http.StatusNoContent, "") @@ -162,7 +161,6 @@ func UnmountContainer(w http.ResponseWriter, r *http.Request) { utils.InternalServerError(w, err) } utils.WriteResponse(w, http.StatusNoContent, "") - } func MountContainer(w http.ResponseWriter, r *http.Request) { runtime := r.Context().Value("runtime").(*libpod.Runtime) @@ -361,7 +359,6 @@ func ShouldRestart(w http.ResponseWriter, r *http.Request) { } utils.InternalServerError(w, err) return - } if report.Value { utils.WriteResponse(w, http.StatusNoContent, "") diff --git a/pkg/api/handlers/libpod/images.go b/pkg/api/handlers/libpod/images.go index 97cd5a65e..efc2b53b5 100644 --- a/pkg/api/handlers/libpod/images.go +++ b/pkg/api/handlers/libpod/images.go @@ -266,7 +266,6 @@ func ExportImages(w http.ResponseWriter, r *http.Request) { if len(query.References) > 1 && query.Format != define.V2s2Archive { utils.Error(w, "unsupported format", http.StatusInternalServerError, errors.Errorf("multi-image archives must use format of %s", define.V2s2Archive)) return - } switch query.Format { @@ -445,7 +444,6 @@ func PushImage(w http.ResponseWriter, r *http.Request) { if authconf != nil { username = authconf.Username password = authconf.Password - } options := entities.ImagePushOptions{ Authfile: authfile, diff --git a/pkg/api/handlers/libpod/networks.go b/pkg/api/handlers/libpod/networks.go index 8511e2733..92279fcc8 100644 --- a/pkg/api/handlers/libpod/networks.go +++ b/pkg/api/handlers/libpod/networks.go @@ -42,7 +42,6 @@ func CreateNetwork(w http.ResponseWriter, r *http.Request) { return } utils.WriteResponse(w, http.StatusOK, report) - } func ListNetworks(w http.ResponseWriter, r *http.Request) { runtime := r.Context().Value("runtime").(*libpod.Runtime) diff --git a/pkg/api/handlers/swagger/swagger.go b/pkg/api/handlers/swagger/swagger.go index 22670d795..32f041dd3 100644 --- a/pkg/api/handlers/swagger/swagger.go +++ b/pkg/api/handlers/swagger/swagger.go @@ -1,7 +1,6 @@ package swagger import ( - "github.com/containers/podman/v2/libpod" "github.com/containers/podman/v2/libpod/define" "github.com/containers/podman/v2/libpod/image" "github.com/containers/podman/v2/pkg/api/handlers" @@ -166,7 +165,7 @@ type swagInspectPodResponse struct { type swagInspectVolumeResponse struct { // in:body Body struct { - libpod.InspectVolumeData + define.InspectVolumeData } } diff --git a/pkg/api/handlers/utils/containers.go b/pkg/api/handlers/utils/containers.go index 518309a03..e79def6f3 100644 --- a/pkg/api/handlers/utils/containers.go +++ b/pkg/api/handlers/utils/containers.go @@ -105,6 +105,7 @@ func WaitContainerLibpod(w http.ResponseWriter, r *http.Request) { query := waitQueryLibpod{} if err := decoder.Decode(&query, r.URL.Query()); err != nil { Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String())) + return } if _, found := r.URL.Query()["interval"]; found { @@ -130,10 +131,9 @@ func WaitContainerLibpod(w http.ResponseWriter, r *http.Request) { if errors.Cause(err) == define.ErrNoSuchCtr { ContainerNotFound(w, name, err) return - } else { - InternalServerError(w, err) - return } + InternalServerError(w, err) + return } WriteResponse(w, http.StatusOK, strconv.Itoa(int(exitCode))) } @@ -141,7 +141,6 @@ func WaitContainerLibpod(w http.ResponseWriter, r *http.Request) { type containerWaitFn func(conditions ...define.ContainerStatus) (int32, error) func createContainerWaitFn(ctx context.Context, containerName string, interval time.Duration) containerWaitFn { - runtime := ctx.Value("runtime").(*libpod.Runtime) var containerEngine entities.ContainerEngine = &abi.ContainerEngine{Libpod: runtime} @@ -170,7 +169,6 @@ func isValidDockerCondition(cond string) bool { } func waitDockerCondition(ctx context.Context, containerName string, interval time.Duration, dockerCondition string) (int32, error) { - containerWait := createContainerWaitFn(ctx, containerName, interval) var err error @@ -200,9 +198,8 @@ func waitRemoved(ctrWait containerWaitFn) (int32, error) { code, err := ctrWait(define.ContainerStateUnknown) if err != nil && errors.Cause(err) == define.ErrNoSuchCtr { return code, nil - } else { - return code, err } + return code, err } func waitNextExit(ctrWait containerWaitFn) (int32, error) { diff --git a/pkg/api/server/register_ping.go b/pkg/api/server/register_ping.go index 446a12a68..0343d2608 100644 --- a/pkg/api/server/register_ping.go +++ b/pkg/api/server/register_ping.go @@ -8,7 +8,6 @@ import ( ) func (s *APIServer) registerPingHandlers(r *mux.Router) error { - r.Handle("/_ping", s.APIHandler(compat.Ping)).Methods(http.MethodGet, http.MethodHead) r.Handle(VersionedPath("/_ping"), s.APIHandler(compat.Ping)).Methods(http.MethodGet, http.MethodHead) // swagger:operation GET /libpod/_ping libpod libpodPingGet diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go index fcbf6fe39..9c1d87c4f 100644 --- a/pkg/auth/auth.go +++ b/pkg/auth/auth.go @@ -41,7 +41,6 @@ func GetCredentials(r *http.Request) (*types.DockerAuthConfig, string, HeaderAut case has(XRegistryAuthHeader): c, f, err := getAuthCredentials(r) return c, f, XRegistryAuthHeader, err - } return nil, "", "", nil } diff --git a/pkg/bindings/connection.go b/pkg/bindings/connection.go index 7b26037eb..6ff072e75 100644 --- a/pkg/bindings/connection.go +++ b/pkg/bindings/connection.go @@ -124,7 +124,7 @@ func NewConnectionWithIdentity(ctx context.Context, uri string, identity string) ctx = context.WithValue(ctx, clientKey, &connection) if err := pingNewConnection(ctx); err != nil { - return nil, err + return nil, errors.Wrap(err, "cannot connect to the Podman socket, please verify that Podman REST API service is running") } return ctx, nil } diff --git a/pkg/bindings/containers/archive.go b/pkg/bindings/containers/archive.go index d1bbc0b95..18871cfd1 100644 --- a/pkg/bindings/containers/archive.go +++ b/pkg/bindings/containers/archive.go @@ -30,7 +30,7 @@ func Stat(ctx context.Context, nameOrID string, path string) (*entities.Containe var finalErr error if response.StatusCode == http.StatusNotFound { - finalErr = copy.ENOENT + finalErr = copy.ErrENOENT } else if response.StatusCode != http.StatusOK { finalErr = errors.New(response.Status) } diff --git a/pkg/bindings/containers/containers.go b/pkg/bindings/containers/containers.go index 8e644b712..c84595011 100644 --- a/pkg/bindings/containers/containers.go +++ b/pkg/bindings/containers/containers.go @@ -137,7 +137,6 @@ func Kill(ctx context.Context, nameOrID string, options *KillOptions) error { return err } return response.Process(nil) - } // Pause pauses a given container. The nameOrID can be a container name @@ -270,8 +269,8 @@ func Top(ctx context.Context, nameOrID string, options *TopOptions) ([]string, e } params := url.Values{} if options.Changed("Descriptors") { - ps_args := strings.Join(options.GetDescriptors(), ",") - params.Add("ps_args", ps_args) + psArgs := strings.Join(options.GetDescriptors(), ",") + params.Add("ps_args", psArgs) } response, err := conn.DoRequest(nil, http.MethodGet, "/containers/%s/top", params, nil, nameOrID) if err != nil { diff --git a/pkg/bindings/containers/types_attach_options.go b/pkg/bindings/containers/types_attach_options.go index ab5a1615c..e806d161b 100644 --- a/pkg/bindings/containers/types_attach_options.go +++ b/pkg/bindings/containers/types_attach_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *AttachOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *AttachOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithDetachKeys diff --git a/pkg/bindings/containers/types_checkpoint_options.go b/pkg/bindings/containers/types_checkpoint_options.go index d239c476f..edac04ec4 100644 --- a/pkg/bindings/containers/types_checkpoint_options.go +++ b/pkg/bindings/containers/types_checkpoint_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *CheckpointOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *CheckpointOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithExport diff --git a/pkg/bindings/containers/types_commit_options.go b/pkg/bindings/containers/types_commit_options.go index 061f16e25..f3e0a16fc 100644 --- a/pkg/bindings/containers/types_commit_options.go +++ b/pkg/bindings/containers/types_commit_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *CommitOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *CommitOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithAuthor diff --git a/pkg/bindings/containers/types_create_options.go b/pkg/bindings/containers/types_create_options.go index 8cde11335..4ef3be2b4 100644 --- a/pkg/bindings/containers/types_create_options.go +++ b/pkg/bindings/containers/types_create_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *CreateOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *CreateOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/containers/types_diff_options.go b/pkg/bindings/containers/types_diff_options.go index e912bf041..952e149e9 100644 --- a/pkg/bindings/containers/types_diff_options.go +++ b/pkg/bindings/containers/types_diff_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *DiffOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *DiffOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/containers/types_execinspect_options.go b/pkg/bindings/containers/types_execinspect_options.go index b870db46b..2ceb41878 100644 --- a/pkg/bindings/containers/types_execinspect_options.go +++ b/pkg/bindings/containers/types_execinspect_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ExecInspectOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *ExecInspectOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/containers/types_execstart_options.go b/pkg/bindings/containers/types_execstart_options.go index 95f97b1d7..e5b73bc7b 100644 --- a/pkg/bindings/containers/types_execstart_options.go +++ b/pkg/bindings/containers/types_execstart_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ExecStartOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *ExecStartOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/containers/types_execstartandattach_options.go b/pkg/bindings/containers/types_execstartandattach_options.go index 1981c319a..1b9276c8c 100644 --- a/pkg/bindings/containers/types_execstartandattach_options.go +++ b/pkg/bindings/containers/types_execstartandattach_options.go @@ -4,12 +4,8 @@ import ( "bufio" "io" "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -18,62 +14,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ExecStartAndAttachOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *ExecStartAndAttachOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithOutputStream diff --git a/pkg/bindings/containers/types_exists_options.go b/pkg/bindings/containers/types_exists_options.go index a52777600..ee822ab88 100644 --- a/pkg/bindings/containers/types_exists_options.go +++ b/pkg/bindings/containers/types_exists_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ExistsOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *ExistsOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithExternal diff --git a/pkg/bindings/containers/types_export_options.go b/pkg/bindings/containers/types_export_options.go index 3943a5a3b..03eac2bad 100644 --- a/pkg/bindings/containers/types_export_options.go +++ b/pkg/bindings/containers/types_export_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ExportOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *ExportOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/containers/types_healthcheck_options.go b/pkg/bindings/containers/types_healthcheck_options.go index a548232cd..ac6d67f63 100644 --- a/pkg/bindings/containers/types_healthcheck_options.go +++ b/pkg/bindings/containers/types_healthcheck_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *HealthCheckOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *HealthCheckOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/containers/types_init_options.go b/pkg/bindings/containers/types_init_options.go index 92e8a6c17..7365bcd25 100644 --- a/pkg/bindings/containers/types_init_options.go +++ b/pkg/bindings/containers/types_init_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *InitOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *InitOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/containers/types_inspect_options.go b/pkg/bindings/containers/types_inspect_options.go index fdb84bda8..fb3e70a9d 100644 --- a/pkg/bindings/containers/types_inspect_options.go +++ b/pkg/bindings/containers/types_inspect_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *InspectOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *InspectOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithSize diff --git a/pkg/bindings/containers/types_kill_options.go b/pkg/bindings/containers/types_kill_options.go index 45bd790a4..5acb0c67d 100644 --- a/pkg/bindings/containers/types_kill_options.go +++ b/pkg/bindings/containers/types_kill_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *KillOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *KillOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithSignal diff --git a/pkg/bindings/containers/types_list_options.go b/pkg/bindings/containers/types_list_options.go index 3293320ec..8e872c99e 100644 --- a/pkg/bindings/containers/types_list_options.go +++ b/pkg/bindings/containers/types_list_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ListOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *ListOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithAll diff --git a/pkg/bindings/containers/types_log_options.go b/pkg/bindings/containers/types_log_options.go index e78eb7bd0..a69570d0e 100644 --- a/pkg/bindings/containers/types_log_options.go +++ b/pkg/bindings/containers/types_log_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *LogOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *LogOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithFollow diff --git a/pkg/bindings/containers/types_mount_options.go b/pkg/bindings/containers/types_mount_options.go index cc8df1255..e5cc35307 100644 --- a/pkg/bindings/containers/types_mount_options.go +++ b/pkg/bindings/containers/types_mount_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *MountOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *MountOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/containers/types_mountedcontainerpaths_options.go b/pkg/bindings/containers/types_mountedcontainerpaths_options.go index 78fa2fca0..f0536abaa 100644 --- a/pkg/bindings/containers/types_mountedcontainerpaths_options.go +++ b/pkg/bindings/containers/types_mountedcontainerpaths_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *MountedContainerPathsOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *MountedContainerPathsOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/containers/types_pause_options.go b/pkg/bindings/containers/types_pause_options.go index 55f14bef0..8497a24a8 100644 --- a/pkg/bindings/containers/types_pause_options.go +++ b/pkg/bindings/containers/types_pause_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *PauseOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *PauseOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/containers/types_prune_options.go b/pkg/bindings/containers/types_prune_options.go index 000c7c0bd..2ea963c97 100644 --- a/pkg/bindings/containers/types_prune_options.go +++ b/pkg/bindings/containers/types_prune_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *PruneOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *PruneOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithFilters diff --git a/pkg/bindings/containers/types_remove_options.go b/pkg/bindings/containers/types_remove_options.go index dfb5367eb..b9dea71a1 100644 --- a/pkg/bindings/containers/types_remove_options.go +++ b/pkg/bindings/containers/types_remove_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *RemoveOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *RemoveOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithIgnore diff --git a/pkg/bindings/containers/types_rename_options.go b/pkg/bindings/containers/types_rename_options.go index f4f5d1426..c148f6730 100644 --- a/pkg/bindings/containers/types_rename_options.go +++ b/pkg/bindings/containers/types_rename_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *RenameOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *RenameOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithName diff --git a/pkg/bindings/containers/types_resizeexectty_options.go b/pkg/bindings/containers/types_resizeexectty_options.go index e63d965eb..256e5299b 100644 --- a/pkg/bindings/containers/types_resizeexectty_options.go +++ b/pkg/bindings/containers/types_resizeexectty_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ResizeExecTTYOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *ResizeExecTTYOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithHeight diff --git a/pkg/bindings/containers/types_resizetty_options.go b/pkg/bindings/containers/types_resizetty_options.go index 3170f4053..4f2958ba0 100644 --- a/pkg/bindings/containers/types_resizetty_options.go +++ b/pkg/bindings/containers/types_resizetty_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ResizeTTYOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *ResizeTTYOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithHeight diff --git a/pkg/bindings/containers/types_restart_options.go b/pkg/bindings/containers/types_restart_options.go index d59176e67..8c791ae67 100644 --- a/pkg/bindings/containers/types_restart_options.go +++ b/pkg/bindings/containers/types_restart_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *RestartOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *RestartOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithTimeout diff --git a/pkg/bindings/containers/types_restore_options.go b/pkg/bindings/containers/types_restore_options.go index e9f14fc47..e0204a677 100644 --- a/pkg/bindings/containers/types_restore_options.go +++ b/pkg/bindings/containers/types_restore_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *RestoreOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *RestoreOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithIgnoreRootfs diff --git a/pkg/bindings/containers/types_shouldrestart_options.go b/pkg/bindings/containers/types_shouldrestart_options.go index 49f943460..b0aeff09c 100644 --- a/pkg/bindings/containers/types_shouldrestart_options.go +++ b/pkg/bindings/containers/types_shouldrestart_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ShouldRestartOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *ShouldRestartOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/containers/types_start_options.go b/pkg/bindings/containers/types_start_options.go index a0f0b3077..60e061c79 100644 --- a/pkg/bindings/containers/types_start_options.go +++ b/pkg/bindings/containers/types_start_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *StartOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *StartOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithDetachKeys diff --git a/pkg/bindings/containers/types_stats_options.go b/pkg/bindings/containers/types_stats_options.go index 79e35ba62..ce0fdfe87 100644 --- a/pkg/bindings/containers/types_stats_options.go +++ b/pkg/bindings/containers/types_stats_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *StatsOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *StatsOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithStream diff --git a/pkg/bindings/containers/types_stop_options.go b/pkg/bindings/containers/types_stop_options.go index f221b16e8..14ece3a43 100644 --- a/pkg/bindings/containers/types_stop_options.go +++ b/pkg/bindings/containers/types_stop_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *StopOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *StopOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithIgnore diff --git a/pkg/bindings/containers/types_top_options.go b/pkg/bindings/containers/types_top_options.go index 570dd4e90..0481abe9a 100644 --- a/pkg/bindings/containers/types_top_options.go +++ b/pkg/bindings/containers/types_top_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *TopOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *TopOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithDescriptors diff --git a/pkg/bindings/containers/types_unmount_options.go b/pkg/bindings/containers/types_unmount_options.go index 24249073e..c32747e3a 100644 --- a/pkg/bindings/containers/types_unmount_options.go +++ b/pkg/bindings/containers/types_unmount_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *UnmountOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *UnmountOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/containers/types_unpause_options.go b/pkg/bindings/containers/types_unpause_options.go index 3b1d75001..5f17067af 100644 --- a/pkg/bindings/containers/types_unpause_options.go +++ b/pkg/bindings/containers/types_unpause_options.go @@ -2,12 +2,8 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *UnpauseOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *UnpauseOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/containers/types_wait_options.go b/pkg/bindings/containers/types_wait_options.go index a3f1e3b8c..42ee0c316 100644 --- a/pkg/bindings/containers/types_wait_options.go +++ b/pkg/bindings/containers/types_wait_options.go @@ -2,13 +2,9 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/libpod/define" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -17,62 +13,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *WaitOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *WaitOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithCondition diff --git a/pkg/bindings/errors.go b/pkg/bindings/errors.go index e75ce898d..51ea487be 100644 --- a/pkg/bindings/errors.go +++ b/pkg/bindings/errors.go @@ -20,12 +20,12 @@ func handleError(data []byte) error { return e } -func (a APIResponse) Process(unmarshalInto interface{}) error { - data, err := ioutil.ReadAll(a.Response.Body) +func (h APIResponse) Process(unmarshalInto interface{}) error { + data, err := ioutil.ReadAll(h.Response.Body) if err != nil { return errors.Wrap(err, "unable to process API response") } - if a.IsSuccess() || a.IsRedirection() { + if h.IsSuccess() || h.IsRedirection() { if unmarshalInto != nil { return json.Unmarshal(data, unmarshalInto) } diff --git a/pkg/bindings/generate/types_kube_options.go b/pkg/bindings/generate/types_kube_options.go index 218d308e1..5d34f4bee 100644 --- a/pkg/bindings/generate/types_kube_options.go +++ b/pkg/bindings/generate/types_kube_options.go @@ -1,13 +1,9 @@ package generate import ( - "errors" "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *KubeOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *KubeOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithService diff --git a/pkg/bindings/generate/types_systemd_options.go b/pkg/bindings/generate/types_systemd_options.go index faf981d1b..dc7378888 100644 --- a/pkg/bindings/generate/types_systemd_options.go +++ b/pkg/bindings/generate/types_systemd_options.go @@ -1,13 +1,9 @@ package generate import ( - "errors" "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *SystemdOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *SystemdOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithUseName diff --git a/pkg/bindings/generator/generator.go b/pkg/bindings/generator/generator.go index dad154166..fc06fedd9 100644 --- a/pkg/bindings/generator/generator.go +++ b/pkg/bindings/generator/generator.go @@ -27,81 +27,31 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *{{.StructName}}) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *{{.StructName}}) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } -` -var fieldTmpl = ` +{{range $field := .Fields}} // With{{.Name}} -func(o *{{.StructName}}) With{{.Name}}(value {{.Type}}) *{{.StructName}} { - v := {{.TypedValue}} - o.{{.Name}} = v +func(o *{{$field.StructName}}) With{{$field.Name}}(value {{$field.Type}}) *{{$field.StructName}} { + v := {{$field.TypedValue}} + o.{{$field.Name}} = v return o } // Get{{.Name}} -func(o *{{.StructName}}) Get{{.Name}}() {{.Type}} { - var {{.ZeroName}} {{.Type}} - if o.{{.Name}} == nil { - return {{.ZeroName}} +func(o *{{$field.StructName}}) Get{{$field.Name}}() {{$field.Type}} { + var {{$field.ZeroName}} {{$field.Type}} + if o.{{$field.Name}} == nil { + return {{$field.ZeroName}} } - return {{.TypedName}} + return {{$field.TypedName}} } +{{end}} ` type fieldStruct struct { @@ -145,20 +95,7 @@ func main() { out.Close() } }() - bodyStruct := struct { - PackageName string - Imports []string - Date string - StructName string - }{ - PackageName: pkg, - Imports: imports, - Date: time.Now().String(), - StructName: inputStructName, - } - body := template.Must(template.New("body").Parse(bodyTmpl)) - fields := template.Must(template.New("fields").Parse(fieldTmpl)) ast.Inspect(f, func(n ast.Node) bool { ref, refOK := n.(*ast.TypeSpec) if refOK { @@ -202,20 +139,28 @@ func main() { fieldStructs = append(fieldStructs, fStruct) } // for + bodyStruct := struct { + PackageName string + Imports []string + Date string + StructName string + Fields []fieldStruct + }{ + PackageName: pkg, + Imports: imports, + Date: time.Now().String(), + StructName: inputStructName, + Fields: fieldStructs, + } + + body := template.Must(template.New("body").Parse(bodyTmpl)) + // create the body if err := body.Execute(out, bodyStruct); err != nil { fmt.Println(err) os.Exit(1) } - // create with func from the struct fields - for _, fs := range fieldStructs { - if err := fields.Execute(out, fs); err != nil { - fmt.Println(err) - os.Exit(1) - } - } - // close out file if err := out.Close(); err != nil { fmt.Println(err) @@ -239,7 +184,6 @@ func main() { os.Exit(1) } } - } return true }) diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go index 02765816f..8ea09b881 100644 --- a/pkg/bindings/images/build.go +++ b/pkg/bindings/images/build.go @@ -31,36 +31,31 @@ import ( func Build(ctx context.Context, containerFiles []string, options entities.BuildOptions) (*entities.BuildReport, error) { params := url.Values{} - if t := options.Output; len(t) > 0 { - params.Set("t", t) + if caps := options.AddCapabilities; len(caps) > 0 { + c, err := jsoniter.MarshalToString(caps) + if err != nil { + return nil, err + } + params.Add("addcaps", c) } + + if annotations := options.Annotations; len(annotations) > 0 { + l, err := jsoniter.MarshalToString(annotations) + if err != nil { + return nil, err + } + params.Set("annotations", l) + } + params.Add("t", options.Output) for _, tag := range options.AdditionalTags { params.Add("t", tag) } - if options.Quiet { - params.Set("q", "1") - } - if options.NoCache { - params.Set("nocache", "1") - } - if options.Layers { - params.Set("layers", "1") - } - // TODO cachefrom - if options.PullPolicy == buildah.PullAlways { - params.Set("pull", "1") - } - if options.RemoveIntermediateCtrs { - params.Set("rm", "1") - } - if options.ForceRmIntermediateCtrs { - params.Set("forcerm", "1") - } - if mem := options.CommonBuildOpts.Memory; mem > 0 { - params.Set("memory", strconv.Itoa(int(mem))) - } - if memSwap := options.CommonBuildOpts.MemorySwap; memSwap > 0 { - params.Set("memswap", strconv.Itoa(int(memSwap))) + if buildArgs := options.Args; len(buildArgs) > 0 { + bArgs, err := jsoniter.MarshalToString(buildArgs) + if err != nil { + return nil, err + } + params.Set("buildargs", bArgs) } if cpuShares := options.CommonBuildOpts.CPUShares; cpuShares > 0 { params.Set("cpushares", strconv.Itoa(int(cpuShares))) @@ -74,22 +69,38 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO if cpuQuota := options.CommonBuildOpts.CPUQuota; cpuQuota > 0 { params.Set("cpuquota", strconv.Itoa(int(cpuQuota))) } - if buildArgs := options.Args; len(buildArgs) > 0 { - bArgs, err := jsoniter.MarshalToString(buildArgs) + params.Set("networkmode", strconv.Itoa(int(options.ConfigureNetwork))) + params.Set("outputformat", options.OutputFormat) + + if devices := options.Devices; len(devices) > 0 { + d, err := jsoniter.MarshalToString(devices) if err != nil { return nil, err } - params.Set("buildargs", bArgs) + params.Add("devices", d) } - if shmSize := options.CommonBuildOpts.ShmSize; len(shmSize) > 0 { - shmBytes, err := units.RAMInBytes(shmSize) + + if caps := options.DropCapabilities; len(caps) > 0 { + c, err := jsoniter.MarshalToString(caps) if err != nil { return nil, err } - params.Set("shmsize", strconv.Itoa(int(shmBytes))) + params.Add("dropcaps", c) } - if options.Squash { - params.Set("squash", "1") + + if options.ForceRmIntermediateCtrs { + params.Set("forcerm", "1") + } + if len(options.From) > 0 { + params.Set("from", options.From) + } + + params.Set("isolation", strconv.Itoa(int(options.Isolation))) + if options.CommonBuildOpts.HTTPProxy { + params.Set("httpproxy", "1") + } + if options.Jobs != nil { + params.Set("jobs", strconv.FormatUint(uint64(*options.Jobs), 10)) } if labels := options.Labels; len(labels) > 0 { l, err := jsoniter.MarshalToString(labels) @@ -98,10 +109,66 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO } params.Set("labels", l) } - if options.CommonBuildOpts.HTTPProxy { - params.Set("httpproxy", "1") + if options.Layers { + params.Set("layers", "1") + } + if options.LogRusage { + params.Set("rusage", "1") + } + if len(options.Manifest) > 0 { + params.Set("manifest", options.Manifest) + } + if memSwap := options.CommonBuildOpts.MemorySwap; memSwap > 0 { + params.Set("memswap", strconv.Itoa(int(memSwap))) + } + if mem := options.CommonBuildOpts.Memory; mem > 0 { + params.Set("memory", strconv.Itoa(int(mem))) + } + if options.NoCache { + params.Set("nocache", "1") + } + if t := options.Output; len(t) > 0 { + params.Set("output", t) + } + var platform string + if len(options.OS) > 0 { + platform = options.OS + } + if len(options.Architecture) > 0 { + if len(platform) == 0 { + platform = "linux" + } + platform += "/" + options.Architecture + } + if len(platform) > 0 { + params.Set("platform", platform) + } + if options.PullPolicy == buildah.PullAlways { + params.Set("pull", "1") + } + if options.Quiet { + params.Set("q", "1") + } + if options.RemoveIntermediateCtrs { + params.Set("rm", "1") + } + if hosts := options.CommonBuildOpts.AddHost; len(hosts) > 0 { + h, err := jsoniter.MarshalToString(hosts) + if err != nil { + return nil, err + } + params.Set("extrahosts", h) + } + if shmSize := options.CommonBuildOpts.ShmSize; len(shmSize) > 0 { + shmBytes, err := units.RAMInBytes(shmSize) + if err != nil { + return nil, err + } + params.Set("shmsize", strconv.Itoa(int(shmBytes))) + } + if options.Squash { + params.Set("squash", "1") } - var ( headers map[string]string err error @@ -124,19 +191,6 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO stdout = options.Out } - // TODO network? - - var platform string - if OS := options.OS; len(OS) > 0 { - platform += OS - } - if arch := options.Architecture; len(arch) > 0 { - platform += "/" + arch - } - if len(platform) > 0 { - params.Set("platform", platform) - } - entries := make([]string, len(containerFiles)) copy(entries, containerFiles) entries = append(entries, options.ContextDirectory) diff --git a/pkg/bindings/images/pull.go b/pkg/bindings/images/pull.go index 5669c704e..9149b7445 100644 --- a/pkg/bindings/images/pull.go +++ b/pkg/bindings/images/pull.go @@ -93,7 +93,6 @@ func Pull(ctx context.Context, rawImage string, options *PullOptions) ([]string, default: return images, errors.New("failed to parse pull results stream, unexpected input") } - } return images, mErr } diff --git a/pkg/bindings/images/types_diff_options.go b/pkg/bindings/images/types_diff_options.go index edfc7bfa2..ae4b4655b 100644 --- a/pkg/bindings/images/types_diff_options.go +++ b/pkg/bindings/images/types_diff_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *DiffOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *DiffOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/images/types_exists_options.go b/pkg/bindings/images/types_exists_options.go index 649be4862..9de1b9878 100644 --- a/pkg/bindings/images/types_exists_options.go +++ b/pkg/bindings/images/types_exists_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ExistsOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *ExistsOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/images/types_export_options.go b/pkg/bindings/images/types_export_options.go index ebd053165..dcce565f6 100644 --- a/pkg/bindings/images/types_export_options.go +++ b/pkg/bindings/images/types_export_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ExportOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *ExportOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithCompress diff --git a/pkg/bindings/images/types_get_options.go b/pkg/bindings/images/types_get_options.go index 33ebe2611..b9d00d82c 100644 --- a/pkg/bindings/images/types_get_options.go +++ b/pkg/bindings/images/types_get_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *GetOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *GetOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithSize diff --git a/pkg/bindings/images/types_history_options.go b/pkg/bindings/images/types_history_options.go index b2c37acea..e2cd43852 100644 --- a/pkg/bindings/images/types_history_options.go +++ b/pkg/bindings/images/types_history_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *HistoryOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *HistoryOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/images/types_import_options.go b/pkg/bindings/images/types_import_options.go index e2aed0866..ff409cc7c 100644 --- a/pkg/bindings/images/types_import_options.go +++ b/pkg/bindings/images/types_import_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ImportOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *ImportOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithChanges diff --git a/pkg/bindings/images/types_list_options.go b/pkg/bindings/images/types_list_options.go index e194474b9..38d1bde70 100644 --- a/pkg/bindings/images/types_list_options.go +++ b/pkg/bindings/images/types_list_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ListOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *ListOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithAll diff --git a/pkg/bindings/images/types_load_options.go b/pkg/bindings/images/types_load_options.go index 7e15d4e03..d17e7cc10 100644 --- a/pkg/bindings/images/types_load_options.go +++ b/pkg/bindings/images/types_load_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *LoadOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *LoadOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithReference diff --git a/pkg/bindings/images/types_prune_options.go b/pkg/bindings/images/types_prune_options.go index f86676d53..deef211c1 100644 --- a/pkg/bindings/images/types_prune_options.go +++ b/pkg/bindings/images/types_prune_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *PruneOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *PruneOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithAll diff --git a/pkg/bindings/images/types_pull_options.go b/pkg/bindings/images/types_pull_options.go index 59e2b6354..2220ade26 100644 --- a/pkg/bindings/images/types_pull_options.go +++ b/pkg/bindings/images/types_pull_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *PullOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *PullOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithAllTags diff --git a/pkg/bindings/images/types_push_options.go b/pkg/bindings/images/types_push_options.go index ae946fcde..966bb11fe 100644 --- a/pkg/bindings/images/types_push_options.go +++ b/pkg/bindings/images/types_push_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *PushOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *PushOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithAll diff --git a/pkg/bindings/images/types_remove_options.go b/pkg/bindings/images/types_remove_options.go index d79186565..964fca265 100644 --- a/pkg/bindings/images/types_remove_options.go +++ b/pkg/bindings/images/types_remove_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *RemoveOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *RemoveOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithAll diff --git a/pkg/bindings/images/types_search_options.go b/pkg/bindings/images/types_search_options.go index a55c9ac89..1321d1910 100644 --- a/pkg/bindings/images/types_search_options.go +++ b/pkg/bindings/images/types_search_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *SearchOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *SearchOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithAuthfile diff --git a/pkg/bindings/images/types_tag_options.go b/pkg/bindings/images/types_tag_options.go index b323ea41c..74977e10a 100644 --- a/pkg/bindings/images/types_tag_options.go +++ b/pkg/bindings/images/types_tag_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *TagOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *TagOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/images/types_tree_options.go b/pkg/bindings/images/types_tree_options.go index 8e1b16c5c..a07a3a647 100644 --- a/pkg/bindings/images/types_tree_options.go +++ b/pkg/bindings/images/types_tree_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *TreeOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *TreeOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithWhatRequires diff --git a/pkg/bindings/images/types_untag_options.go b/pkg/bindings/images/types_untag_options.go index b28670134..3f7ac4a5a 100644 --- a/pkg/bindings/images/types_untag_options.go +++ b/pkg/bindings/images/types_untag_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *UntagOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *UntagOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/manifests/types_add_options.go b/pkg/bindings/manifests/types_add_options.go index 61314c479..ae7e914b2 100644 --- a/pkg/bindings/manifests/types_add_options.go +++ b/pkg/bindings/manifests/types_add_options.go @@ -1,13 +1,9 @@ package manifests import ( - "errors" "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *AddOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *AddOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithAll diff --git a/pkg/bindings/manifests/types_create_options.go b/pkg/bindings/manifests/types_create_options.go index 4c7c1397a..a8e11b828 100644 --- a/pkg/bindings/manifests/types_create_options.go +++ b/pkg/bindings/manifests/types_create_options.go @@ -1,13 +1,9 @@ package manifests import ( - "errors" "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *CreateOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *CreateOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithAll diff --git a/pkg/bindings/manifests/types_inspect_options.go b/pkg/bindings/manifests/types_inspect_options.go index 0b82fc3cf..90be7ebe3 100644 --- a/pkg/bindings/manifests/types_inspect_options.go +++ b/pkg/bindings/manifests/types_inspect_options.go @@ -1,13 +1,9 @@ package manifests import ( - "errors" "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *InspectOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *InspectOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/manifests/types_remove_options.go b/pkg/bindings/manifests/types_remove_options.go index 6ed0fd329..612d72dac 100644 --- a/pkg/bindings/manifests/types_remove_options.go +++ b/pkg/bindings/manifests/types_remove_options.go @@ -1,13 +1,9 @@ package manifests import ( - "errors" "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *RemoveOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *RemoveOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/network/network.go b/pkg/bindings/network/network.go index 7cd251b0e..d747f9bd7 100644 --- a/pkg/bindings/network/network.go +++ b/pkg/bindings/network/network.go @@ -102,7 +102,7 @@ func List(ctx context.Context, options *ListOptions) ([]*entities.NetworkListRep } // Disconnect removes a container from a given network -func Disconnect(ctx context.Context, networkName string, ContainerNameOrId string, options *DisconnectOptions) error { +func Disconnect(ctx context.Context, networkName string, ContainerNameOrID string, options *DisconnectOptions) error { if options == nil { options = new(DisconnectOptions) } @@ -117,7 +117,7 @@ func Disconnect(ctx context.Context, networkName string, ContainerNameOrId strin Container string Force bool }{ - Container: ContainerNameOrId, + Container: ContainerNameOrID, } if force := options.GetForce(); options.Changed("Force") { disconnect.Force = force @@ -136,7 +136,7 @@ func Disconnect(ctx context.Context, networkName string, ContainerNameOrId strin } // Connect adds a container to a network -func Connect(ctx context.Context, networkName string, ContainerNameOrId string, options *ConnectOptions) error { +func Connect(ctx context.Context, networkName string, ContainerNameOrID string, options *ConnectOptions) error { if options == nil { options = new(ConnectOptions) } @@ -151,7 +151,7 @@ func Connect(ctx context.Context, networkName string, ContainerNameOrId string, Container string Aliases []string }{ - Container: ContainerNameOrId, + Container: ContainerNameOrID, } if aliases := options.GetAliases(); options.Changed("Aliases") { connect.Aliases = aliases diff --git a/pkg/bindings/network/types_connect_options.go b/pkg/bindings/network/types_connect_options.go index 4440bbed4..b3cad6164 100644 --- a/pkg/bindings/network/types_connect_options.go +++ b/pkg/bindings/network/types_connect_options.go @@ -2,12 +2,8 @@ package network import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ConnectOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *ConnectOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithAliases diff --git a/pkg/bindings/network/types_create_options.go b/pkg/bindings/network/types_create_options.go index 5fbdce93a..553c94ee5 100644 --- a/pkg/bindings/network/types_create_options.go +++ b/pkg/bindings/network/types_create_options.go @@ -3,12 +3,8 @@ package network import ( "net" "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -17,62 +13,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *CreateOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *CreateOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithDisableDNS diff --git a/pkg/bindings/network/types_disconnect_options.go b/pkg/bindings/network/types_disconnect_options.go index 947f2f114..667da0d99 100644 --- a/pkg/bindings/network/types_disconnect_options.go +++ b/pkg/bindings/network/types_disconnect_options.go @@ -2,12 +2,8 @@ package network import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *DisconnectOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *DisconnectOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithForce diff --git a/pkg/bindings/network/types_inspect_options.go b/pkg/bindings/network/types_inspect_options.go index 144ccbfae..ce8f58e2e 100644 --- a/pkg/bindings/network/types_inspect_options.go +++ b/pkg/bindings/network/types_inspect_options.go @@ -2,12 +2,8 @@ package network import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *InspectOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *InspectOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/network/types_list_options.go b/pkg/bindings/network/types_list_options.go index 60632ce33..c16e4c05e 100644 --- a/pkg/bindings/network/types_list_options.go +++ b/pkg/bindings/network/types_list_options.go @@ -2,12 +2,8 @@ package network import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ListOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *ListOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithFilters diff --git a/pkg/bindings/network/types_remove_options.go b/pkg/bindings/network/types_remove_options.go index 4ad4a2301..8e4dca819 100644 --- a/pkg/bindings/network/types_remove_options.go +++ b/pkg/bindings/network/types_remove_options.go @@ -2,12 +2,8 @@ package network import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *RemoveOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *RemoveOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithForce diff --git a/pkg/bindings/play/types_kube_options.go b/pkg/bindings/play/types_kube_options.go index ea3872aae..946c19b28 100644 --- a/pkg/bindings/play/types_kube_options.go +++ b/pkg/bindings/play/types_kube_options.go @@ -1,13 +1,9 @@ package play import ( - "errors" "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *KubeOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *KubeOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithAuthfile diff --git a/pkg/bindings/pods/types_create_options.go b/pkg/bindings/pods/types_create_options.go index cfa29c6be..942f25629 100644 --- a/pkg/bindings/pods/types_create_options.go +++ b/pkg/bindings/pods/types_create_options.go @@ -2,12 +2,8 @@ package pods import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *CreateOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *CreateOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/pods/types_exists_options.go b/pkg/bindings/pods/types_exists_options.go index 6149ab1cc..11c6f9c05 100644 --- a/pkg/bindings/pods/types_exists_options.go +++ b/pkg/bindings/pods/types_exists_options.go @@ -2,12 +2,8 @@ package pods import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ExistsOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *ExistsOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/pods/types_inspect_options.go b/pkg/bindings/pods/types_inspect_options.go index 281717ff1..172b1303c 100644 --- a/pkg/bindings/pods/types_inspect_options.go +++ b/pkg/bindings/pods/types_inspect_options.go @@ -2,12 +2,8 @@ package pods import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *InspectOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *InspectOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/pods/types_kill_options.go b/pkg/bindings/pods/types_kill_options.go index 4c310d50c..e350746db 100644 --- a/pkg/bindings/pods/types_kill_options.go +++ b/pkg/bindings/pods/types_kill_options.go @@ -2,12 +2,8 @@ package pods import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *KillOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *KillOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithSignal diff --git a/pkg/bindings/pods/types_list_options.go b/pkg/bindings/pods/types_list_options.go index 20f3229e5..fcaeb7c1c 100644 --- a/pkg/bindings/pods/types_list_options.go +++ b/pkg/bindings/pods/types_list_options.go @@ -2,12 +2,8 @@ package pods import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ListOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *ListOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithFilters diff --git a/pkg/bindings/pods/types_pause_options.go b/pkg/bindings/pods/types_pause_options.go index 0f0f5bd97..b5aee3984 100644 --- a/pkg/bindings/pods/types_pause_options.go +++ b/pkg/bindings/pods/types_pause_options.go @@ -2,12 +2,8 @@ package pods import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *PauseOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *PauseOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/pods/types_prune_options.go b/pkg/bindings/pods/types_prune_options.go index ef8aae17f..80019a2fd 100644 --- a/pkg/bindings/pods/types_prune_options.go +++ b/pkg/bindings/pods/types_prune_options.go @@ -2,12 +2,8 @@ package pods import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *PruneOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *PruneOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/pods/types_remove_options.go b/pkg/bindings/pods/types_remove_options.go index f51f67129..e129d1e29 100644 --- a/pkg/bindings/pods/types_remove_options.go +++ b/pkg/bindings/pods/types_remove_options.go @@ -2,12 +2,8 @@ package pods import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *RemoveOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *RemoveOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithForce diff --git a/pkg/bindings/pods/types_restart_options.go b/pkg/bindings/pods/types_restart_options.go index ec05e9fc9..7b95b91a1 100644 --- a/pkg/bindings/pods/types_restart_options.go +++ b/pkg/bindings/pods/types_restart_options.go @@ -2,12 +2,8 @@ package pods import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *RestartOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *RestartOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/pods/types_start_options.go b/pkg/bindings/pods/types_start_options.go index ec9f5b1de..b0d574020 100644 --- a/pkg/bindings/pods/types_start_options.go +++ b/pkg/bindings/pods/types_start_options.go @@ -2,12 +2,8 @@ package pods import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *StartOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *StartOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/pods/types_stats_options.go b/pkg/bindings/pods/types_stats_options.go index 8be7d175d..50a18bc6a 100644 --- a/pkg/bindings/pods/types_stats_options.go +++ b/pkg/bindings/pods/types_stats_options.go @@ -2,12 +2,8 @@ package pods import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *StatsOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *StatsOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithAll diff --git a/pkg/bindings/pods/types_stop_options.go b/pkg/bindings/pods/types_stop_options.go index fa3577e72..f80d391c6 100644 --- a/pkg/bindings/pods/types_stop_options.go +++ b/pkg/bindings/pods/types_stop_options.go @@ -2,12 +2,8 @@ package pods import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *StopOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *StopOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithTimeout diff --git a/pkg/bindings/pods/types_top_options.go b/pkg/bindings/pods/types_top_options.go index c3c701dad..7e05a7937 100644 --- a/pkg/bindings/pods/types_top_options.go +++ b/pkg/bindings/pods/types_top_options.go @@ -2,12 +2,8 @@ package pods import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *TopOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *TopOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithDescriptors diff --git a/pkg/bindings/pods/types_unpause_options.go b/pkg/bindings/pods/types_unpause_options.go index 281f0ea8d..9575e3949 100644 --- a/pkg/bindings/pods/types_unpause_options.go +++ b/pkg/bindings/pods/types_unpause_options.go @@ -2,12 +2,8 @@ package pods import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *UnpauseOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *UnpauseOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/system/types_disk_options.go b/pkg/bindings/system/types_disk_options.go index 6f0c3735a..118d2e8d2 100644 --- a/pkg/bindings/system/types_disk_options.go +++ b/pkg/bindings/system/types_disk_options.go @@ -2,12 +2,8 @@ package system import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *DiskOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *DiskOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/system/types_events_options.go b/pkg/bindings/system/types_events_options.go index 401a9807e..f6717f38d 100644 --- a/pkg/bindings/system/types_events_options.go +++ b/pkg/bindings/system/types_events_options.go @@ -2,12 +2,8 @@ package system import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *EventsOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *EventsOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithFilters diff --git a/pkg/bindings/system/types_info_options.go b/pkg/bindings/system/types_info_options.go index 7c07b5081..bc6c67282 100644 --- a/pkg/bindings/system/types_info_options.go +++ b/pkg/bindings/system/types_info_options.go @@ -2,12 +2,8 @@ package system import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *InfoOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *InfoOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/system/types_prune_options.go b/pkg/bindings/system/types_prune_options.go index c677ccca6..c08a9baf3 100644 --- a/pkg/bindings/system/types_prune_options.go +++ b/pkg/bindings/system/types_prune_options.go @@ -2,12 +2,8 @@ package system import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *PruneOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *PruneOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithAll diff --git a/pkg/bindings/system/types_version_options.go b/pkg/bindings/system/types_version_options.go index 60ebfced9..fa6956677 100644 --- a/pkg/bindings/system/types_version_options.go +++ b/pkg/bindings/system/types_version_options.go @@ -2,12 +2,8 @@ package system import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *VersionOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *VersionOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/util/util.go b/pkg/bindings/util/util.go index 403846355..c1961308e 100644 --- a/pkg/bindings/util/util.go +++ b/pkg/bindings/util/util.go @@ -1,19 +1,34 @@ package util import ( + "errors" + "fmt" + "net/url" "reflect" "strconv" + "strings" + + jsoniter "github.com/json-iterator/go" ) func IsSimpleType(f reflect.Value) bool { + if _, ok := f.Interface().(fmt.Stringer); ok { + return true + } + switch f.Kind() { case reflect.Bool, reflect.Int, reflect.Int64, reflect.Uint, reflect.Uint64, reflect.String: return true } + return false } func SimpleTypeToParam(f reflect.Value) string { + if s, ok := f.Interface().(fmt.Stringer); ok { + return s.String() + } + switch f.Kind() { case reflect.Bool: return strconv.FormatBool(f.Bool()) @@ -26,5 +41,62 @@ func SimpleTypeToParam(f reflect.Value) string { case reflect.String: return f.String() } + panic("the input parameter is not a simple type") } + +func Changed(o interface{}, fieldName string) bool { + r := reflect.ValueOf(o) + value := reflect.Indirect(r).FieldByName(fieldName) + return !value.IsNil() +} + +func ToParams(o interface{}) (url.Values, error) { + params := url.Values{} + if o == nil || reflect.ValueOf(o).IsNil() { + return params, nil + } + json := jsoniter.ConfigCompatibleWithStandardLibrary + s := reflect.ValueOf(o) + if reflect.Ptr == s.Kind() { + s = s.Elem() + } + sType := s.Type() + for i := 0; i < s.NumField(); i++ { + fieldName := sType.Field(i).Name + if !Changed(o, fieldName) { + continue + } + fieldName = strings.ToLower(fieldName) + f := s.Field(i) + if reflect.Ptr == f.Kind() { + f = f.Elem() + } + switch { + case IsSimpleType(f): + params.Set(fieldName, SimpleTypeToParam(f)) + case f.Kind() == reflect.Slice: + for i := 0; i < f.Len(); i++ { + elem := f.Index(i) + if IsSimpleType(elem) { + params.Add(fieldName, SimpleTypeToParam(elem)) + } else { + return nil, errors.New("slices must contain only simple types") + } + } + case f.Kind() == reflect.Map: + lowerCaseKeys := make(map[string][]string) + iter := f.MapRange() + for iter.Next() { + lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) + } + s, err := json.MarshalToString(lowerCaseKeys) + if err != nil { + return nil, err + } + + params.Set(fieldName, s) + } + } + return params, nil +} diff --git a/pkg/bindings/volumes/types_create_options.go b/pkg/bindings/volumes/types_create_options.go index 2254f8c13..45053e261 100644 --- a/pkg/bindings/volumes/types_create_options.go +++ b/pkg/bindings/volumes/types_create_options.go @@ -2,12 +2,8 @@ package volumes import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *CreateOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *CreateOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/volumes/types_inspect_options.go b/pkg/bindings/volumes/types_inspect_options.go index 51ac2d348..e6397a0d2 100644 --- a/pkg/bindings/volumes/types_inspect_options.go +++ b/pkg/bindings/volumes/types_inspect_options.go @@ -2,12 +2,8 @@ package volumes import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *InspectOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *InspectOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/volumes/types_list_options.go b/pkg/bindings/volumes/types_list_options.go index c96e647b0..103515e99 100644 --- a/pkg/bindings/volumes/types_list_options.go +++ b/pkg/bindings/volumes/types_list_options.go @@ -2,12 +2,8 @@ package volumes import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ListOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *ListOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithFilters diff --git a/pkg/bindings/volumes/types_prune_options.go b/pkg/bindings/volumes/types_prune_options.go index 06d16b659..eb910e05d 100644 --- a/pkg/bindings/volumes/types_prune_options.go +++ b/pkg/bindings/volumes/types_prune_options.go @@ -2,12 +2,8 @@ package volumes import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *PruneOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *PruneOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithFilters diff --git a/pkg/bindings/volumes/types_remove_options.go b/pkg/bindings/volumes/types_remove_options.go index 4b0037234..30cb923c7 100644 --- a/pkg/bindings/volumes/types_remove_options.go +++ b/pkg/bindings/volumes/types_remove_options.go @@ -2,12 +2,8 @@ package volumes import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,62 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *RemoveOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *RemoveOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - switch { - case util.IsSimpleType(f): - params.Set(fieldName, util.SimpleTypeToParam(f)) - case f.Kind() == reflect.Slice: - for i := 0; i < f.Len(); i++ { - elem := f.Index(i) - if util.IsSimpleType(elem) { - params.Add(fieldName, util.SimpleTypeToParam(elem)) - } else { - return nil, errors.New("slices must contain only simple types") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - - } - return params, nil + return util.ToParams(o) } // WithForce diff --git a/pkg/cgroups/cpu.go b/pkg/cgroups/cpu.go index a73187dc8..05223c2e1 100644 --- a/pkg/cgroups/cpu.go +++ b/pkg/cgroups/cpu.go @@ -155,7 +155,6 @@ func GetSystemCPUUsage() (uint64, error) { } total += v * 1000 } - } return total, nil } diff --git a/pkg/copy/fileinfo.go b/pkg/copy/fileinfo.go index ddb9b629c..b95bcd90c 100644 --- a/pkg/copy/fileinfo.go +++ b/pkg/copy/fileinfo.go @@ -16,9 +16,9 @@ import ( // base64 encoded JSON payload of stating a path in a container. const XDockerContainerPathStatHeader = "X-Docker-Container-Path-Stat" -// ENOENT mimics the stdlib's ENOENT and can be used to implement custom logic +// ErrENOENT mimics the stdlib's ErrENOENT and can be used to implement custom logic // while preserving the user-visible error message. -var ENOENT = errors.New("No such file or directory") +var ErrENOENT = errors.New("No such file or directory") // FileInfo describes a file or directory and is returned by // (*CopyItem).Stat(). @@ -70,7 +70,7 @@ func ResolveHostPath(path string) (*FileInfo, error) { statInfo, err := os.Stat(resolvedHostPath) if err != nil { if os.IsNotExist(err) { - return nil, ENOENT + return nil, ErrENOENT } return nil, err } diff --git a/pkg/domain/entities/network.go b/pkg/domain/entities/network.go index b76bfcac7..95608f01b 100644 --- a/pkg/domain/entities/network.go +++ b/pkg/domain/entities/network.go @@ -31,6 +31,7 @@ type NetworkReloadOptions struct { // NetworkReloadReport describes the results of reloading a container network. type NetworkReloadReport struct { + // nolint:stylecheck,golint Id string Err error } diff --git a/pkg/domain/infra/abi/containers_stat.go b/pkg/domain/infra/abi/containers_stat.go index f3d0799a0..1844f4019 100644 --- a/pkg/domain/infra/abi/containers_stat.go +++ b/pkg/domain/infra/abi/containers_stat.go @@ -35,7 +35,7 @@ func (ic *ContainerEngine) containerStat(container *libpod.Container, containerM // ENOENT let's the API handlers return the correct status code // which is crucial for the remote client. if os.IsNotExist(err) || strings.Contains(statInfoErr.Error(), "o such file or directory") { - statInfoErr = copy.ENOENT + statInfoErr = copy.ErrENOENT } // If statInfo is nil, there's nothing we can do anymore. A // non-nil statInfo may indicate a symlink where we must have @@ -129,7 +129,7 @@ func secureStat(root string, path string) (*buildahCopiah.StatForItem, error) { stat, exists := globStats[0].Results[glob] // only one glob passed, so that's okay if !exists { - return nil, copy.ENOENT + return nil, copy.ErrENOENT } var statErr error diff --git a/pkg/domain/infra/abi/images.go b/pkg/domain/infra/abi/images.go index f2d0f2c39..fb01c72b6 100644 --- a/pkg/domain/infra/abi/images.go +++ b/pkg/domain/infra/abi/images.go @@ -40,10 +40,9 @@ func (ir *ImageEngine) Exists(_ context.Context, nameOrID string) (*entities.Boo if err != nil { if errors.Cause(err) == define.ErrMultipleImages { return &entities.BoolReport{Value: true}, nil - } else { - if errors.Cause(err) != define.ErrNoSuchImage { - return nil, err - } + } + if errors.Cause(err) != define.ErrNoSuchImage { + return nil, err } } return &entities.BoolReport{Value: err == nil}, nil @@ -270,7 +269,6 @@ func pull(ctx context.Context, runtime *image.Runtime, rawImage string, options } if _, isTagged := namedRef.(reference.Tagged); isTagged { return nil, errors.New("--all-tags requires a reference without a tag") - } systemContext := image.GetSystemContext("", options.Authfile, false) @@ -503,7 +501,6 @@ func (ir *ImageEngine) Config(_ context.Context) (*config.Config, error) { } func (ir *ImageEngine) Build(ctx context.Context, containerFiles []string, opts entities.BuildOptions) (*entities.BuildReport, error) { - id, _, err := ir.Libpod.Build(ctx, opts.BuildOptions, containerFiles...) if err != nil { return nil, err diff --git a/pkg/domain/infra/abi/manifest.go b/pkg/domain/infra/abi/manifest.go index 139032ad6..e3cf20863 100644 --- a/pkg/domain/infra/abi/manifest.go +++ b/pkg/domain/infra/abi/manifest.go @@ -1,5 +1,3 @@ -// +build !remote - package abi import ( diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go index 70c7104f1..35a84106f 100644 --- a/pkg/domain/infra/abi/play.go +++ b/pkg/domain/infra/abi/play.go @@ -60,7 +60,6 @@ func (ic *ContainerEngine) PlayKube(ctx context.Context, path string, options en default: return nil, errors.Errorf("invalid YAML kind: %q. [Pod|Deployment] are the only supported Kubernetes Kinds", kubeObject.Kind) } - } func (ic *ContainerEngine) playKubeDeployment(ctx context.Context, deploymentYAML *v1apps.Deployment, options entities.PlayKubeOptions) (*entities.PlayKubeReport, error) { diff --git a/pkg/domain/infra/abi/system.go b/pkg/domain/infra/abi/system.go index f29b98696..c68a12414 100644 --- a/pkg/domain/infra/abi/system.go +++ b/pkg/domain/infra/abi/system.go @@ -82,7 +82,7 @@ func (ic *ContainerEngine) SetupRootless(_ context.Context, cmd *cobra.Command) unitName := fmt.Sprintf("podman-%d.scope", os.Getpid()) if runsUnderSystemd || conf.Engine.CgroupManager == config.SystemdCgroupsManager { if err := utils.RunUnderSystemdScope(os.Getpid(), "user.slice", unitName); err != nil { - logrus.Warnf("Failed to add podman to systemd sandbox cgroup: %v", err) + logrus.Debugf("Failed to add podman to systemd sandbox cgroup: %v", err) } } } diff --git a/pkg/domain/infra/tunnel/containers.go b/pkg/domain/infra/tunnel/containers.go index e9c513f8e..c2c282ef9 100644 --- a/pkg/domain/infra/tunnel/containers.go +++ b/pkg/domain/infra/tunnel/containers.go @@ -290,7 +290,6 @@ func (ic *ContainerEngine) ContainerCheckpoint(ctx context.Context, namesOrIds [ ctrs = append(ctrs, c) } } - } else { ctrs, err = getContainersByContext(ic.ClientCtx, false, false, namesOrIds) if err != nil { @@ -326,7 +325,6 @@ func (ic *ContainerEngine) ContainerRestore(ctx context.Context, namesOrIds []st ctrs = append(ctrs, c) } } - } else { ctrs, err = getContainersByContext(ic.ClientCtx, false, false, namesOrIds) if err != nil { @@ -570,7 +568,6 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri } // Start the container if it's not running already. if !ctrRunning { - err = containers.Start(ic.ClientCtx, name, new(containers.StartOptions).WithDetachKeys(options.DetachKeys)) if err != nil { if ctr.AutoRemove { diff --git a/pkg/domain/infra/tunnel/helpers.go b/pkg/domain/infra/tunnel/helpers.go index 0a806d860..e40e27596 100644 --- a/pkg/domain/infra/tunnel/helpers.go +++ b/pkg/domain/infra/tunnel/helpers.go @@ -55,7 +55,6 @@ func getContainersByContext(contextWithConnection context.Context, all, ignore b found = true break } - } if !found && !ignore { @@ -107,7 +106,6 @@ func getPodsByContext(contextWithConnection context.Context, all bool, namesOrID found = true break } - } if !found { diff --git a/pkg/domain/infra/tunnel/images.go b/pkg/domain/infra/tunnel/images.go index 0fe2387d7..b5f09ab22 100644 --- a/pkg/domain/infra/tunnel/images.go +++ b/pkg/domain/infra/tunnel/images.go @@ -32,7 +32,6 @@ func (ir *ImageEngine) Remove(ctx context.Context, imagesArg []string, opts enti } func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions) ([]*entities.ImageSummary, error) { - filters := make(map[string][]string, len(opts.Filter)) for _, filter := range opts.Filter { f := strings.Split(filter, "=") @@ -350,17 +349,6 @@ func (ir *ImageEngine) Build(_ context.Context, containerFiles []string, opts en if err != nil { return nil, err } - // For remote clients, if the option for writing to a file was - // selected, we need to write to the *client's* filesystem. - if len(opts.IIDFile) > 0 { - f, err := os.Create(opts.IIDFile) - if err != nil { - return nil, err - } - if _, err := f.WriteString(report.ID); err != nil { - return nil, err - } - } return report, nil } diff --git a/pkg/lookup/lookup.go b/pkg/lookup/lookup.go index 8f241edf2..0b22a1974 100644 --- a/pkg/lookup/lookup.go +++ b/pkg/lookup/lookup.go @@ -66,7 +66,6 @@ func GetUserGroupInfo(containerMount, containerUser string, override *Overrides) // Gid: 0, // Home: "/", defaultExecUser = nil - } return user.GetExecUserPath(containerUser, defaultExecUser, passwdDest, groupDest) diff --git a/pkg/netns/netns_linux.go b/pkg/netns/netns_linux.go index 6817a3abd..95b50e073 100644 --- a/pkg/netns/netns_linux.go +++ b/pkg/netns/netns_linux.go @@ -51,7 +51,6 @@ func getNSRunDir() (string, error) { // NewNS creates a new persistent (bind-mounted) network namespace and returns // an object representing that namespace, without switching to it. func NewNS() (ns.NetNS, error) { - nsRunDir, err := getNSRunDir() if err != nil { return nil, err @@ -92,7 +91,6 @@ func NewNS() (ns.NetNS, error) { if err != nil { return nil, fmt.Errorf("mount --make-rshared %s failed: %q", nsRunDir, err) } - } nsName := fmt.Sprintf("cni-%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:]) diff --git a/pkg/rootless/rootless.go b/pkg/rootless/rootless.go index df35c0d6b..b5538efc3 100644 --- a/pkg/rootless/rootless.go +++ b/pkg/rootless/rootless.go @@ -61,9 +61,9 @@ var ( gidMapOnce sync.Once ) -// GetAvailableUidMap returns the UID mappings in the +// GetAvailableUIDMap returns the UID mappings in the // current user namespace. -func GetAvailableUidMap() ([]user.IDMap, error) { +func GetAvailableUIDMap() ([]user.IDMap, error) { uidMapOnce.Do(func() { var err error uidMap, err = user.ParseIDMapFile("/proc/self/uid_map") @@ -75,9 +75,9 @@ func GetAvailableUidMap() ([]user.IDMap, error) { return uidMap, uidMapError } -// GetAvailableGidMap returns the GID mappings in the +// GetAvailableGIDMap returns the GID mappings in the // current user namespace. -func GetAvailableGidMap() ([]user.IDMap, error) { +func GetAvailableGIDMap() ([]user.IDMap, error) { gidMapOnce.Do(func() { var err error gidMap, err = user.ParseIDMapFile("/proc/self/gid_map") @@ -92,11 +92,11 @@ func GetAvailableGidMap() ([]user.IDMap, error) { // GetAvailableIDMaps returns the UID and GID mappings in the // current user namespace. func GetAvailableIDMaps() ([]user.IDMap, []user.IDMap, error) { - u, err := GetAvailableUidMap() + u, err := GetAvailableUIDMap() if err != nil { return nil, nil, err } - g, err := GetAvailableGidMap() + g, err := GetAvailableGIDMap() if err != nil { return nil, nil, err } @@ -114,7 +114,7 @@ func countAvailableIDs(mappings []user.IDMap) int64 { // GetAvailableUids returns how many UIDs are available in the // current user namespace. func GetAvailableUids() (int64, error) { - uids, err := GetAvailableUidMap() + uids, err := GetAvailableUIDMap() if err != nil { return -1, err } @@ -125,7 +125,7 @@ func GetAvailableUids() (int64, error) { // GetAvailableGids returns how many GIDs are available in the // current user namespace. func GetAvailableGids() (int64, error) { - gids, err := GetAvailableGidMap() + gids, err := GetAvailableGIDMap() if err != nil { return -1, err } diff --git a/pkg/rootlessport/rootlessport_linux.go b/pkg/rootlessport/rootlessport_linux.go index 80e1309a5..7cb54a7c3 100644 --- a/pkg/rootlessport/rootlessport_linux.go +++ b/pkg/rootlessport/rootlessport_linux.go @@ -64,7 +64,6 @@ func init() { os.Exit(1) } }) - } func loadConfig(r io.Reader) (*Config, io.ReadCloser, io.WriteCloser, error) { diff --git a/pkg/specgen/container_validate.go b/pkg/specgen/container_validate.go index 81cb8b78d..042e20e02 100644 --- a/pkg/specgen/container_validate.go +++ b/pkg/specgen/container_validate.go @@ -29,7 +29,6 @@ func exclusiveOptions(opt1, opt2 string) error { // Validate verifies that the given SpecGenerator is valid and satisfies required // input for creating a container. func (s *SpecGenerator) Validate() error { - if rootless.IsRootless() && len(s.CNINetworks) == 0 { if s.StaticIP != nil || s.StaticIPv6 != nil { return ErrNoStaticIPRootless diff --git a/pkg/specgen/generate/config_linux.go b/pkg/specgen/generate/config_linux.go index 1290a8eb6..b9f024814 100644 --- a/pkg/specgen/generate/config_linux.go +++ b/pkg/specgen/generate/config_linux.go @@ -113,7 +113,6 @@ func DevicesFromPath(g *generate.Generator, devicePath string) error { // mount the internal devices recursively if err := filepath.Walk(resolvedDevicePath, func(dpath string, f os.FileInfo, e error) error { - if f.Mode()&os.ModeDevice == os.ModeDevice { found = true device := fmt.Sprintf("%s:%s", dpath, filepath.Join(dest, strings.TrimPrefix(dpath, src))) diff --git a/pkg/specgen/generate/kube/kube.go b/pkg/specgen/generate/kube/kube.go index 98ab82259..e04ced3d3 100644 --- a/pkg/specgen/generate/kube/kube.go +++ b/pkg/specgen/generate/kube/kube.go @@ -384,7 +384,6 @@ func getPodPorts(containers []v1.Container) []specgen.PortMapping { if p.HostPort != 0 { infraPorts = append(infraPorts, portBinding) } - } } return infraPorts diff --git a/pkg/specgen/generate/kube/seccomp.go b/pkg/specgen/generate/kube/seccomp.go index 4cbdf6e2e..353f9cbf2 100644 --- a/pkg/specgen/generate/kube/seccomp.go +++ b/pkg/specgen/generate/kube/seccomp.go @@ -11,6 +11,7 @@ import ( // KubeSeccompPaths holds information about a pod YAML's seccomp configuration // it holds both container and pod seccomp paths +// nolint:golint type KubeSeccompPaths struct { containerPaths map[string]string podPath string diff --git a/pkg/specgen/generate/kube/volume.go b/pkg/specgen/generate/kube/volume.go index f5687f60d..c3241a49e 100644 --- a/pkg/specgen/generate/kube/volume.go +++ b/pkg/specgen/generate/kube/volume.go @@ -17,6 +17,7 @@ const ( kubeFilePermission = 0644 ) +// nolint:golint type KubeVolumeType int const ( @@ -24,6 +25,7 @@ const ( KubeVolumeTypeNamed KubeVolumeType = iota ) +// nolint:golint type KubeVolume struct { // Type of volume to create Type KubeVolumeType diff --git a/pkg/specgen/generate/oci.go b/pkg/specgen/generate/oci.go index e62131244..eefe45dfe 100644 --- a/pkg/specgen/generate/oci.go +++ b/pkg/specgen/generate/oci.go @@ -105,7 +105,10 @@ func makeCommand(ctx context.Context, s *specgen.SpecGenerator, img *image.Image entrypoint = newEntry } - finalCommand = append(finalCommand, entrypoint...) + // Don't append the entrypoint if it is [""] + if len(entrypoint) != 1 || entrypoint[0] != "" { + finalCommand = append(finalCommand, entrypoint...) + } // Only use image command if the user did not manually set an // entrypoint. @@ -219,7 +222,6 @@ func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runt if !mappingFound { gid5Available = false } - } if !gid5Available { // If we have no GID mappings, the gid=5 default option would fail, so drop it. diff --git a/pkg/specgen/generate/security.go b/pkg/specgen/generate/security.go index 390b19beb..fb45d87db 100644 --- a/pkg/specgen/generate/security.go +++ b/pkg/specgen/generate/security.go @@ -109,17 +109,15 @@ func securityConfigureGenerator(s *specgen.SpecGenerator, g *generate.Generator, } } if !s.Privileged && len(capsRequiredRequested) > 0 { - // Pass capRequiredRequested in CapAdd field to normalize capabilities names capsRequired, err := capabilities.MergeCapabilities(nil, capsRequiredRequested, nil) if err != nil { return errors.Wrapf(err, "capabilities requested by user or image are not valid: %q", strings.Join(capsRequired, ",")) - } else { - // Verify all capRequired are in the capList - for _, cap := range capsRequired { - if !util.StringInSlice(cap, caplist) { - privCapsRequired = append(privCapsRequired, cap) - } + } + // Verify all capRequired are in the capList + for _, cap := range capsRequired { + if !util.StringInSlice(cap, caplist) { + privCapsRequired = append(privCapsRequired, cap) } } if len(privCapsRequired) == 0 { @@ -189,7 +187,6 @@ func securityConfigureGenerator(s *specgen.SpecGenerator, g *generate.Generator, return err } for sysctlKey, sysctlVal := range defaultSysctls { - // Ignore mqueue sysctls if --ipc=host if noUseIPC && strings.HasPrefix(sysctlKey, "fs.mqueue.") { logrus.Infof("Sysctl %s=%s ignored in containers.conf, since IPC Namespace set to host", sysctlKey, sysctlVal) @@ -213,7 +210,6 @@ func securityConfigureGenerator(s *specgen.SpecGenerator, g *generate.Generator, } for sysctlKey, sysctlVal := range s.Sysctl { - if s.IpcNS.IsHost() && strings.HasPrefix(sysctlKey, "fs.mqueue.") { return errors.Wrapf(define.ErrInvalidArg, "sysctl %s=%s can't be set since IPC Namespace set to host", sysctlKey, sysctlVal) } diff --git a/pkg/specgen/pod_validate.go b/pkg/specgen/pod_validate.go index 518adb32f..c9bcdf623 100644 --- a/pkg/specgen/pod_validate.go +++ b/pkg/specgen/pod_validate.go @@ -19,7 +19,6 @@ func exclusivePodOptions(opt1, opt2 string) error { // Validate verifies the input is valid func (p *PodSpecGenerator) Validate() error { - if rootless.IsRootless() && len(p.CNINetworks) == 0 { if p.StaticIP != nil { return ErrNoStaticIPRootless diff --git a/pkg/systemd/generate/common_test.go b/pkg/systemd/generate/common_test.go index a0691d1ad..3787e461e 100644 --- a/pkg/systemd/generate/common_test.go +++ b/pkg/systemd/generate/common_test.go @@ -8,7 +8,6 @@ import ( ) func TestFilterPodFlags(t *testing.T) { - tests := []struct { input []string }{ diff --git a/pkg/systemd/generate/containers.go b/pkg/systemd/generate/containers.go index abe159812..acee7be65 100644 --- a/pkg/systemd/generate/containers.go +++ b/pkg/systemd/generate/containers.go @@ -68,7 +68,7 @@ type containerInfo struct { // If not nil, the container is part of the pod. We can use the // podInfo to extract the relevant data. - pod *podInfo + Pod *podInfo } const containerTemplate = headerTemplate + ` @@ -215,8 +215,8 @@ func executeContainerTemplate(info *containerInfo, options entities.GenerateSyst ) // If the container is in a pod, make sure that the // --pod-id-file is set correctly. - if info.pod != nil { - podFlags := []string{"--pod-id-file", info.pod.PodIDFile} + if info.Pod != nil { + podFlags := []string{"--pod-id-file", "{{{{.Pod.PodIDFile}}}}"} startCommand = append(startCommand, podFlags...) info.CreateCommand = filterPodFlags(info.CreateCommand) } diff --git a/pkg/systemd/generate/containers_test.go b/pkg/systemd/generate/containers_test.go index be14e4c28..dad14ece9 100644 --- a/pkg/systemd/generate/containers_test.go +++ b/pkg/systemd/generate/containers_test.go @@ -170,7 +170,7 @@ Environment=PODMAN_SYSTEMD_UNIT=%n Restart=always TimeoutStopSec=70 ExecStartPre=/bin/rm -f %t/jadda-jadda.pid %t/jadda-jadda.ctr-id -ExecStart=/usr/bin/podman run --conmon-pidfile %t/jadda-jadda.pid --cidfile %t/jadda-jadda.ctr-id --cgroups=no-conmon --pod-id-file /tmp/pod-foobar.pod-id-file --replace -d --name jadda-jadda --hostname hello-world awesome-image:latest command arg1 ... argN +ExecStart=/usr/bin/podman run --conmon-pidfile %t/jadda-jadda.pid --cidfile %t/jadda-jadda.ctr-id --cgroups=no-conmon --pod-id-file %t/pod-foobar.pod-id-file --replace -d --name jadda-jadda --hostname hello-world awesome-image:latest command arg1 ... argN ExecStop=/usr/bin/podman stop --ignore --cidfile %t/jadda-jadda.ctr-id -t 10 ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/jadda-jadda.ctr-id PIDFile=%t/jadda-jadda.pid @@ -487,8 +487,8 @@ WantedBy=multi-user.target default.target PodmanVersion: "CI", CreateCommand: []string{"I'll get stripped", "run", "-d", "--name", "jadda-jadda", "--hostname", "hello-world", "awesome-image:latest", "command", "arg1", "...", "argN"}, EnvVariable: EnvVariable, - pod: &podInfo{ - PodIDFile: "/tmp/pod-foobar.pod-id-file", + Pod: &podInfo{ + PodIDFile: "%t/pod-foobar.pod-id-file", }, }, goodNameNewWithPodFile, diff --git a/pkg/systemd/generate/pods.go b/pkg/systemd/generate/pods.go index d6ede19af..ff8ce3a03 100644 --- a/pkg/systemd/generate/pods.go +++ b/pkg/systemd/generate/pods.go @@ -162,7 +162,7 @@ func PodUnits(pod *libpod.Pod, options entities.GenerateSystemdOptions) (map[str } units[podInfo.ServiceName] = out for _, info := range containerInfos { - info.pod = podInfo + info.Pod = podInfo out, err := executeContainerTemplate(info, options) if err != nil { return nil, err diff --git a/pkg/trust/trust.go b/pkg/trust/trust.go index a30611b74..18a6a1717 100644 --- a/pkg/trust/trust.go +++ b/pkg/trust/trust.go @@ -179,7 +179,6 @@ func CreateTmpFile(dir, pattern string, content []byte) (string, error) { if _, err := tmpfile.Write(content); err != nil { return "", err - } return tmpfile.Name(), nil } diff --git a/pkg/util/utils.go b/pkg/util/utils.go index e0f631eb4..32bb66332 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -388,7 +388,6 @@ func GetKeepIDMapping() (*storage.IDMappingOptions, int, int, error) { options.HostUIDMapping = false options.HostGIDMapping = false - } // Simply ignore the setting and do not setup an inner namespace for root as it is a no-op return &options, uid, gid, nil @@ -530,9 +529,9 @@ func ParseInputTime(inputTime string) (time.Time, error) { } } - unix_timestamp, err := strconv.ParseInt(inputTime, 10, 64) + unixTimestamp, err := strconv.ParseInt(inputTime, 10, 64) if err == nil { - return time.Unix(unix_timestamp, 0), nil + return time.Unix(unixTimestamp, 0), nil } // input might be a duration |