本文整理匯總了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
}