本文整理汇总了Golang中encoding/json.RawMessage函数的典型用法代码### 示例。如果您正苦于以下问题:Golang RawMessage函数的具体用法?Golang RawMessage怎么用?Golang RawMessage使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。
在下文中一共展示了RawMessage函数的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。
示例1: TestParseCommandArgs
func TestParseCommandArgs(t *testing.T) {
if cmd, err := parseCommandArgs(nil); err == nil {
validateCommandParsed(t, "command", cmd, nil)
} else {
t.Errorf("Unexpected parse error: %s", err.Error())
}
expected := []string{"/test.sh", "arg1"}
json1 := json.RawMessage(`"/test.sh arg1"`)
if cmd, err := parseCommandArgs(json1); err == nil {
validateCommandParsed(t, "json1", cmd, expected)
} else {
t.Errorf("Unexpected parse error json1: %s", err.Error())
}
json2 := json.RawMessage(`["/test.sh","arg1"]`)
if cmd, err := parseCommandArgs(json2); err == nil {
validateCommandParsed(t, "json2", cmd, expected)
} else {
t.Errorf("Unexpected parse error json2: %s", err.Error())
}
json3 := json.RawMessage(`{ "a": true }`)
if _, err := parseCommandArgs(json3); err == nil {
t.Errorf("Expected parse error for json3")
}
}
开发者ID:zofuthan,项目名称:containerbuddy,代码行数:28,代码来源:config_test.go
示例2: TestUnmarshalSingleErrs
func TestUnmarshalSingleErrs(t *testing.T) {
err := unmarshalSingle(json.RawMessage{}, "", "foo")
assert.Error(t, err)
var foo string
err = unmarshalSingle(json.RawMessage([]byte(`{"bar":"baz"}`)), "foo", &foo)
assert.Error(t, err)
var outInt int
var outStr string
var outBool bool
var outSlice []struct{}
err = unmarshalSingle(json.RawMessage([]byte(`{"foo": "bar"}`)), "foo", &outInt)
assert.Error(t, err)
assert.Empty(t, outInt)
err = unmarshalSingle(json.RawMessage([]byte(`{"foo": 1}`)), "foo", &outStr)
assert.Error(t, err)
assert.Empty(t, outStr)
err = unmarshalSingle(json.RawMessage([]byte(`{"foo": "bar"}`)), "foo", &outBool)
assert.Error(t, err)
assert.Empty(t, outBool)
err = unmarshalSingle(json.RawMessage([]byte(`{"foo": "bar"}`)), "foo", &outSlice)
assert.Error(t, err)
assert.Empty(t, outSlice)
}
开发者ID:alexsacr,项目名称:linode,代码行数:26,代码来源:marshal_test.go
示例3: TestParseInterfaces
func TestParseInterfaces(t *testing.T) {
if interfaces, err := parseInterfaces(nil); err != nil {
t.Errorf("Unexpected parse error: %s", err.Error())
} else if len(interfaces) > 0 {
t.Errorf("Expected no interfaces, but got %s", interfaces)
}
json1 := json.RawMessage(`"eth0"`)
expected1 := []string{"eth0"}
if interfaces, err := parseInterfaces(json1); err != nil {
t.Errorf("Unexpected parse error: %s", err.Error())
} else if !reflect.DeepEqual(interfaces, expected1) {
t.Errorf("Expected %s, got: %s", expected1, interfaces)
}
json2 := json.RawMessage(`["ethwe","eth0"]`)
expected2 := []string{"ethwe", "eth0"}
if interfaces, err := parseInterfaces(json2); err != nil {
t.Errorf("Unexpected parse error: %s", err.Error())
} else if !reflect.DeepEqual(interfaces, expected2) {
t.Errorf("Expected %s, got: %s", expected2, interfaces)
}
json3 := json.RawMessage(`{ "a": true }`)
if _, err := parseInterfaces(json3); err == nil {
t.Errorf("Expected parse error for json3")
}
}
开发者ID:zofuthan,项目名称:containerbuddy,代码行数:28,代码来源:ips_test.go
示例4: Encode
// 转换到下层对象
func (this ContentModel) Encode(webqq *WebQQ) (v Content) {
matches := contentPatten.FindAllStringSubmatch(this.Message, -1)
if matches == nil { // 没有图片
v = make([]json.RawMessage, 1, 2)
b, err := json.Marshal(this.Message)
util.Try(err)
v[0] = json.RawMessage(b)
} else {
v = make([]json.RawMessage, 0, len(matches)*2+2) // 123[]1[]2[]3 = 3*2+1 = 7
for _, v1 := range matches {
switch v1[1] {
case "offpic":
b, err := json.Marshal([]interface{}{v1[1], Offpic{Success: 1, FilePath: v1[2]}})
if err == nil {
v = append(v, b)
}
case "cface":
b, err := json.Marshal([]interface{}{v1[1], Cface{Key: webqq.cface_key, Name: v1[2], Server: DefaultServer}})
if err == nil {
v = append(v, json.RawMessage(b))
}
case "face":
b, err := json.Marshal([]interface{}{v1[1], util.ToInt(v1[2])})
if err == nil {
v = append(v, json.RawMessage(b))
}
}
}
}
b, err := json.Marshal([]interface{}{"font", this.Font})
util.Try(err)
v = append(v, json.RawMessage(b))
return v
}
开发者ID:pa001024,项目名称:reflex,代码行数:36,代码来源:WebQQ.content.go
示例5: Authority
func (gs *GrantManager) Authority(
ctx scope.Context, manager Account, managerKey *security.ManagedKey) (
subjectKeyPair *security.ManagedKeyPair, public, private *json.RawMessage, err error) {
managerKeyPair, err := manager.Unlock(managerKey)
if err != nil {
return nil, nil, nil, err
}
subjectKeyPair, err = gs.unlockSubjectKeyPair(ctx, manager, managerKeyPair)
if err != nil {
return nil, nil, nil, err
}
sourceCapability, err := gs.AccountCapability(ctx, manager)
if err != nil {
return nil, nil, nil, err
}
public = new(json.RawMessage)
if publicBytes := sourceCapability.PublicPayload(); publicBytes != nil {
*public = json.RawMessage(publicBytes)
}
private = new(json.RawMessage)
privateBytes, err := sourceCapability.DecryptPayload(gs.SubjectKeyPair, managerKeyPair)
if err != nil {
return nil, nil, nil, err
}
*private = json.RawMessage(privateBytes)
return
}
开发者ID:logan,项目名称:heim,代码行数:33,代码来源:grants.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng