github.com/smugmug/godynamo@v0.0.0-20151122084750-7913028f6623/endpoint/endpoint.go (about) 1 // A collection of types and methods common to all of the endpoint/* packages. 2 // Define types for the core datatype listed here: 3 // http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Types.html 4 // Some of the data types at that url are not defined here, rather they may be 5 // defined with special limits for the various endpoints - see the packages 6 // for these endpoints for details. 7 package endpoint 8 9 import ( 10 "github.com/smugmug/godynamo/conf" 11 "github.com/smugmug/godynamo/types/attributedefinition" 12 "github.com/smugmug/godynamo/types/attributesresponse" 13 "github.com/smugmug/godynamo/types/attributestoget" 14 "github.com/smugmug/godynamo/types/attributevalue" 15 "github.com/smugmug/godynamo/types/aws_strings" 16 "github.com/smugmug/godynamo/types/capacity" 17 "github.com/smugmug/godynamo/types/expected" 18 "github.com/smugmug/godynamo/types/globalsecondaryindex" 19 "github.com/smugmug/godynamo/types/item" 20 "github.com/smugmug/godynamo/types/itemcollectionmetrics" 21 "github.com/smugmug/godynamo/types/keydefinition" 22 "github.com/smugmug/godynamo/types/localsecondaryindex" 23 "github.com/smugmug/godynamo/types/nullable" 24 "github.com/smugmug/godynamo/types/provisionedthroughput" 25 "github.com/smugmug/godynamo/types/returnvalues" 26 "net/http" 27 ) 28 29 // re-exported consts for backwards compatibility 30 const ( 31 HASH = aws_strings.HASH 32 RANGE = aws_strings.RANGE 33 HASH_KEY_ELEMENT = aws_strings.HASH_KEY_ELEMENT 34 RANGE_KEY_ELEMENT = aws_strings.RANGE_KEY_ELEMENT 35 S = aws_strings.S 36 N = aws_strings.N 37 B = aws_strings.B 38 BOOL = aws_strings.BOOL 39 NULL = aws_strings.NULL 40 L = aws_strings.L 41 M = aws_strings.M 42 SS = aws_strings.SS 43 NS = aws_strings.NS 44 BS = aws_strings.BS 45 RETVAL_NONE = aws_strings.RETVAL_NONE 46 RETVAL_ALL_OLD = aws_strings.RETVAL_ALL_OLD 47 RETVAL_ALL_NEW = aws_strings.RETVAL_ALL_NEW 48 RETVAL_UPDATED_OLD = aws_strings.RETVAL_UPDATED_OLD 49 RETVAL_UPDATED_NEW = aws_strings.RETVAL_UPDATED_NEW 50 ALL = aws_strings.ALL 51 SIZE = aws_strings.SIZE 52 TOTAL = aws_strings.TOTAL 53 KEYS_ONLY = aws_strings.KEYS_ONLY 54 INCLUDE = aws_strings.INCLUDE 55 SELECT_ALL = aws_strings.SELECT_ALL 56 SELECT_PROJECTED = aws_strings.SELECT_PROJECTED 57 SELECT_SPECIFIC = aws_strings.SELECT_SPECIFIC 58 SELECT_COUNT = aws_strings.SELECT_COUNT 59 OP_EQ = aws_strings.OP_EQ 60 OP_NE = aws_strings.OP_NE 61 OP_LE = aws_strings.OP_LE 62 OP_LT = aws_strings.OP_LT 63 OP_GE = aws_strings.OP_GE 64 OP_GT = aws_strings.OP_GT 65 OP_NULL = aws_strings.OP_NULL 66 OP_NOT_NULL = aws_strings.OP_NOT_NULL 67 OP_CONTAINS = aws_strings.OP_CONTAINS 68 OP_NOT_CONTAINS = aws_strings.OP_NOT_CONTAINS 69 OP_BEGINS_WITH = aws_strings.OP_BEGINS_WITH 70 OP_IN = aws_strings.OP_IN 71 OP_BETWEEN = aws_strings.OP_BETWEEN 72 ) 73 74 // re-exported types for backwards compatibility 75 type AttributeDefinition attributedefinition.AttributeDefinition 76 77 type AttributeDefinitions attributedefinition.AttributeDefinitions 78 79 type AttributeValue attributevalue.AttributeValue 80 81 type AttributesResponse attributesresponse.AttributesResponse 82 83 type AttributesToGet attributestoget.AttributesToGet 84 85 type ConsumedCapacityUnit capacity.ConsumedCapacityUnit 86 87 type ConsumedCapacity capacity.ConsumedCapacity 88 89 type Item item.Item 90 91 type ReturnValues returnvalues.ReturnValues 92 93 type NullableString nullable.NullableString 94 95 type NullableUInt64 nullable.NullableUInt64 96 97 type ReturnConsumedCapacity capacity.ReturnConsumedCapacity 98 99 type ReturnItemCollectionMetrics itemcollectionmetrics.ItemCollectionMetrics 100 101 type ItemCollectionMetrics itemcollectionmetrics.ItemCollectionMetrics 102 103 type Constraints expected.Constraints 104 105 type Expected expected.Expected 106 107 type ProvionedThroughPut provisionedthroughput.ProvisionedThroughput 108 109 type ProvionedThroughPutDesc provisionedthroughput.ProvisionedThroughputDesc 110 111 type KeyDefinition keydefinition.KeyDefinition 112 113 type KeySchema keydefinition.KeySchema 114 115 type LocalSecondaryIndex localsecondaryindex.LocalSecondaryIndex 116 117 type LocalSecondaryIndexes localsecondaryindex.LocalSecondaryIndexes 118 119 type LocalSecondaryIndexDesc localsecondaryindex.LocalSecondaryIndexDesc 120 121 type GlobalSecondaryIndex globalsecondaryindex.GlobalSecondaryIndex 122 123 type GlobalSecondaryIndexes globalsecondaryindex.GlobalSecondaryIndexes 124 125 type GlobalSecondaryIndexDesc globalsecondaryindex.GlobalSecondaryIndexDesc 126 127 // --------------------------------------------------------------------- 128 // GoDynamo-specific types 129 130 // Endpoint is a core interface for defining all endpoints. 131 // Packages implementing the Endpoint interface should return the 132 // string output from the authorized request (or ""), the http code, 133 // and an error (or nil). This is the fundamental endpoint interface of 134 // GoDynamo. 135 type Endpoint interface { 136 // uses a parameterized conf 137 EndpointReqWithConf(c *conf.AWS_Conf) ([]byte, int, error) 138 139 // applies the global conf.Vals to EndpointReq(c *AWS_Conf) 140 EndpointReq() ([]byte, int, error) 141 } 142 143 // Endpoint_Response describes the response from Dynamo for a given request. 144 type Endpoint_Response struct { 145 Body []byte 146 Code int 147 Err error 148 } 149 150 // ReqErr is a convenience function to see if the request was bad. 151 func ReqErr(code int) bool { 152 return code >= http.StatusBadRequest && 153 code < http.StatusInternalServerError 154 } 155 156 // ServerErr is a convenience function to see if the remote server had an 157 // internal error. 158 func ServerErr(code int) bool { 159 return code >= http.StatusInternalServerError 160 } 161 162 // HttpErr is a convenience function to see determine if the code is an error code. 163 func HttpErr(code int) bool { 164 return ReqErr(code) || ServerErr(code) 165 }