本文整理汇总了Golang中encoding/json.Unmarshal函数的典型用法代码### 示例。如果您正苦于以下问题:Golang Unmarshal函数的具体用法?Golang Unmarshal怎么用?Golang Unmarshal使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。

在下文中一共展示了Unmarshal函数的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。

示例1: makeRawConfigFromV1Config

func makeRawConfigFromV1Config(imageJSON []byte, rootfs *image.RootFS, history []image.History) (map[string]*json.RawMessage, error) {
    var dver struct {
        DockerVersion string `json:"docker_version"`
    }

    if err := json.Unmarshal(imageJSON, &dver); err != nil {
        return nil, err
    }

    useFallback := versionPkg.Version(dver.DockerVersion).LessThan("1.8.3")

    if useFallback {
        var v1Image image.V1Image
        err := json.Unmarshal(imageJSON, &v1Image)
        if err != nil {
            return nil, err
        }
        imageJSON, err = json.Marshal(v1Image)
        if err != nil {
            return nil, err
        }
    }

    var c map[string]*json.RawMessage
    if err := json.Unmarshal(imageJSON, &c); err != nil {
        return nil, err
    }

    c["rootfs"] = rawJSON(rootfs)
    c["history"] = rawJSON(history)

    return c, nil
}

开发者ID:doublek420,项目名称:skopeo,代码行数:33,代码来源:inspect.go

示例2: compareObjects

// What we're trying to do here is compare the JSON encoded values, but we can't
// to a simple encode + string compare since JSON encoding is not ordered. So
// what we do is JSON encode, then JSON decode into untyped maps, and then
// finally do a recursive comparison.
func compareObjects(t *testing.T, expected interface{}, actual interface{}) {
    expectedBytes, err := json.Marshal(expected)
    if err != nil {
        t.Fatal(err)
        return
    }
    actualBytes, err := json.Marshal(actual)
    if err != nil {
        t.Fatal(err)
        return
    }
    var expectedUntyped, actualUntyped map[string]interface{}
    err = json.Unmarshal(expectedBytes, &expectedUntyped)
    if err != nil {
        t.Fatal(err)
        return
    }
    err = json.Unmarshal(actualBytes, &actualUntyped)
    if err != nil {
        t.Fatal(err)
        return
    }
    if !reflect.DeepEqual(expectedUntyped, actualUntyped) {
        t.Fatalf("Expected %s, got %s", string(expectedBytes), string(actualBytes))
    }
}

开发者ID:docker,项目名称:goamz,代码行数:30,代码来源:dynamizer_test.go

示例3: UtilCreateNetworkMode

func UtilCreateNetworkMode(c *check.C, networkMode string) {
    config := map[string]interface{}{
        "Image":      "busybox",
        "HostConfig": map[string]interface{}{"NetworkMode": networkMode},
    }

    status, body, err := sockRequest("POST", "/containers/create", config)
    c.Assert(err, check.IsNil)
    c.Assert(status, check.Equals, http.StatusCreated)

    var container types.ContainerCreateResponse
    if err := json.Unmarshal(body, &container); err != nil {
        c.Fatal(err)
    }

    status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
    c.Assert(err, check.IsNil)
    c.Assert(status, check.Equals, http.StatusOK)

    var containerJSON types.ContainerJSON
    if err := json.Unmarshal(body, &containerJSON); err != nil {
        c.Fatal(err)
    }

    if containerJSON.HostConfig.NetworkMode != runconfig.NetworkMode(networkMode) {
        c.Fatalf("Mismatched NetworkMode, Expected %s, Actual: %s ", networkMode, containerJSON.HostConfig.NetworkMode)
    }
}

开发者ID:previousnext,项目名称:kube-ingress,代码行数:28,代码来源:docker_api_containers_test.go

示例4: modUser

func (u *httpAuthUserAPI) modUser(ctx context.Context, req *authUserAPIAction) (*User, error) {
    resp, body, err := u.client.Do(ctx, req)
    if err != nil {
        return nil, err
    }
    if err = assertStatusCode(resp.StatusCode, http.StatusOK); err != nil {
        var sec authError
        err = json.Unmarshal(body, &sec)
        if err != nil {
            return nil, err
        }
        return nil, sec
    }
    var user User
    if err = json.Unmarshal(body, &user); err != nil {
        var userR UserRoles
        if urerr := json.Unmarshal(body, &userR); urerr != nil {
            return nil, err
        }
        user.User = userR.User
        for _, r := range userR.Roles {
            user.Roles = append(user.Roles, r.Role)
        }
    }
    return &user, nil
}

开发者ID:kjplatz,项目名称:vic,代码行数:26,代码来源:auth_user.go

示例5: ManifestMatchesImage

// ManifestMatchesImage returns true if the provided manifest matches the name of the image.
func ManifestMatchesImage(image *Image, newManifest []byte) (bool, error) {
    dgst, err := digest.ParseDigest(image.Name)
    if err != nil {
        return false, err
    }
    v, err := digest.NewDigestVerifier(dgst)
    if err != nil {
        return false, err
    }
    var canonical []byte

    switch image.DockerImageManifestMediaType {
    case schema2.MediaTypeManifest:
        var m schema2.DeserializedManifest
        if err := json.Unmarshal(newManifest, &m); err != nil {
            return false, err
        }
        _, canonical, err = m.Payload()
        if err != nil {
            return false, err
        }
    case schema1.MediaTypeManifest, "":
        var m schema1.SignedManifest
        if err := json.Unmarshal(newManifest, &m); err != nil {
            return false, err
        }
        canonical = m.Canonical
    default:
        return false, fmt.Errorf("unsupported manifest mediatype: %s", image.DockerImageManifestMediaType)
    }
    if _, err := v.Write(canonical); err != nil {
        return false, err
    }
    return v.Verified(), nil
}

开发者ID:tracyrankin,项目名称:origin,代码行数:36,代码来源:helper.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng