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

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

示例1: TestSysGenerateRootAttempt_Status

func TestSysGenerateRootAttempt_Status(t *testing.T) {
    core, _, token := vault.TestCoreUnsealed(t)
    ln, addr := TestServer(t, core)
    defer ln.Close()
    TestServerAuth(t, addr, token)

    resp, err := http.Get(addr + "/v1/sys/generate-root/attempt")
    if err != nil {
        t.Fatalf("err: %s", err)
    }

    var actual map[string]interface{}
    expected := map[string]interface{}{
        "started":            false,
        "progress":           json.Number("0"),
        "required":           json.Number("1"),
        "complete":           false,
        "encoded_root_token": "",
        "pgp_fingerprint":    "",
        "nonce":              "",
    }
    testResponseStatus(t, resp, 200)
    testResponseBody(t, resp, &actual)
    if !reflect.DeepEqual(actual, expected) {
        t.Fatalf("\nexpected: %#v\nactual: %#v", expected, actual)
    }
}

开发者ID:quixoten,项目名称:vault,代码行数:27,代码来源:sys_generate_root_test.go

示例2: TestSelectJSONNumbers

func (s *RethinkSuite) TestSelectJSONNumbers(c *test.C) {
    session, err := Connect(ConnectOpts{
        Address:       url,
        UseJSONNumber: true,
    })
    c.Assert(err, test.IsNil)
    defer session.Close()
    // Ensure table + database exist
    DBCreate("test").Exec(session)
    DB("test").TableCreate("Table1").Exec(session)

    // Insert rows
    DB("test").Table("Table1").Insert(objList).Exec(session)

    // Test query
    var response interface{}
    query := DB("test").Table("Table1").Get(6)
    res, err := query.Run(session)
    c.Assert(err, test.IsNil)

    err = res.One(&response)

    c.Assert(err, test.IsNil)
    c.Assert(response, jsonEquals, map[string]interface{}{"id": json.Number("6"), "g1": json.Number("1"), "g2": json.Number("1"), "num": json.Number("15")})

    res.Close()
}

开发者ID:XuesongYang,项目名称:shipyard,代码行数:27,代码来源:query_select_test.go

示例3: TestSysGenerateRootAttempt_Setup_PGP

func TestSysGenerateRootAttempt_Setup_PGP(t *testing.T) {
    core, _, token := vault.TestCoreUnsealed(t)
    ln, addr := TestServer(t, core)
    defer ln.Close()
    TestServerAuth(t, addr, token)

    resp := testHttpPut(t, token, addr+"/v1/sys/generate-root/attempt", map[string]interface{}{
        "pgp_key": pgpkeys.TestPubKey1,
    })
    testResponseStatus(t, resp, 200)

    resp = testHttpGet(t, token, addr+"/v1/sys/generate-root/attempt")

    var actual map[string]interface{}
    expected := map[string]interface{}{
        "started":            true,
        "progress":           json.Number("0"),
        "required":           json.Number("1"),
        "complete":           false,
        "encoded_root_token": "",
        "pgp_fingerprint":    "816938b8a29146fbe245dd29e7cbaf8e011db793",
    }
    testResponseStatus(t, resp, 200)
    testResponseBody(t, resp, &actual)
    if actual["nonce"].(string) == "" {
        t.Fatalf("nonce was empty")
    }
    expected["nonce"] = actual["nonce"]
    if !reflect.DeepEqual(actual, expected) {
        t.Fatalf("\nexpected: %#v\nactual: %#v", expected, actual)
    }
}

开发者ID:quixoten,项目名称:vault,代码行数:32,代码来源:sys_generate_root_test.go

示例4: MarshalJSON

// MarshalJSON implements the "encoding/json".Marshaler interface for
// ValueList.
func (vl *ValueList) MarshalJSON() ([]byte, error) {
    jvl := jsonValueList{
        Values:         make([]json.Number, len(vl.Values)),
        DSTypes:        make([]string, len(vl.Values)),
        DSNames:        make([]string, len(vl.Values)),
        Time:           cdtime.New(vl.Time),
        Interval:       cdtime.NewDuration(vl.Interval),
        Host:           vl.Host,
        Plugin:         vl.Plugin,
        PluginInstance: vl.PluginInstance,
        Type:           vl.Type,
        TypeInstance:   vl.TypeInstance,
    }

    for i, v := range vl.Values {
        switch v := v.(type) {
        case Gauge:
            jvl.Values[i] = json.Number(fmt.Sprintf("%.15g", v))
        case Derive:
            jvl.Values[i] = json.Number(fmt.Sprintf("%d", v))
        case Counter:
            jvl.Values[i] = json.Number(fmt.Sprintf("%d", v))
        default:
            return nil, fmt.Errorf("unexpected data source type: %T", v)
        }
        jvl.DSTypes[i] = v.Type()
        jvl.DSNames[i] = vl.DSName(i)
    }

    return json.Marshal(jvl)
}

开发者ID:octo,项目名称:collectd_exporter,代码行数:33,代码来源:json.go

示例5: TestSysRekeyInit_Status

func TestSysRekeyInit_Status(t *testing.T) {
    core, _, token := vault.TestCoreUnsealed(t)
    ln, addr := TestServer(t, core)
    defer ln.Close()
    TestServerAuth(t, addr, token)

    resp, err := http.Get(addr + "/v1/sys/rekey/init")
    if err != nil {
        t.Fatalf("err: %s", err)
    }

    var actual map[string]interface{}
    expected := map[string]interface{}{
        "started":          false,
        "t":                json.Number("0"),
        "n":                json.Number("0"),
        "progress":         json.Number("0"),
        "required":         json.Number("1"),
        "pgp_fingerprints": interface{}(nil),
        "backup":           false,
        "nonce":            "",
    }
    testResponseStatus(t, resp, 200)
    testResponseBody(t, resp, &actual)
    if !reflect.DeepEqual(actual, expected) {
        t.Fatalf("\nexpected: %#v\nactual: %#v", expected, actual)
    }
}

开发者ID:mhurne,项目名称:vault,代码行数:28,代码来源:sys_rekey_test.go

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