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

     1  // Support for the DynamoDB ListTables endpoint.
     2  //
     3  // example use:
     4  //
     5  // tests/create_table-livestest.go, which contains a ListTables invocation
     6  //
     7  package list_tables
     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  )
    16  
    17  const (
    18  	ENDPOINT_NAME              = "ListTables"
    19  	LISTTABLE_ENDPOINT         = aws_const.ENDPOINT_PREFIX + ENDPOINT_NAME
    20  	EXCLUSIVE_START_TABLE_NAME = "ExclusiveStartTableName"
    21  	LIMIT                      = "Limit"
    22  	LAST_EVALUATED_TABLE_NAME  = "LastEvaluatedTableName"
    23  	AWS_LIMIT                  = 100
    24  )
    25  
    26  type ListTables struct {
    27  	ExclusiveStartTableName string `json:",omitempty"`
    28  	Limit                   uint64 `json:",omitempty"`
    29  }
    30  
    31  // List is an alias for backwards compatibility
    32  type List ListTables
    33  
    34  type Request ListTables
    35  
    36  type Response struct {
    37  	TableNames             []string
    38  	LastEvaluatedTableName string `json:",omitempty"`
    39  }
    40  
    41  func NewResponse() *Response {
    42  	r := new(Response)
    43  	r.TableNames = make([]string, 0)
    44  	return r
    45  }
    46  
    47  // These implementations of EndpointReq use a parameterized conf.
    48  
    49  func (list_tables *ListTables) EndpointReqWithConf(c *conf.AWS_Conf) ([]byte, int, error) {
    50  	if list_tables == nil {
    51  		return nil, 0, errors.New("list_tables.(ListTables)EndpointReqWithConf: receiver is nil")
    52  	}
    53  	if !conf.IsValid(c) {
    54  		return nil, 0, errors.New("list_tables.EndpointReqWithConf: c is not valid")
    55  	}
    56  	// returns resp_body,code,err
    57  	reqJSON, json_err := json.Marshal(list_tables)
    58  	if json_err != nil {
    59  		return nil, 0, json_err
    60  	}
    61  	return authreq.RetryReqJSON_V4WithConf(reqJSON, LISTTABLE_ENDPOINT, c)
    62  }
    63  
    64  func (list *List) EndpointReqWithConf(c *conf.AWS_Conf) ([]byte, int, error) {
    65  	if list == nil {
    66  		return nil, 0, errors.New("list_tables.(List)EndpointReqWithConf: receiver is nil")
    67  	}
    68  	list_tables := ListTables(*list)
    69  	return list_tables.EndpointReqWithConf(c)
    70  }
    71  
    72  func (req *Request) EndpointReqWithConf(c *conf.AWS_Conf) ([]byte, int, error) {
    73  	if req == nil {
    74  		return nil, 0, errors.New("list_tables.(Request)EndpointReqWithConf: receiver is nil")
    75  	}
    76  	list_tables := ListTables(*req)
    77  	return list_tables.EndpointReqWithConf(c)
    78  }
    79  
    80  // These implementations of EndpointReq use the global conf.
    81  
    82  func (list_table *ListTables) EndpointReq() ([]byte, int, error) {
    83  	if list_table == nil {
    84  		return nil, 0, errors.New("list_tables.(ListTables)EndpointReq: receiver is nil")
    85  	}
    86  	return list_table.EndpointReqWithConf(&conf.Vals)
    87  }
    88  
    89  func (list *List) EndpointReq() ([]byte, int, error) {
    90  	if list == nil {
    91  		return nil, 0, errors.New("list_tables.(List)EndpointReq: receiver is nil")
    92  	}
    93  	list_table := ListTables(*list)
    94  	return list_table.EndpointReqWithConf(&conf.Vals)
    95  }
    96  
    97  func (req *Request) EndpointReq() ([]byte, int, error) {
    98  	if req == nil {
    99  		return nil, 0, errors.New("list_tables.(Request)EndpointReq: receiver is nil")
   100  	}
   101  	list_table := ListTables(*req)
   102  	return list_table.EndpointReqWithConf(&conf.Vals)
   103  }