本文整理汇总了Golang中github.com/cockroachdb/cockroach/proto.Value.SetFloat方法的典型用法代码示例。如果您正苦于以下问题:Golang Value.SetFloat方法的具体用法?Golang Value.SetFloat怎么用?Golang Value.SetFloat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/proto.Value
的用法示例。
在下文中一共展示了Value.SetFloat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: marshalValue
// marshalValue returns a proto.Value initialized from the source
// reflect.Value, returning an error if the types are not compatible.
func marshalValue(v interface{}) (proto.Value, error) {
var r proto.Value
if v == nil {
return r, nil
}
switch t := v.(type) {
case nil:
return r, nil
case string:
r.SetBytes([]byte(t))
return r, nil
case []byte:
r.SetBytes(t)
return r, nil
case proto.Key:
r.SetBytes([]byte(t))
return r, nil
case time.Time:
err := r.SetTime(t)
return r, err
case gogoproto.Message:
err := r.SetProto(t)
return r, err
}
switch v := reflect.ValueOf(v); v.Kind() {
case reflect.Bool:
i := int64(0)
if v.Bool() {
i = 1
}
r.SetInt(i)
return r, nil
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
r.SetInt(v.Int())
return r, nil
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
r.SetInt(int64(v.Uint()))
return r, nil
case reflect.Float32, reflect.Float64:
r.SetFloat(v.Float())
return r, nil
case reflect.String:
r.SetBytes([]byte(v.String()))
return r, nil
}
return r, fmt.Errorf("unable to marshal value: %s", v)
}
示例2: marshalValue
// marshalValue returns a proto.Value initialized from the source
// interface{}, returning an error if the types are not compatible.
func marshalValue(v interface{}) (proto.Value, error) {
var r proto.Value
// Handle a few common types via a type switch.
switch t := v.(type) {
case nil:
return r, nil
case bool:
i := int64(0)
if t {
i = 1
}
r.SetInt(i)
return r, nil
case string:
r.SetBytes([]byte(t))
return r, nil
case []byte:
r.SetBytes(t)
return r, nil
case proto.Key:
r.SetBytes([]byte(t))
return r, nil
case time.Time:
r.SetTime(t)
return r, nil
case gogoproto.Message:
err := r.SetProto(t)
return r, err
}
// Handle all of the Go primitive types besides struct and pointers. This
// switch also handles types based on a primitive type (e.g. "type MyInt
// int").
switch v := reflect.ValueOf(v); v.Kind() {
case reflect.Bool:
i := int64(0)
if v.Bool() {
i = 1
}
r.SetInt(i)
return r, nil
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
r.SetInt(v.Int())
return r, nil
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
r.SetInt(int64(v.Uint()))
return r, nil
case reflect.Float32, reflect.Float64:
r.SetFloat(v.Float())
return r, nil
case reflect.String:
r.SetBytes([]byte(v.String()))
return r, nil
}
return r, fmt.Errorf("unable to marshal value: %s", v)
}