本文整理汇总了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
示例6: TestJsonParametersGetter
func TestJsonParametersGetter(t *testing.T) {
p := &JsonParametersGetter{
values: map[string]interface{}{
"int": json.Number("3"),
"nested": map[string]interface{}{
"b": true,
},
"slice_in_slice": []interface{}{
[]interface{}{json.Number("1"), json.Number("2"), json.Number("3")},
},
},
}
if !p.IsExists(nil, "int") {
t.Fatal("'int' not found")
}
if v, err := p.GetInt(nil, "int"); err != nil || v != 3 {
t.Fatalf("'int'(%d) != 3, error: %v", v, err)
}
if !p.IsExists([]string{"nested"}, "b") {
t.Fatal("'nested.b' not found")
}
if v, err := p.GetBool([]string{"nested"}, "b"); err != nil || v != true {
t.Fatalf("'nested.b'(%z) != true, error: %v", v, err)
}
if v, err := p.GetInt([]string{"slice_in_slice", "0"}, "1"); err != nil || v != 2 {
t.Fatalf("'slice_in_slice[0][1]'(%d) != 2, error: %v", v, err)
}
}
开发者ID:sergei-svistunov,项目名称:gorpc,代码行数:28,代码来源:json_parameters_getter_test.go
示例7: TestIndicesBuild
func TestIndicesBuild(t *testing.T) {
tests := []struct {
note string
ref string
value interface{}
expected string
}{
{"single var", "data.a[i]", json.Number("2"), `[{"i": 1}]`},
{"two var", "data.d[x][y]", "baz", `[{"x": "e", "y": 1}]`},
{"partial ground", `data.c[i]["y"][j]`, nil, `[{"i": 0, "j": 0}]`},
{"multiple bindings", "data.g[x][y]", json.Number("0"), `[
{"x": "a", "y": 1},
{"x": "a", "y": 2},
{"x": "a", "y": 3},
{"x": "b", "y": 0},
{"x": "b", "y": 2},
{"x": "b", "y": 3},
{"x": "c", "y": 0},
{"x": "c", "y": 1},
{"x": "c", "y": 2}
]`},
}
for i, tc := range tests {
runIndexBuildTestCase(t, i+1, tc.note, tc.ref, tc.expected, tc.value)
}
}
开发者ID:tsandall,项目名称:opa,代码行数:29,代码来源:index_test.go
示例8: buildMonitorStruct
func buildMonitorStruct(d *schema.ResourceData) *datadog.Monitor {
var thresholds datadog.ThresholdCount
if r, ok := d.GetOk("thresholds.ok"); ok {
thresholds.Ok = json.Number(r.(string))
}
if r, ok := d.GetOk("thresholds.warning"); ok {
thresholds.Warning = json.Number(r.(string))
}
if r, ok := d.GetOk("thresholds.critical"); ok {
thresholds.Critical = json.Number(r.(string))
}
o := datadog.Options{
Thresholds: thresholds,
}
if attr, ok := d.GetOk("silenced"); ok {
s := make(map[string]int)
// TODO: this is not very defensive, test if we can fail on non int input
for k, v := range attr.(map[string]interface{}) {
s[k], _ = strconv.Atoi(v.(string))
}
o.Silenced = s
}
if attr, ok := d.GetOk("notify_data"); ok {
o.NotifyNoData = attr.(bool)
}
if attr, ok := d.GetOk("no_data_timeframe"); ok {
o.NoDataTimeframe = attr.(int)
}
if attr, ok := d.GetOk("renotify_interval"); ok {
o.RenotifyInterval = attr.(int)
}
if attr, ok := d.GetOk("notify_audit"); ok {
o.NotifyAudit = attr.(bool)
}
if attr, ok := d.GetOk("timeout_h"); ok {
o.TimeoutH = attr.(int)
}
if attr, ok := d.GetOk("escalation_message"); ok {
o.EscalationMessage = attr.(string)
}
if attr, ok := d.GetOk("escalation_message"); ok {
o.EscalationMessage = attr.(string)
}
if attr, ok := d.GetOk("include_tags"); ok {
o.IncludeTags = attr.(bool)
}
m := datadog.Monitor{
Type: d.Get("type").(string),
Query: d.Get("query").(string),
Name: d.Get("name").(string),
Message: d.Get("message").(string),
Options: o,
}
return &m
}
开发者ID:rjeczalik,项目名称:terraform-1,代码行数:60,代码来源:resource_datadog_monitor.go
示例9: TestEvalBodyCompileError
func TestEvalBodyCompileError(t *testing.T) {
ctx := context.Background()
store := newTestStore()
var buffer bytes.Buffer
repl := newRepl(store, &buffer)
repl.outputFormat = "json"
err := repl.OneShot(ctx, "x = 1, y > x")
if _, ok := err.(ast.Errors); !ok {
t.Fatalf("Expected error message in output but got`: %v", buffer.String())
}
buffer.Reset()
repl.OneShot(ctx, "x = 1, y = 2, y > x")
var result2 []interface{}
err = util.UnmarshalJSON(buffer.Bytes(), &result2)
if err != nil {
t.Errorf("Expected valid JSON output but got: %v", buffer.String())
return
}
expected2 := []interface{}{
map[string]interface{}{
"x": json.Number("1"),
"y": json.Number("2"),
},
}
if !reflect.DeepEqual(expected2, result2) {
t.Errorf(`Expected [{"x": 1, "y": 2}] but got: %v"`, result2)
return
}
}
开发者ID:tsandall,项目名称:opa,代码行数:29,代码来源:repl_test.go
示例10: TestSysGenerateRootAttempt_Cancel
func TestSysGenerateRootAttempt_Cancel(t *testing.T) {
core, _, token := vault.TestCoreUnsealed(t)
ln, addr := TestServer(t, core)
defer ln.Close()
TestServerAuth(t, addr, token)
otpBytes, err := vault.GenerateRandBytes(16)
if err != nil {
t.Fatal(err)
}
otp := base64.StdEncoding.EncodeToString(otpBytes)
resp := testHttpPut(t, token, addr+"/v1/sys/generate-root/attempt", map[string]interface{}{
"otp": otp,
})
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": "",
}
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)
}
resp = testHttpDelete(t, token, addr+"/v1/sys/generate-root/attempt")
testResponseStatus(t, resp, 204)
resp, err = http.Get(addr + "/v1/sys/generate-root/attempt")
if err != nil {
t.Fatalf("err: %s", err)
}
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,代码行数:59,代码来源:sys_generate_root_test.go
示例11: Less
// Less compares two statements for sort.Sort
// Implements a natural sort to keep array indexes in order
func (ss statements) Less(a, b int) bool {
diffStart := -1
for i := range ss[a] {
if len(ss[b]) < i+1 {
// b must be shorter than a, so it
// should come first
return false
}
// The tokens match, so just carry on
if ss[a][i] == ss[b][i] {
continue
}
// We've found a difference
diffStart = i
break
}
// If diffStart is still -1 then the only difference must be
// that string B is longer than A, so A should come first
if diffStart == -1 {
return true
}
// Get the tokens that differ
ta := ss[a][diffStart]
tb := ss[b][diffStart]
// An equals always comes first
if ta.typ == typEquals {
return true
}
if tb.typ == typEquals {
return false
}
// If both tokens are numeric keys do an integer comparison
if ta.typ == typNumericKey && tb.typ == typNumericKey {
ia, _ := strconv.Atoi(ta.text)
ib, _ := strconv.Atoi(tb.text)
return ia < ib
}
// If neither token is a number, just do a string comparison
if ta.typ != typNumber || tb.typ != typNumber {
return ta.text < tb.text
}
// We have two numbers to compare so turn them into json.Number
// for comparison
na, _ := json.Number(ta.text).Float64()
nb, _ := json.Number(tb.text).Float64()
return na < nb
}
开发者ID:tomnomnom,项目名称:gron,代码行数:60,代码来源:statements.go
示例12: AnalyseData
// AnalyseData decides if the monitor is statistically up or down and creates / resolves an incident
func (monitor *Monitor) AnalyseData() {
// look at the past few incidents
numDown := 0
for _, wasUp := range monitor.History {
if wasUp == false {
numDown++
}
}
t := (float32(numDown) / float32(len(monitor.History))) * 100
Logger.Printf("%s %.2f%% Down at %v. Threshold: %.2f%%\n", monitor.URL, t, time.Now().UnixNano()/int64(time.Second), monitor.Threshold)
if len(monitor.History) != 10 {
// not enough data
return
}
if t > monitor.Threshold && monitor.Incident == nil {
// is down, create an incident
Logger.Println("Creating incident...")
component_id := json.Number(strconv.Itoa(*monitor.ComponentID))
monitor.Incident = &Incident{
Name: monitor.Name + " - " + Config.SystemName,
Message: monitor.Name + " check failed",
ComponentID: &component_id,
}
if monitor.LastFailReason != nil {
monitor.Incident.Message += "\n\n - " + *monitor.LastFailReason
}
// set investigating status
monitor.Incident.SetInvestigating()
// create/update incident
monitor.Incident.Send()
monitor.Incident.UpdateComponent()
} else if t < monitor.Threshold && monitor.Incident != nil {
// was down, created an incident, its now ok, make it resolved.
Logger.Println("Updating incident to resolved...")
component_id := json.Number(strconv.Itoa(*monitor.ComponentID))
monitor.Incident = &Incident{
Name: monitor.Incident.Name,
Message: monitor.Name + " check succeeded",
ComponentID: &component_id,
}
monitor.Incident.SetFixed()
monitor.Incident.Send()
monitor.Incident.UpdateComponent()
monitor.Incident = nil
}
}
开发者ID:JC1738,项目名称:cachet-monitor,代码行数:57,代码来源:monitor.go
示例13: TestSysDisableAuth
func TestSysDisableAuth(t *testing.T) {
core, _, token := vault.TestCoreUnsealed(t)
ln, addr := TestServer(t, core)
defer ln.Close()
TestServerAuth(t, addr, token)
resp := testHttpPost(t, token, addr+"/v1/sys/auth/foo", map[string]interface{}{
"type": "noop",
"description": "foo",
})
testResponseStatus(t, resp, 204)
resp = testHttpDelete(t, token, addr+"/v1/sys/auth/foo")
testResponseStatus(t, resp, 204)
resp = testHttpGet(t, token, addr+"/v1/sys/auth")
var actual map[string]interface{}
expected := map[string]interface{}{
"lease_id": "",
"renewable": false,
"lease_duration": json.Number("0"),
"wrap_info": nil,
"warnings": nil,
"auth": nil,
"data": map[string]interface{}{
"token/": map[string]interface{}{
"config": map[string]interface{}{
"default_lease_ttl": json.Number("0"),
"max_lease_ttl": json.Number("0"),
},
"description": "token based credentials",
"type": "token",
},
},
"token/": map[string]interface{}{
"config": map[string]interface{}{
"default_lease_ttl": json.Number("0"),
"max_lease_ttl": json.Number("0"),
},
"description": "token based credentials",
"type": "token",
},
}
testResponseStatus(t, resp, 200)
testResponseBody(t, resp, &actual)
expected["request_id"] = actual["request_id"]
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: expected:%#v\nactual:%#v", expected, actual)
}
}
开发者ID:quixoten,项目名称:vault,代码行数:53,代码来源:sys_auth_test.go
示例14: TestSysMounts_headerAuth_Wrapped
// We use this test to verify header auth wrapping
func TestSysMounts_headerAuth_Wrapped(t *testing.T) {
core, _, token := vault.TestCoreUnsealed(t)
ln, addr := TestServer(t, core)
defer ln.Close()
req, err := http.NewRequest("GET", addr+"/v1/sys/mounts", nil)
if err != nil {
t.Fatalf("err: %s", err)
}
req.Header.Set(AuthHeaderName, token)
req.Header.Set(WrapTTLHeaderName, "60s")
client := cleanhttp.DefaultClient()
resp, err := client.Do(req)
if err != nil {
t.Fatalf("err: %s", err)
}
var actual map[string]interface{}
expected := map[string]interface{}{
"request_id": "",
"lease_id": "",
"renewable": false,
"lease_duration": json.Number("0"),
"data": nil,
"wrap_info": map[string]interface{}{
"ttl": json.Number("60"),
},
"warnings": nil,
"auth": nil,
}
testResponseStatus(t, resp, 200)
testResponseBody(t, resp, &actual)
actualToken, ok := actual["wrap_info"].(map[string]interface{})["token"]
if !ok || actualToken == "" {
t.Fatal("token missing in wrap info")
}
expected["wrap_info"].(map[string]interface{})["token"] = actualToken
actualCreationTime, ok := actual["wrap_info"].(map[string]interface{})["creation_time"]
if !ok || actualCreationTime == "" {
t.Fatal("creation_time missing in wrap info")
}
expected["wrap_info"].(map[string]interface{})["creation_time"] = actualCreationTime
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad:\nExpected: %#v\nActual: %#v\n%T %T", expected, actual, actual["warnings"], actual["data"])
}
}
开发者ID:quixoten,项目名称:vault,代码行数:52,代码来源:handler_test.go
示例15: TestDataStoreGet
func TestDataStoreGet(t *testing.T) {
data := loadSmallTestData()
var tests = []struct {
path string
expected interface{}
}{
{"/a/0", json.Number("1")},
{"/a/3", json.Number("4")},
{"/b/v1", "hello"},
{"/b/v2", "goodbye"},
{"/c/0/x/1", false},
{"/c/0/y/0", nil},
{"/c/0/y/1", json.Number("3.14159")},
{"/d/e/1", "baz"},
{"/d/e", []interface{}{"bar", "baz"}},
{"/c/0/z", map[string]interface{}{"p": true, "q": false}},
{"/d/100", notFoundError(MustParsePath("/d/100"), doesNotExistMsg)},
{"/dead/beef", notFoundError(MustParsePath("/dead/beef"), doesNotExistMsg)},
{"/a/str", notFoundError(MustParsePath("/a/str"), arrayIndexTypeMsg)},
{"/a/100", notFoundError(MustParsePath("/a/100"), outOfRangeMsg)},
{"/a/-1", notFoundError(MustParsePath("/a/-1"), outOfRangeMsg)},
{"/b/vdeadbeef", notFoundError(MustParsePath("/b/vdeadbeef"), doesNotExistMsg)},
}
ds := NewDataStoreFromJSONObject(data)
for idx, tc := range tests {
result, err := ds.Read(context.Background(), nil, MustParsePath(tc.path))
switch e := tc.expected.(type) {
case error:
if err == nil {
t.Errorf("Test case %d: expected error for %v but got %v", idx+1, tc.path, result)
} else if !reflect.DeepEqual(err, tc.expected) {
t.Errorf("Test case %d: unexpected error for %v: %v, expected: %v", idx+1, tc.path, err, e)
}
default:
if err != nil {
t.Errorf("Test case %d: expected success for %v but got %v", idx+1, tc.path, err)
}
if !reflect.DeepEqual(result, tc.expected) {
t.Errorf("Test case %d: expected %f but got %f", idx+1, tc.expected, result)
}
}
}
}
开发者ID:tsandall,项目名称:opa,代码行数:48,代码来源:datastore_test.go
示例16: TestClaimsMarshalUnmarshal
func TestClaimsMarshalUnmarshal(t *testing.T) {
tm := time.Now().Add(14 * time.Hour)
expr := json.Number(strconv.FormatInt(tm.Unix(), 10))
c := Claims{Issuer: "issuer", Expiration: expr}
buf, err := json.Marshal(&c)
if err != nil {
t.Fatalf("expected no error, got: %v", err)
}
c0 := Claims{}
err = json.Unmarshal(buf, &c0)
if err != nil {
t.Fatalf("expected no error, got: %v", err)
}
if expr != c0.Expiration {
t.Errorf("expr and c0.Expiration should equal -- %v / %v", expr, c0.Expiration)
}
if "issuer" != c0.Issuer {
t.Errorf("c0.Issuer should be 'issuer'")
}
c1 := Claims{}
err = json.Unmarshal([]byte(`{ "nbf": [] }`), &c1)
if err == nil {
t.Errorf("expected error, got nil")
}
}
开发者ID:knq,项目名称:jwt,代码行数:29,代码来源:type_test.go
示例17: getNumber
func (p *JsonParametersGetter) getNumber(path []string, name string) (json.Number, error) {
v, _ := p.get(path, name)
if n, ok := v.(json.Number); ok {
return n, nil
}
return json.Number(""), errors.New(`Wrong value of param "` + name + `". It must be number`)
}
开发者ID:wtertius,项目名称:gorpc,代码行数:7,代码来源:json_parameters_getter.go
示例18: TestJSONMarshaller
func TestJSONMarshaller(t *testing.T) {
var m Marshaller = NewJSON()
assert.Equal(t, m.Mime(), "application/json")
data := map[string]interface{}{
"key1": 1,
"key2": "str",
}
buf := bytes.NewBuffer(nil)
err := m.Marshal(buf)
assert.Equal(t, err, nil, "error: %s", err)
assert.Equal(t, buf.String(), "")
err = m.Marshal(buf, data, nil)
assert.Equal(t, err, nil, "error: %s", err)
assert.Equal(t, buf.String(), "{\"key1\":1,\"key2\":\"str\"}\n")
data = nil
err = m.Unmarshal(buf)
assert.Equal(t, err, nil, "error: %s", err)
err = m.Unmarshal(buf, &data)
assert.Equal(t, err, nil, "error: %s", err)
assert.Equal(t, data, map[string]interface{}{"key1": json.Number("1"), "key2": "str"})
data["f"] = TestJSONMarshaller
err = m.Marshal(buf, data)
assert.NotEqual(t, err, nil)
buf = bytes.NewBufferString("abc")
err = m.Unmarshal(buf, &data)
assert.NotEqual(t, err, nil)
}
开发者ID:jmptrader,项目名称:go-rest,代码行数:28,代码来源:mime_json_test.go
示例19: TestSysReadPolicy
func TestSysReadPolicy(t *testing.T) {
core, _, token := vault.TestCoreUnsealed(t)
ln, addr := TestServer(t, core)
defer ln.Close()
TestServerAuth(t, addr, token)
resp := testHttpGet(t, token, addr+"/v1/sys/policy/root")
var actual map[string]interface{}
expected := map[string]interface{}{
"lease_id": "",
"renewable": false,
"lease_duration": json.Number("0"),
"wrap_info": nil,
"warnings": nil,
"auth": nil,
"data": map[string]interface{}{
"name": "root",
"rules": "",
},
"name": "root",
"rules": "",
}
testResponseStatus(t, resp, 200)
testResponseBody(t, resp, &actual)
expected["request_id"] = actual["request_id"]
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: got\n%#v\nexpected\n%#v\n", actual, expected)
}
}
开发者ID:quixoten,项目名称:vault,代码行数:30,代码来源:sys_policy_test.go
示例20: GetPropertyNumber
// If the property has been set at least once, returns all values joined
// as a space separated string. Returns true if the propery has been set
// at least once.
func (s RawSection) GetPropertyNumber(property string) (json.Number, bool) {
vs, ok := s[property]
if !ok {
return "", false
}
return json.Number(strings.Join(vs, " ")), true
}
开发者ID:awreece,项目名称:goini,代码行数:10,代码来源:goini.go
注:本文中的encoding/json.Number函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论