本文整理汇总了Golang中github.com/couchbaselabs/query/value.Value.MarshalJSON方法的典型用法代码示例。如果您正苦于以下问题:Golang Value.MarshalJSON方法的具体用法?Golang Value.MarshalJSON怎么用?Golang Value.MarshalJSON使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/couchbaselabs/query/value.Value
的用法示例。
在下文中一共展示了Value.MarshalJSON方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Apply
/*
This method takes in an operand value and context and returns a value.
If the type of operand is missing then return it. Call MarshalJSON
to get the bytes, and then use Go's encoding/base64 package to
encode the bytes to string. Create a newValue using the string and
return it.
*/
func (this *Base64) Apply(context Context, operand value.Value) (value.Value, error) {
if operand.Type() == value.MISSING {
return operand, nil
}
bytes, _ := operand.MarshalJSON() // Ignore errors from BINARY values
str := base64.StdEncoding.EncodeToString(bytes)
return value.NewValue(str), nil
}
示例2: GetPrepared
func (this *cacheType) GetPrepared(value value.Value) (*Prepared, error) {
json_bytes, err := value.MarshalJSON()
if err != nil {
return nil, err
}
key := makeKey(json_bytes)
this.RLock()
prepared := this.prepareds[key]
this.RUnlock()
return prepared, nil
}
示例3: Apply
/*
This method returns a number value that represents the length of the bytes slice
returned by the MarshalJSON method cast to a float64 value.
*/
func (this *EncodedSize) Apply(context Context, arg value.Value) (value.Value, error) {
bytes, _ := arg.MarshalJSON()
return value.NewValue(float64(len(bytes))), nil
}