s/int/int64/ for IDs and time integers
authorMikael Berthe <mikael@lilotux.net>
Sun, 30 Apr 2017 20:43:17 +0200
changeset 159 408aa794d9bb
parent 158 083d33bb419b
child 160 9f7e683b323f
s/int/int64/ for IDs and time integers
account.go
api.go
app.go
login.go
madon.go
notifications.go
report.go
status.go
streams.go
types.go
--- a/account.go	Sun Apr 30 20:42:02 2017 +0200
+++ b/account.go	Sun Apr 30 20:43:17 2017 +0200
@@ -23,7 +23,7 @@
 // getAccountsOptions contains option fields for POST and DELETE API calls
 type getAccountsOptions struct {
 	// The ID is used for most commands
-	ID int
+	ID int64
 
 	// The Q field (query) is used when searching for accounts
 	Q string
@@ -36,10 +36,10 @@
 // "unfollow", "block", "unblock", "mute", "unmute",
 // "follow_requests/authorize" or // "follow_requests/reject".
 // The id is optional and depends on the operation.
-func (mc *Client) getSingleAccount(op string, id int) (*Account, error) {
+func (mc *Client) getSingleAccount(op string, id int64) (*Account, error) {
 	var endPoint string
 	method := rest.Get
-	strID := strconv.Itoa(id)
+	strID := strconv.FormatInt(id, 10)
 
 	switch op {
 	case "account":
@@ -84,7 +84,7 @@
 		if opts == nil || opts.ID < 1 {
 			return []Account{}, ErrInvalidID
 		}
-		endPoint = "accounts/" + strconv.Itoa(opts.ID) + "/" + op
+		endPoint = "accounts/" + strconv.FormatInt(opts.ID, 10) + "/" + op
 	case "follow_requests", "blocks", "mutes":
 		endPoint = op
 	case "search":
@@ -96,7 +96,7 @@
 		if opts == nil || opts.ID < 1 {
 			return []Account{}, ErrInvalidID
 		}
-		endPoint = "statuses/" + strconv.Itoa(opts.ID) + "/" + op
+		endPoint = "statuses/" + strconv.FormatInt(opts.ID, 10) + "/" + op
 	default:
 		return nil, ErrInvalidParameter
 	}
@@ -130,7 +130,7 @@
 // GetAccount returns an account entity
 // The returned value can be nil if there is an error or if the
 // requested ID does not exist.
-func (mc *Client) GetAccount(accountID int) (*Account, error) {
+func (mc *Client) GetAccount(accountID int64) (*Account, error) {
 	account, err := mc.getSingleAccount("account", accountID)
 	if err != nil {
 		return nil, err
@@ -154,19 +154,19 @@
 }
 
 // GetAccountFollowers returns the list of accounts following a given account
-func (mc *Client) GetAccountFollowers(accountID int, lopt *LimitParams) ([]Account, error) {
+func (mc *Client) GetAccountFollowers(accountID int64, lopt *LimitParams) ([]Account, error) {
 	o := &getAccountsOptions{ID: accountID, Limit: lopt}
 	return mc.getMultipleAccounts("followers", o)
 }
 
 // GetAccountFollowing returns the list of accounts a given account is following
-func (mc *Client) GetAccountFollowing(accountID int, lopt *LimitParams) ([]Account, error) {
+func (mc *Client) GetAccountFollowing(accountID int64, lopt *LimitParams) ([]Account, error) {
 	o := &getAccountsOptions{ID: accountID, Limit: lopt}
 	return mc.getMultipleAccounts("following", o)
 }
 
 // FollowAccount follows an account
-func (mc *Client) FollowAccount(accountID int) error {
+func (mc *Client) FollowAccount(accountID int64) error {
 	account, err := mc.getSingleAccount("follow", accountID)
 	if err != nil {
 		return err
@@ -178,7 +178,7 @@
 }
 
 // UnfollowAccount unfollows an account
-func (mc *Client) UnfollowAccount(accountID int) error {
+func (mc *Client) UnfollowAccount(accountID int64) error {
 	account, err := mc.getSingleAccount("unfollow", accountID)
 	if err != nil {
 		return err
@@ -210,7 +210,7 @@
 }
 
 // BlockAccount blocks an account
-func (mc *Client) BlockAccount(accountID int) error {
+func (mc *Client) BlockAccount(accountID int64) error {
 	account, err := mc.getSingleAccount("block", accountID)
 	if err != nil {
 		return err
@@ -222,7 +222,7 @@
 }
 
 // UnblockAccount unblocks an account
-func (mc *Client) UnblockAccount(accountID int) error {
+func (mc *Client) UnblockAccount(accountID int64) error {
 	account, err := mc.getSingleAccount("unblock", accountID)
 	if err != nil {
 		return err
@@ -234,7 +234,7 @@
 }
 
 // MuteAccount mutes an account
-func (mc *Client) MuteAccount(accountID int) error {
+func (mc *Client) MuteAccount(accountID int64) error {
 	account, err := mc.getSingleAccount("mute", accountID)
 	if err != nil {
 		return err
@@ -246,7 +246,7 @@
 }
 
 // UnmuteAccount unmutes an account
-func (mc *Client) UnmuteAccount(accountID int) error {
+func (mc *Client) UnmuteAccount(accountID int64) error {
 	account, err := mc.getSingleAccount("unmute", accountID)
 	if err != nil {
 		return err
@@ -286,7 +286,7 @@
 }
 
 // GetAccountRelationships returns a list of relationship entities for the given accounts
-func (mc *Client) GetAccountRelationships(accountIDs []int) ([]Relationship, error) {
+func (mc *Client) GetAccountRelationships(accountIDs []int64) ([]Relationship, error) {
 	if len(accountIDs) < 1 {
 		return nil, ErrInvalidID
 	}
@@ -297,7 +297,7 @@
 			return nil, ErrInvalidID
 		}
 		qID := fmt.Sprintf("id[%d]", i+1)
-		params[qID] = strconv.Itoa(id)
+		params[qID] = strconv.FormatInt(id, 10)
 	}
 
 	var rl []Relationship
@@ -314,12 +314,12 @@
 // has nothing to return.
 // If lopt.Limit is set (and not All), several queries can be made until the
 // limit is reached.
-func (mc *Client) GetAccountStatuses(accountID int, onlyMedia, excludeReplies bool, lopt *LimitParams) ([]Status, error) {
+func (mc *Client) GetAccountStatuses(accountID int64, onlyMedia, excludeReplies bool, lopt *LimitParams) ([]Status, error) {
 	if accountID < 1 {
 		return nil, ErrInvalidID
 	}
 
-	endPoint := "accounts/" + strconv.Itoa(accountID) + "/" + "statuses"
+	endPoint := "accounts/" + strconv.FormatInt(accountID, 10) + "/" + "statuses"
 	params := make(apiCallParams)
 	if onlyMedia {
 		params["only_media"] = "true"
@@ -349,7 +349,7 @@
 }
 
 // FollowRequestAuthorize authorizes or rejects an account follow-request
-func (mc *Client) FollowRequestAuthorize(accountID int, authorize bool) error {
+func (mc *Client) FollowRequestAuthorize(accountID int64, authorize bool) error {
 	endPoint := "follow_requests/reject"
 	if authorize {
 		endPoint = "follow_requests/authorize"
--- a/api.go	Sun Apr 30 20:42:02 2017 +0200
+++ b/api.go	Sun Apr 30 20:43:17 2017 +0200
@@ -51,13 +51,13 @@
 			}
 			lp = new(LimitParams)
 			if since != "" {
-				lp.SinceID, err = strconv.Atoi(since)
+				lp.SinceID, err = strconv.ParseInt(since, 10, 64)
 				if err != nil {
 					return al, err
 				}
 			}
 			if max != "" {
-				lp.MaxID, err = strconv.Atoi(max)
+				lp.MaxID, err = strconv.ParseInt(max, 10, 64)
 				if err != nil {
 					return al, err
 				}
@@ -178,10 +178,10 @@
 			params["limit"] = strconv.Itoa(limitOptions.Limit)
 		}
 		if limitOptions.SinceID > 0 {
-			params["since_id"] = strconv.Itoa(limitOptions.SinceID)
+			params["since_id"] = strconv.FormatInt(limitOptions.SinceID, 10)
 		}
 		if limitOptions.MaxID > 0 {
-			params["max_id"] = strconv.Itoa(limitOptions.MaxID)
+			params["max_id"] = strconv.FormatInt(limitOptions.MaxID, 10)
 		}
 	}
 
--- a/app.go	Sun Apr 30 20:42:02 2017 +0200
+++ b/app.go	Sun Apr 30 20:43:17 2017 +0200
@@ -16,7 +16,7 @@
 )
 
 type registerApp struct {
-	ID           int    `json:"id"`
+	ID           int64  `json:"id"`
 	ClientID     string `json:"client_id"`
 	ClientSecret string `json:"client_secret"`
 }
--- a/login.go	Sun Apr 30 20:42:02 2017 +0200
+++ b/login.go	Sun Apr 30 20:43:17 2017 +0200
@@ -17,7 +17,7 @@
 // UserToken represents a user token as returned by the Mastodon API
 type UserToken struct {
 	AccessToken string `json:"access_token"`
-	CreatedAt   int    `json:"created_at"`
+	CreatedAt   int64  `json:"created_at"`
 	Scope       string `json:"scope"`
 	TokenType   string `json:"token_type"`
 }
--- a/madon.go	Sun Apr 30 20:42:02 2017 +0200
+++ b/madon.go	Sun Apr 30 20:43:17 2017 +0200
@@ -13,9 +13,9 @@
 
 // LimitParams contains common limit/paging options for the Mastodon REST API
 type LimitParams struct {
-	Limit          int  // Number of items per query
-	SinceID, MaxID int  // Boundaries
-	All            bool // Get as many items as possible
+	Limit          int   // Number of items per query
+	SinceID, MaxID int64 // Boundaries
+	All            bool  // Get as many items as possible
 }
 
 // apiCallParams is a map with the parameters for an API call
--- a/notifications.go	Sun Apr 30 20:42:02 2017 +0200
+++ b/notifications.go	Sun Apr 30 20:43:17 2017 +0200
@@ -41,12 +41,12 @@
 // GetNotification returns a notification
 // The returned notification can be nil if there is an error or if the
 // requested notification does not exist.
-func (mc *Client) GetNotification(notificationID int) (*Notification, error) {
+func (mc *Client) GetNotification(notificationID int64) (*Notification, error) {
 	if notificationID < 1 {
 		return nil, ErrInvalidID
 	}
 
-	var endPoint = "notifications/" + strconv.Itoa(notificationID)
+	var endPoint = "notifications/" + strconv.FormatInt(notificationID, 10)
 	var notification Notification
 	if err := mc.apiCall(endPoint, rest.Get, nil, nil, nil, &notification); err != nil {
 		return nil, err
@@ -58,13 +58,13 @@
 }
 
 // DismissNotification deletes a notification
-func (mc *Client) DismissNotification(notificationID int) error {
+func (mc *Client) DismissNotification(notificationID int64) error {
 	if notificationID < 1 {
 		return ErrInvalidID
 	}
 
 	endPoint := "notifications/dismiss"
-	params := apiCallParams{"id": strconv.Itoa(notificationID)}
+	params := apiCallParams{"id": strconv.FormatInt(notificationID, 10)}
 	err := mc.apiCall(endPoint, rest.Post, params, nil, nil, &Notification{})
 	return err
 }
--- a/report.go	Sun Apr 30 20:42:02 2017 +0200
+++ b/report.go	Sun Apr 30 20:43:17 2017 +0200
@@ -24,20 +24,20 @@
 }
 
 // ReportUser reports the user account
-func (mc *Client) ReportUser(accountID int, statusIDs []int, comment string) (*Report, error) {
+func (mc *Client) ReportUser(accountID int64, statusIDs []int64, comment string) (*Report, error) {
 	if accountID < 1 || comment == "" || len(statusIDs) < 1 {
 		return nil, ErrInvalidParameter
 	}
 
 	params := make(apiCallParams)
-	params["account_id"] = strconv.Itoa(accountID)
+	params["account_id"] = strconv.FormatInt(accountID, 10)
 	params["comment"] = comment
 	for i, id := range statusIDs {
 		if id < 1 {
 			return nil, ErrInvalidID
 		}
 		qID := fmt.Sprintf("status_ids[%d]", i+1)
-		params[qID] = strconv.Itoa(id)
+		params[qID] = strconv.FormatInt(id, 10)
 	}
 
 	var report Report
--- a/status.go	Sun Apr 30 20:42:02 2017 +0200
+++ b/status.go	Sun Apr 30 20:43:17 2017 +0200
@@ -16,12 +16,12 @@
 // updateStatusOptions contains option fields for POST and DELETE API calls
 type updateStatusOptions struct {
 	// The ID is used for most commands
-	ID int
+	ID int64
 
 	// The following fields are used for posting a new status
 	Status      string
-	InReplyToID int
-	MediaIDs    []int
+	InReplyToID int64
+	MediaIDs    []int64
 	Sensitive   bool
 	SpoilerText string
 	Visibility  string // "direct", "private", "unlisted" or "public"
@@ -31,12 +31,12 @@
 // The operation 'op' can be empty or "status" (the status itself), "context",
 // "card", "reblogged_by", "favourited_by".
 // The data argument will receive the object(s) returned by the API server.
-func (mc *Client) queryStatusData(statusID int, op string, data interface{}) error {
+func (mc *Client) queryStatusData(statusID int64, op string, data interface{}) error {
 	if statusID < 1 {
 		return ErrInvalidID
 	}
 
-	endPoint := "statuses/" + strconv.Itoa(statusID)
+	endPoint := "statuses/" + strconv.FormatInt(statusID, 10)
 
 	if op != "" && op != "status" {
 		switch op {
@@ -80,12 +80,12 @@
 		if opts.ID < 1 {
 			return ErrInvalidID
 		}
-		endPoint += "/" + strconv.Itoa(opts.ID)
+		endPoint += "/" + strconv.FormatInt(opts.ID, 10)
 	case "reblog", "unreblog", "favourite", "unfavourite":
 		if opts.ID < 1 {
 			return ErrInvalidID
 		}
-		endPoint += "/" + strconv.Itoa(opts.ID) + "/" + op
+		endPoint += "/" + strconv.FormatInt(opts.ID, 10) + "/" + op
 	default:
 		return ErrInvalidParameter
 	}
@@ -94,14 +94,14 @@
 	if op == "status" {
 		params["status"] = opts.Status
 		if opts.InReplyToID > 0 {
-			params["in_reply_to_id"] = strconv.Itoa(opts.InReplyToID)
+			params["in_reply_to_id"] = strconv.FormatInt(opts.InReplyToID, 10)
 		}
 		for i, id := range opts.MediaIDs {
 			if id < 1 {
 				return ErrInvalidID
 			}
 			qID := fmt.Sprintf("media_ids[%d]", i+1)
-			params[qID] = strconv.Itoa(id)
+			params[qID] = strconv.FormatInt(id, 10)
 		}
 		if opts.Sensitive {
 			params["sensitive"] = "true"
@@ -120,7 +120,7 @@
 // GetStatus returns a status
 // The returned status can be nil if there is an error or if the
 // requested ID does not exist.
-func (mc *Client) GetStatus(statusID int) (*Status, error) {
+func (mc *Client) GetStatus(statusID int64) (*Status, error) {
 	var status Status
 
 	if err := mc.queryStatusData(statusID, "status", &status); err != nil {
@@ -133,7 +133,7 @@
 }
 
 // GetStatusContext returns a status context
-func (mc *Client) GetStatusContext(statusID int) (*Context, error) {
+func (mc *Client) GetStatusContext(statusID int64) (*Context, error) {
 	var context Context
 	if err := mc.queryStatusData(statusID, "context", &context); err != nil {
 		return nil, err
@@ -142,7 +142,7 @@
 }
 
 // GetStatusCard returns a status card
-func (mc *Client) GetStatusCard(statusID int) (*Card, error) {
+func (mc *Client) GetStatusCard(statusID int64) (*Card, error) {
 	var card Card
 	if err := mc.queryStatusData(statusID, "card", &card); err != nil {
 		return nil, err
@@ -151,13 +151,13 @@
 }
 
 // GetStatusRebloggedBy returns a list of the accounts who reblogged a status
-func (mc *Client) GetStatusRebloggedBy(statusID int, lopt *LimitParams) ([]Account, error) {
+func (mc *Client) GetStatusRebloggedBy(statusID int64, lopt *LimitParams) ([]Account, error) {
 	o := &getAccountsOptions{ID: statusID, Limit: lopt}
 	return mc.getMultipleAccounts("reblogged_by", o)
 }
 
 // GetStatusFavouritedBy returns a list of the accounts who favourited a status
-func (mc *Client) GetStatusFavouritedBy(statusID int, lopt *LimitParams) ([]Account, error) {
+func (mc *Client) GetStatusFavouritedBy(statusID int64, lopt *LimitParams) ([]Account, error) {
 	o := &getAccountsOptions{ID: statusID, Limit: lopt}
 	return mc.getMultipleAccounts("favourited_by", o)
 }
@@ -165,7 +165,7 @@
 // PostStatus posts a new "toot"
 // All parameters but "text" can be empty.
 // Visibility must be empty, or one of "direct", "private", "unlisted" and "public".
-func (mc *Client) PostStatus(text string, inReplyTo int, mediaIDs []int, sensitive bool, spoilerText string, visibility string) (*Status, error) {
+func (mc *Client) PostStatus(text string, inReplyTo int64, mediaIDs []int64, sensitive bool, spoilerText string, visibility string) (*Status, error) {
 	var status Status
 	o := updateStatusOptions{
 		Status:      text,
@@ -187,7 +187,7 @@
 }
 
 // DeleteStatus deletes a status
-func (mc *Client) DeleteStatus(statusID int) error {
+func (mc *Client) DeleteStatus(statusID int64) error {
 	var status Status
 	o := updateStatusOptions{ID: statusID}
 	err := mc.updateStatusData("delete", o, &status)
@@ -195,7 +195,7 @@
 }
 
 // ReblogStatus reblogs a status
-func (mc *Client) ReblogStatus(statusID int) error {
+func (mc *Client) ReblogStatus(statusID int64) error {
 	var status Status
 	o := updateStatusOptions{ID: statusID}
 	err := mc.updateStatusData("reblog", o, &status)
@@ -203,7 +203,7 @@
 }
 
 // UnreblogStatus unreblogs a status
-func (mc *Client) UnreblogStatus(statusID int) error {
+func (mc *Client) UnreblogStatus(statusID int64) error {
 	var status Status
 	o := updateStatusOptions{ID: statusID}
 	err := mc.updateStatusData("unreblog", o, &status)
@@ -211,7 +211,7 @@
 }
 
 // FavouriteStatus favourites a status
-func (mc *Client) FavouriteStatus(statusID int) error {
+func (mc *Client) FavouriteStatus(statusID int64) error {
 	var status Status
 	o := updateStatusOptions{ID: statusID}
 	err := mc.updateStatusData("favourite", o, &status)
@@ -219,7 +219,7 @@
 }
 
 // UnfavouriteStatus unfavourites a status
-func (mc *Client) UnfavouriteStatus(statusID int) error {
+func (mc *Client) UnfavouriteStatus(statusID int64) error {
 	var status Status
 	o := updateStatusOptions{ID: statusID}
 	err := mc.updateStatusData("unfavourite", o, &status)
--- a/streams.go	Sun Apr 30 20:42:02 2017 +0200
+++ b/streams.go	Sun Apr 30 20:43:17 2017 +0200
@@ -136,7 +136,7 @@
 				events <- StreamEvent{Event: "error", Error: e}
 				continue
 			}
-			obj = int(floatPayload) // statusID
+			obj = int64(floatPayload) // statusID
 		default:
 			e := fmt.Errorf("unhandled event '%s'", msg.Event)
 			events <- StreamEvent{Event: "error", Error: e}
--- a/types.go	Sun Apr 30 20:42:02 2017 +0200
+++ b/types.go	Sun Apr 30 20:43:17 2017 +0200
@@ -28,7 +28,7 @@
 
 // Account represents a Mastodon account entity
 type Account struct {
-	ID             int       `json:"id"`
+	ID             int64     `json:"id"`
 	Username       string    `json:"username"`
 	Acct           string    `json:"acct"`
 	DisplayName    string    `json:"display_name"`
@@ -38,9 +38,9 @@
 	Header         string    `json:"header"`
 	Locked         bool      `json:"locked"`
 	CreatedAt      time.Time `json:"created_at"`
-	FollowersCount int       `json:"followers_count"`
-	FollowingCount int       `json:"following_count"`
-	StatusesCount  int       `json:"statuses_count"`
+	FollowersCount int64     `json:"followers_count"`
+	FollowingCount int64     `json:"following_count"`
+	StatusesCount  int64     `json:"statuses_count"`
 }
 
 // Application represents a Mastodon application entity
@@ -51,7 +51,7 @@
 
 // Attachment represents a Mastodon attachement entity
 type Attachment struct {
-	ID         int    `json:"iD"`
+	ID         int64  `json:"iD"`
 	Type       string `json:"type"`
 	URL        string `json:"url"`
 	RemoteURL  string `json:"remote_url"`
@@ -89,7 +89,7 @@
 
 // Mention represents a Mastodon mention entity
 type Mention struct {
-	ID       int    `json:"id"`
+	ID       int64  `json:"id"`
 	URL      string `json:"url"`
 	Username string `json:"username"`
 	Acct     string `json:"acct"`
@@ -97,7 +97,7 @@
 
 // Notification represents a Mastodon notification entity
 type Notification struct {
-	ID        int       `json:"id"`
+	ID        int64     `json:"id"`
 	Type      string    `json:"type"`
 	CreatedAt time.Time `json:"created_at"`
 	Account   *Account  `json:"account"`
@@ -106,17 +106,17 @@
 
 // Relationship represents a Mastodon relationship entity
 type Relationship struct {
-	ID         int  `json:"id"`
-	Following  bool `json:"following"`
-	FollowedBy bool `json:"followed_by"`
-	Blocking   bool `json:"blocking"`
-	Muting     bool `json:"muting"`
-	Requested  bool `json:"requested"`
+	ID         int64 `json:"id"`
+	Following  bool  `json:"following"`
+	FollowedBy bool  `json:"followed_by"`
+	Blocking   bool  `json:"blocking"`
+	Muting     bool  `json:"muting"`
+	Requested  bool  `json:"requested"`
 }
 
 // Report represents a Mastodon report entity
 type Report struct {
-	ID          int    `json:"iD"`
+	ID          int64  `json:"iD"`
 	ActionTaken string `json:"action_taken"`
 }
 
@@ -129,17 +129,17 @@
 
 // Status represents a Mastodon status entity
 type Status struct {
-	ID                 int          `json:"id"`
+	ID                 int64        `json:"id"`
 	URI                string       `json:"uri"`
 	URL                string       `json:"url"`
 	Account            *Account     `json:"account"`
-	InReplyToID        int          `json:"in_reply_to_id"`
-	InReplyToAccountID int          `json:"in_reply_to_account_id"`
+	InReplyToID        int64        `json:"in_reply_to_id"`
+	InReplyToAccountID int64        `json:"in_reply_to_account_id"`
 	Reblog             *Status      `json:"reblog"`
 	Content            string       `json:"content"`
 	CreatedAt          time.Time    `json:"created_at"`
-	ReblogsCount       int          `json:"reblogs_count"`
-	FavouritesCount    int          `json:"favourites_count"`
+	ReblogsCount       int64        `json:"reblogs_count"`
+	FavouritesCount    int64        `json:"favourites_count"`
 	Reblogged          bool         `json:"reblogged"`
 	Favourited         bool         `json:"favourited"`
 	Sensitive          bool         `json:"sensitive"`