github.com/smugmug/godynamo@v0.0.0-20151122084750-7913028f6623/endpoints/update_table/update_table.go (about) 1 // Support for the DynamoDB UpdateTable endpoint. 2 // 3 // example use: 4 // 5 // tests/update_table-livestest.go 6 // 7 package update_table 8 9 import ( 10 "encoding/json" 11 "errors" 12 "github.com/smugmug/godynamo/authreq" 13 "github.com/smugmug/godynamo/aws_const" 14 "github.com/smugmug/godynamo/conf" 15 create_table "github.com/smugmug/godynamo/endpoints/create_table" 16 "github.com/smugmug/godynamo/types/globalsecondaryindex" 17 "github.com/smugmug/godynamo/types/provisionedthroughput" 18 ) 19 20 const ( 21 ENDPOINT_NAME = "UpdateTable" 22 UPDATETABLE_ENDPOINT = aws_const.ENDPOINT_PREFIX + ENDPOINT_NAME 23 ) 24 25 type UpdateTable struct { 26 GlobalSecondaryIndexUpdates *globalsecondaryindex.GlobalSecondaryIndexUpdates `json:",omitempty"` 27 TableName string 28 ProvisionedThroughput *provisionedthroughput.ProvisionedThroughput `json:",omitempty"` 29 } 30 31 func NewUpdateTable() *UpdateTable { 32 update_table := new(UpdateTable) 33 update_table.GlobalSecondaryIndexUpdates = 34 globalsecondaryindex.NewGlobalSecondaryIndexUpdates() 35 update_table.ProvisionedThroughput = 36 provisionedthroughput.NewProvisionedThroughput() 37 return update_table 38 } 39 40 // Update is an alias for backwards compatibility 41 type Update UpdateTable 42 43 func NewUpdate() *Update { 44 update_table := NewUpdateTable() 45 update := Update(*update_table) 46 return &update 47 } 48 49 type Request UpdateTable 50 51 type Response create_table.Response 52 53 func NewResponse() *Response { 54 cr := create_table.NewResponse() 55 r := Response(*cr) 56 return &r 57 } 58 59 // These implementations of EndpointReq use a parameterized conf. 60 61 func (update_table *UpdateTable) EndpointReqWithConf(c *conf.AWS_Conf) ([]byte, int, error) { 62 if update_table == nil { 63 return nil, 0, errors.New("update_table.(UpdateTable)EndpointReqWithConf: receiver is nil") 64 } 65 if !conf.IsValid(c) { 66 return nil, 0, errors.New("update_table.EndpointReqWithConf: c is not valid") 67 } 68 // returns resp_body,code,err 69 reqJSON, json_err := json.Marshal(update_table) 70 if json_err != nil { 71 return nil, 0, json_err 72 } 73 return authreq.RetryReqJSON_V4WithConf(reqJSON, UPDATETABLE_ENDPOINT, c) 74 } 75 76 func (update *Update) EndpointReqWithConf(c *conf.AWS_Conf) ([]byte, int, error) { 77 if update == nil { 78 return nil, 0, errors.New("update_table.(Update)EndpointReqWithConf: receiver is nil") 79 } 80 update_table := UpdateTable(*update) 81 return update_table.EndpointReqWithConf(c) 82 } 83 84 func (req *Request) EndpointReqWithConf(c *conf.AWS_Conf) ([]byte, int, error) { 85 if req == nil { 86 return nil, 0, errors.New("update_table.(Request)EndpointReqWithConf: receiver is nil") 87 } 88 update_table := UpdateTable(*req) 89 return update_table.EndpointReqWithConf(c) 90 } 91 92 // These implementations of EndpointReq use the global conf. 93 94 func (update_table *UpdateTable) EndpointReq() ([]byte, int, error) { 95 if update_table == nil { 96 return nil, 0, errors.New("update_table.(UpdateTable)EndpointReq: receiver is nil") 97 } 98 return update_table.EndpointReqWithConf(&conf.Vals) 99 } 100 101 func (update *Update) EndpointReq() ([]byte, int, error) { 102 if update == nil { 103 return nil, 0, errors.New("update_table.(Update)EndpointReq: receiver is nil") 104 } 105 update_table := UpdateTable(*update) 106 return update_table.EndpointReqWithConf(&conf.Vals) 107 } 108 109 func (req *Request) EndpointReq() ([]byte, int, error) { 110 if req == nil { 111 return nil, 0, errors.New("update_table.(Request)EndpointReq: receiver is nil") 112 } 113 update_table := UpdateTable(*req) 114 return update_table.EndpointReqWithConf(&conf.Vals) 115 }