本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/dynamodb.AttributeValue.N方法的典型用法代码示例。如果您正苦于以下问题:Golang AttributeValue.N方法的具体用法?Golang AttributeValue.N怎么用?Golang AttributeValue.N使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/aws/aws-sdk-go/service/dynamodb.AttributeValue
的用法示例。
在下文中一共展示了AttributeValue.N方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: encodeScalar
func (e *Encoder) encodeScalar(av *dynamodb.AttributeValue, v reflect.Value, fieldTag tag) error {
switch typed := v.Interface().(type) {
case bool:
av.BOOL = new(bool)
*av.BOOL = typed
case string:
if err := e.encodeString(av, v); err != nil {
return err
}
case Number:
s := string(typed)
if fieldTag.AsString {
av.S = &s
} else {
av.N = &s
}
default:
// Fallback to encoding numbers, will return invalid type if not supported
if err := e.encodeNumber(av, v); err != nil {
return err
}
if fieldTag.AsString && av.NULL == nil && av.N != nil {
av.S = av.N
av.N = nil
}
}
return nil
}
示例2: encodeScalar
func (e *Encoder) encodeScalar(av *dynamodb.AttributeValue, v reflect.Value, fieldTag tag) error {
if v.Type() == numberType {
s := v.String()
if fieldTag.AsString {
av.S = &s
} else {
av.N = &s
}
return nil
}
switch v.Kind() {
case reflect.Bool:
av.BOOL = new(bool)
*av.BOOL = v.Bool()
case reflect.String:
if err := e.encodeString(av, v); err != nil {
return err
}
default:
// Fallback to encoding numbers, will return invalid type if not supported
if err := e.encodeNumber(av, v); err != nil {
return err
}
if fieldTag.AsString && av.NULL == nil && av.N != nil {
av.S = av.N
av.N = nil
}
}
return nil
}
示例3: encodeNumber
func (e *Encoder) encodeNumber(av *dynamodb.AttributeValue, v reflect.Value) error {
if used, err := tryMarshaler(av, v); used {
return err
}
var out string
switch v.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
out = encodeInt(v.Int())
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
out = encodeUint(v.Uint())
case reflect.Float32, reflect.Float64:
out = encodeFloat(v.Float())
default:
return &unsupportedMarshalTypeError{Type: v.Type()}
}
av.N = &out
return nil
}
示例4: encodeNumber
func (e *Encoder) encodeNumber(av *dynamodb.AttributeValue, v reflect.Value) error {
if used, err := tryMarshaler(av, v); used {
return err
}
var out string
switch typed := v.Interface().(type) {
case int:
out = encodeInt(int64(typed))
case int8:
out = encodeInt(int64(typed))
case int16:
out = encodeInt(int64(typed))
case int32:
out = encodeInt(int64(typed))
case int64:
out = encodeInt(typed)
case uint:
out = encodeUint(uint64(typed))
case uint8:
out = encodeUint(uint64(typed))
case uint16:
out = encodeUint(uint64(typed))
case uint32:
out = encodeUint(uint64(typed))
case uint64:
out = encodeUint(typed)
case float32:
out = encodeFloat(float64(typed))
case float64:
out = encodeFloat(typed)
default:
return &unsupportedMarshalTypeError{Type: v.Type()}
}
av.N = &out
return nil
}