github.com/smugmug/godynamo@v0.0.0-20151122084750-7913028f6623/endpoints/delete_item/delete_item.go (about)

     1  // Support for the DynamoDB DeleteItem endpoint.
     2  //
     3  // example use:
     4  //
     5  // tests/delete_item-livestest.go
     6  //
     7  package delete_item
     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  	"github.com/smugmug/godynamo/types/attributesresponse"
    16  	"github.com/smugmug/godynamo/types/attributevalue"
    17  	"github.com/smugmug/godynamo/types/aws_strings"
    18  	"github.com/smugmug/godynamo/types/expected"
    19  	"github.com/smugmug/godynamo/types/expressionattributenames"
    20  	"github.com/smugmug/godynamo/types/item"
    21  )
    22  
    23  const (
    24  	ENDPOINT_NAME       = "DeleteItem"
    25  	DELETEITEM_ENDPOINT = aws_const.ENDPOINT_PREFIX + ENDPOINT_NAME
    26  	// the permitted ReturnValues flags for this op
    27  	RETVAL_ALL_OLD = aws_strings.RETVAL_ALL_OLD
    28  	RETVAL_NONE    = aws_strings.RETVAL_NONE
    29  )
    30  
    31  type DeleteItem struct {
    32  	ConditionExpression         string                                            `json:",omitempty"`
    33  	ConditionalOperator         string                                            `json:",omitempty"`
    34  	Expected                    expected.Expected                                 `json:",omitempty"`
    35  	ExpressionAttributeNames    expressionattributenames.ExpressionAttributeNames `json:",omitempty"`
    36  	ExpressionAttributeValues   attributevalue.AttributeValueMap                  `json:",omitempty"`
    37  	Key                         item.Key
    38  	ReturnConsumedCapacity      string `json:",omitempty"`
    39  	ReturnItemCollectionMetrics string `json:",omitempty"`
    40  	ReturnValues                string `json:",omitempty"`
    41  	TableName                   string
    42  }
    43  
    44  func NewDeleteItem() *DeleteItem {
    45  	u := new(DeleteItem)
    46  	u.Expected = expected.NewExpected()
    47  	u.ExpressionAttributeNames = expressionattributenames.NewExpressionAttributeNames()
    48  	u.ExpressionAttributeValues = attributevalue.NewAttributeValueMap()
    49  	u.Key = item.NewKey()
    50  	return u
    51  }
    52  
    53  // Delete is an alias for backwards compatibility
    54  type Delete DeleteItem
    55  
    56  func NewDelete() *Delete {
    57  	delete_item := NewDeleteItem()
    58  	delete := Delete(*delete_item)
    59  	return &delete
    60  }
    61  
    62  type Request DeleteItem
    63  
    64  type Response attributesresponse.AttributesResponse
    65  
    66  func NewResponse() *Response {
    67  	a := attributesresponse.NewAttributesResponse()
    68  	r := Response(*a)
    69  	return &r
    70  }
    71  
    72  // These implementations of EndpointReq use a parameterized conf.
    73  
    74  func (delete_item *DeleteItem) EndpointReqWithConf(c *conf.AWS_Conf) ([]byte, int, error) {
    75  	if delete_item == nil {
    76  		return nil, 0, errors.New("delete_item.(DeleteItem)EndpointReqWithConf: receiver is nil")
    77  	}
    78  	if !conf.IsValid(c) {
    79  		return nil, 0, errors.New("delete_item.EndpointReqWithConf: c is not valid")
    80  	}
    81  	// returns resp_body,code,err
    82  	reqJSON, json_err := json.Marshal(delete_item)
    83  	if json_err != nil {
    84  		return nil, 0, json_err
    85  	}
    86  	return authreq.RetryReqJSON_V4WithConf(reqJSON, DELETEITEM_ENDPOINT, c)
    87  }
    88  
    89  func (delete *Delete) EndpointReqWithConf(c *conf.AWS_Conf) ([]byte, int, error) {
    90  	if delete == nil {
    91  		return nil, 0, errors.New("delete_item.(Delete)EndpointReqWithConf: receiver is nil")
    92  	}
    93  	delete_item := DeleteItem(*delete)
    94  	return delete_item.EndpointReqWithConf(c)
    95  }
    96  
    97  func (req *Request) EndpointReqWithConf(c *conf.AWS_Conf) ([]byte, int, error) {
    98  	if req == nil {
    99  		return nil, 0, errors.New("delete_item.(Request)EndpointReqWithConf: receiver is nil")
   100  	}
   101  	delete_item := DeleteItem(*req)
   102  	return delete_item.EndpointReqWithConf(c)
   103  }
   104  
   105  // These implementations of EndpointReq use the global conf.
   106  
   107  func (delete_item *DeleteItem) EndpointReq() ([]byte, int, error) {
   108  	if delete_item == nil {
   109  		return nil, 0, errors.New("delete_item.(DeleteItem)EndpointReq: receiver is nil")
   110  	}
   111  	return delete_item.EndpointReqWithConf(&conf.Vals)
   112  }
   113  
   114  func (delete *Delete) EndpointReq() ([]byte, int, error) {
   115  	if delete == nil {
   116  		return nil, 0, errors.New("delete_item.(Delete)EndpointReq: receiver is nil")
   117  	}
   118  	delete_item := DeleteItem(*delete)
   119  	return delete_item.EndpointReqWithConf(&conf.Vals)
   120  }
   121  
   122  func (req *Request) EndpointReq() ([]byte, int, error) {
   123  	if req == nil {
   124  		return nil, 0, errors.New("delete_item.(Request)EndpointReq: receiver is nil")
   125  	}
   126  	delete_item := DeleteItem(*req)
   127  	return delete_item.EndpointReqWithConf(&conf.Vals)
   128  }