src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

value.go (2740B)


      1 package query
      2 
      3 import (
      4 	"math/big"
      5 	"net/url"
      6 
      7 	"github.com/aws/smithy-go/encoding/httpbinding"
      8 )
      9 
     10 // Value represents a Query Value type.
     11 type Value struct {
     12 	// The query values to add the value to.
     13 	values url.Values
     14 	// The value's key, which will form the prefix for complex types.
     15 	key string
     16 	// Whether the value should be flattened or not if it's a flattenable type.
     17 	flat       bool
     18 	queryValue httpbinding.QueryValue
     19 }
     20 
     21 func newValue(values url.Values, key string, flat bool) Value {
     22 	return Value{
     23 		values:     values,
     24 		key:        key,
     25 		flat:       flat,
     26 		queryValue: httpbinding.NewQueryValue(values, key, false),
     27 	}
     28 }
     29 
     30 func newAppendValue(values url.Values, key string, flat bool) Value {
     31 	return Value{
     32 		values:     values,
     33 		key:        key,
     34 		flat:       flat,
     35 		queryValue: httpbinding.NewQueryValue(values, key, true),
     36 	}
     37 }
     38 
     39 func newBaseValue(values url.Values) Value {
     40 	return Value{
     41 		values:     values,
     42 		queryValue: httpbinding.NewQueryValue(nil, "", false),
     43 	}
     44 }
     45 
     46 // Array returns a new Array encoder.
     47 func (qv Value) Array(locationName string) *Array {
     48 	return newArray(qv.values, qv.key, qv.flat, locationName)
     49 }
     50 
     51 // Object returns a new Object encoder.
     52 func (qv Value) Object() *Object {
     53 	return newObject(qv.values, qv.key)
     54 }
     55 
     56 // Map returns a new Map encoder.
     57 func (qv Value) Map(keyLocationName string, valueLocationName string) *Map {
     58 	return newMap(qv.values, qv.key, qv.flat, keyLocationName, valueLocationName)
     59 }
     60 
     61 // Base64EncodeBytes encodes v as a base64 query string value.
     62 // This is intended to enable compatibility with the JSON encoder.
     63 func (qv Value) Base64EncodeBytes(v []byte) {
     64 	qv.queryValue.Blob(v)
     65 }
     66 
     67 // Boolean encodes v as a query string value
     68 func (qv Value) Boolean(v bool) {
     69 	qv.queryValue.Boolean(v)
     70 }
     71 
     72 // String encodes v as a query string value
     73 func (qv Value) String(v string) {
     74 	qv.queryValue.String(v)
     75 }
     76 
     77 // Byte encodes v as a query string value
     78 func (qv Value) Byte(v int8) {
     79 	qv.queryValue.Byte(v)
     80 }
     81 
     82 // Short encodes v as a query string value
     83 func (qv Value) Short(v int16) {
     84 	qv.queryValue.Short(v)
     85 }
     86 
     87 // Integer encodes v as a query string value
     88 func (qv Value) Integer(v int32) {
     89 	qv.queryValue.Integer(v)
     90 }
     91 
     92 // Long encodes v as a query string value
     93 func (qv Value) Long(v int64) {
     94 	qv.queryValue.Long(v)
     95 }
     96 
     97 // Float encodes v as a query string value
     98 func (qv Value) Float(v float32) {
     99 	qv.queryValue.Float(v)
    100 }
    101 
    102 // Double encodes v as a query string value
    103 func (qv Value) Double(v float64) {
    104 	qv.queryValue.Double(v)
    105 }
    106 
    107 // BigInteger encodes v as a query string value
    108 func (qv Value) BigInteger(v *big.Int) {
    109 	qv.queryValue.BigInteger(v)
    110 }
    111 
    112 // BigDecimal encodes v as a query string value
    113 func (qv Value) BigDecimal(v *big.Float) {
    114 	qv.queryValue.BigDecimal(v)
    115 }