code.dwrz.net

Go monorepo.
Log | Files | Refs

value.go (2528B)


      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 newBaseValue(values url.Values) Value {
     31 	return Value{
     32 		values:     values,
     33 		queryValue: httpbinding.NewQueryValue(nil, "", false),
     34 	}
     35 }
     36 
     37 // Array returns a new Array encoder.
     38 func (qv Value) Array(locationName string) *Array {
     39 	return newArray(qv.values, qv.key, qv.flat, locationName)
     40 }
     41 
     42 // Object returns a new Object encoder.
     43 func (qv Value) Object() *Object {
     44 	return newObject(qv.values, qv.key)
     45 }
     46 
     47 // Map returns a new Map encoder.
     48 func (qv Value) Map(keyLocationName string, valueLocationName string) *Map {
     49 	return newMap(qv.values, qv.key, qv.flat, keyLocationName, valueLocationName)
     50 }
     51 
     52 // Base64EncodeBytes encodes v as a base64 query string value.
     53 // This is intended to enable compatibility with the JSON encoder.
     54 func (qv Value) Base64EncodeBytes(v []byte) {
     55 	qv.queryValue.Blob(v)
     56 }
     57 
     58 // Boolean encodes v as a query string value
     59 func (qv Value) Boolean(v bool) {
     60 	qv.queryValue.Boolean(v)
     61 }
     62 
     63 // String encodes v as a query string value
     64 func (qv Value) String(v string) {
     65 	qv.queryValue.String(v)
     66 }
     67 
     68 // Byte encodes v as a query string value
     69 func (qv Value) Byte(v int8) {
     70 	qv.queryValue.Byte(v)
     71 }
     72 
     73 // Short encodes v as a query string value
     74 func (qv Value) Short(v int16) {
     75 	qv.queryValue.Short(v)
     76 }
     77 
     78 // Integer encodes v as a query string value
     79 func (qv Value) Integer(v int32) {
     80 	qv.queryValue.Integer(v)
     81 }
     82 
     83 // Long encodes v as a query string value
     84 func (qv Value) Long(v int64) {
     85 	qv.queryValue.Long(v)
     86 }
     87 
     88 // Float encodes v as a query string value
     89 func (qv Value) Float(v float32) {
     90 	qv.queryValue.Float(v)
     91 }
     92 
     93 // Double encodes v as a query string value
     94 func (qv Value) Double(v float64) {
     95 	qv.queryValue.Double(v)
     96 }
     97 
     98 // BigInteger encodes v as a query string value
     99 func (qv Value) BigInteger(v *big.Int) {
    100 	qv.queryValue.BigInteger(v)
    101 }
    102 
    103 // BigDecimal encodes v as a query string value
    104 func (qv Value) BigDecimal(v *big.Float) {
    105 	qv.queryValue.BigDecimal(v)
    106 }