Fix golang clients string -> int64 unmarshale error (#217)

This commit is contained in:
Janos Dobronszki
2021-09-27 12:12:33 +01:00
committed by GitHub
parent 6992fae6cf
commit 24c120896d
15 changed files with 42 additions and 37 deletions

View File

@@ -50,14 +50,14 @@ type DecrementRequest struct {
// The key to decrement // The key to decrement
Key string `json:"key"` Key string `json:"key"`
// The amount to decrement the value by // The amount to decrement the value by
Value int64 `json:"value"` Value int64 `json:"value,string"`
} }
type DecrementResponse struct { type DecrementResponse struct {
// The key decremented // The key decremented
Key string `json:"key"` Key string `json:"key"`
// The new value // The new value
Value int64 `json:"value"` Value int64 `json:"value,string"`
} }
type DeleteRequest struct { type DeleteRequest struct {
@@ -79,7 +79,7 @@ type GetResponse struct {
// The key // The key
Key string `json:"key"` Key string `json:"key"`
// Time to live in seconds // Time to live in seconds
Ttl int64 `json:"ttl"` Ttl int64 `json:"ttl,string"`
// The value // The value
Value string `json:"value"` Value string `json:"value"`
} }
@@ -88,21 +88,21 @@ type IncrementRequest struct {
// The key to increment // The key to increment
Key string `json:"key"` Key string `json:"key"`
// The amount to increment the value by // The amount to increment the value by
Value int64 `json:"value"` Value int64 `json:"value,string"`
} }
type IncrementResponse struct { type IncrementResponse struct {
// The key incremented // The key incremented
Key string `json:"key"` Key string `json:"key"`
// The new value // The new value
Value int64 `json:"value"` Value int64 `json:"value,string"`
} }
type SetRequest struct { type SetRequest struct {
// The key to update // The key to update
Key string `json:"key"` Key string `json:"key"`
// Time to live in seconds // Time to live in seconds
Ttl int64 `json:"ttl"` Ttl int64 `json:"ttl,string"`
// The value to set // The value to set
Value string `json:"value"` Value string `json:"value"`
} }

View File

@@ -38,7 +38,7 @@ type CallResponse struct {
type StreamRequest struct { type StreamRequest struct {
// the number of messages to send back // the number of messages to send back
Messages int64 `json:"messages"` Messages int64 `json:"messages,string"`
Name string `json:"name"` Name string `json:"name"`
} }

View File

@@ -61,7 +61,7 @@ type ListRequest struct {
// The 2 letter country code (as defined in ISO 3166-1 alpha-2) // The 2 letter country code (as defined in ISO 3166-1 alpha-2)
CountryCode string `json:"countryCode"` CountryCode string `json:"countryCode"`
// The year to list holidays for // The year to list holidays for
Year int64 `json:"year"` Year int64 `json:"year,string"`
} }
type ListResponse struct { type ListResponse struct {

View File

@@ -85,14 +85,14 @@ type ResizeRequest struct {
// if provided, after resize, the image // if provided, after resize, the image
// will be cropped // will be cropped
CropOptions *CropOptions `json:"cropOptions"` CropOptions *CropOptions `json:"cropOptions"`
Height int64 `json:"height"` Height int64 `json:"height,string"`
// output name of the image including extension, ie. "cat.png" // output name of the image including extension, ie. "cat.png"
Name string `json:"name"` Name string `json:"name"`
// make output a URL and not a base64 response // make output a URL and not a base64 response
OutputUrl bool `json:"outputUrl"` OutputUrl bool `json:"outputUrl"`
// url of the image to resize // url of the image to resize
Url string `json:"url"` Url string `json:"url"`
Width int64 `json:"width"` Width int64 `json:"width,string"`
} }
type ResizeResponse struct { type ResizeResponse struct {

View File

@@ -43,7 +43,7 @@ type Entity struct {
type Point struct { type Point struct {
Latitude float64 `json:"latitude"` Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"` Longitude float64 `json:"longitude"`
Timestamp int64 `json:"timestamp"` Timestamp int64 `json:"timestamp,string"`
} }
type ReadRequest struct { type ReadRequest struct {
@@ -66,7 +66,7 @@ type SearchRequest struct {
// Central position to search from // Central position to search from
Center *Point `json:"center"` Center *Point `json:"center"`
// Maximum number of entities to return // Maximum number of entities to return
NumEntities int64 `json:"numEntities"` NumEntities int64 `json:"numEntities,string"`
// radius in meters // radius in meters
Radius float64 `json:"radius"` Radius float64 `json:"radius"`
// type of entities to filter // type of entities to filter

View File

@@ -30,11 +30,11 @@ func (t *OtpService) Validate(request *ValidateRequest) (*ValidateResponse, erro
type GenerateRequest struct { type GenerateRequest struct {
// expiration in seconds (default: 60) // expiration in seconds (default: 60)
Expiry int64 `json:"expiry"` Expiry int64 `json:"expiry,string"`
// unique id, email or user to generate an OTP for // unique id, email or user to generate an OTP for
Id string `json:"id"` Id string `json:"id"`
// number of characters (default: 6) // number of characters (default: 6)
Size int64 `json:"size"` Size int64 `json:"size,string"`
} }
type GenerateResponse struct { type GenerateResponse struct {

View File

@@ -24,7 +24,7 @@ func (t *QrService) Generate(request *GenerateRequest) (*GenerateResponse, error
type GenerateRequest struct { type GenerateRequest struct {
// the size (height and width) in pixels of the generated QR code. Defaults to 256 // the size (height and width) in pixels of the generated QR code. Defaults to 256
Size int64 `json:"size"` Size int64 `json:"size,string"`
// the text to encode as a QR code (URL, phone number, email, etc) // the text to encode as a QR code (URL, phone number, email, etc)
Text string `json:"text"` Text string `json:"text"`
} }

View File

@@ -86,11 +86,11 @@ type Feed struct {
type FeedRequest struct { type FeedRequest struct {
// limit entries returned // limit entries returned
Limit int64 `json:"limit"` Limit int64 `json:"limit,string"`
// rss feed name // rss feed name
Name string `json:"name"` Name string `json:"name"`
// offset entries // offset entries
Offset int64 `json:"offset"` Offset int64 `json:"offset,string"`
} }
type FeedResponse struct { type FeedResponse struct {

View File

@@ -43,7 +43,7 @@ type NowResponse struct {
// the timezone as BST // the timezone as BST
Timezone string `json:"timezone"` Timezone string `json:"timezone"`
// the unix timestamp // the unix timestamp
Unix int64 `json:"unix"` Unix int64 `json:"unix,string"`
} }
type ZoneRequest struct { type ZoneRequest struct {

View File

@@ -46,9 +46,9 @@ type Profile struct {
// the user description // the user description
Description string `json:"description"` Description string `json:"description"`
// the follower count // the follower count
Followers int64 `json:"followers"` Followers int64 `json:"followers,string"`
// the user id // the user id
Id int64 `json:"id"` Id int64 `json:"id,string"`
// The user's profile picture // The user's profile picture
ImageUrl string `json:"imageUrl"` ImageUrl string `json:"imageUrl"`
// the user's location // the user's location
@@ -91,7 +91,7 @@ type Trend struct {
// name of the trend // name of the trend
Name string `json:"name"` Name string `json:"name"`
// the volume of tweets in last 24 hours // the volume of tweets in last 24 hours
TweetVolume int64 `json:"tweetVolume"` TweetVolume int64 `json:"tweetVolume,string"`
// the twitter url // the twitter url
Url string `json:"url"` Url string `json:"url"`
} }
@@ -108,11 +108,11 @@ type Tweet struct {
// time of tweet // time of tweet
CreatedAt string `json:"createdAt"` CreatedAt string `json:"createdAt"`
// number of times favourited // number of times favourited
FavouritedCount int64 `json:"favouritedCount"` FavouritedCount int64 `json:"favouritedCount,string"`
// id of the tweet // id of the tweet
Id int64 `json:"id"` Id int64 `json:"id,string"`
// number of times retweeted // number of times retweeted
RetweetedCount int64 `json:"retweetedCount"` RetweetedCount int64 `json:"retweetedCount,string"`
// text of the tweet // text of the tweet
Text string `json:"text"` Text string `json:"text"`
// username of the person who tweeted // username of the person who tweeted

View File

@@ -62,12 +62,12 @@ type ShortenResponse struct {
} }
type URLPair struct { type URLPair struct {
Created int64 `json:"created"` Created int64 `json:"created,string"`
DestinationUrl string `json:"destinationUrl"` DestinationUrl string `json:"destinationUrl"`
// HitCount keeps track many times the short URL has been resolved. // HitCount keeps track many times the short URL has been resolved.
// Hitcount only gets saved to disk (database) after every 10th hit, so // Hitcount only gets saved to disk (database) after every 10th hit, so
// its not intended to be 100% accurate, more like an almost correct estimate. // its not intended to be 100% accurate, more like an almost correct estimate.
HitCount int64 `json:"hitCount"` HitCount int64 `json:"hitCount,string"`
Owner string `json:"owner"` Owner string `json:"owner"`
ShortUrl string `json:"shortUrl"` ShortUrl string `json:"shortUrl"`
} }

View File

@@ -85,7 +85,7 @@ func (t *UserService) VerifyEmail(request *VerifyEmailRequest) (*VerifyEmailResp
type Account struct { type Account struct {
// unix timestamp // unix timestamp
Created int64 `json:"created"` Created int64 `json:"created,string"`
// an email address // an email address
Email string `json:"email"` Email string `json:"email"`
// unique account id // unique account id
@@ -93,10 +93,10 @@ type Account struct {
// Store any custom data you want about your users in this fields. // Store any custom data you want about your users in this fields.
Profile map[string]string `json:"profile"` Profile map[string]string `json:"profile"`
// unix timestamp // unix timestamp
Updated int64 `json:"updated"` Updated int64 `json:"updated,string"`
// alphanumeric username // alphanumeric username
Username string `json:"username"` Username string `json:"username"`
VerificationDate int64 `json:"verificationDate"` VerificationDate int64 `json:"verificationDate,string"`
Verified bool `json:"verified"` Verified bool `json:"verified"`
} }
@@ -185,9 +185,9 @@ type SendVerificationEmailResponse struct {
type Session struct { type Session struct {
// unix timestamp // unix timestamp
Created int64 `json:"created"` Created int64 `json:"created,string"`
// unix timestamp // unix timestamp
Expires int64 `json:"expires"` Expires int64 `json:"expires,string"`
// the session id // the session id
Id string `json:"id"` Id string `json:"id"`
// the associated user id // the associated user id

View File

@@ -61,5 +61,5 @@
}, },
"type": "module", "type": "module",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
"version": "1.0.529" "version": "1.0.530"
} }

View File

@@ -710,6 +710,7 @@ func schemaToType(language, serviceName, typeName string, schemas map[string]*op
if fieldUpperCase { if fieldUpperCase {
k = strcase.UpperCamelCase(k) k = strcase.UpperCamelCase(k)
} }
var typ string
// @todo clean up this piece of code by // @todo clean up this piece of code by
// separating out type string marshaling and not // separating out type string marshaling and not
// repeating code // repeating code
@@ -765,7 +766,7 @@ func schemaToType(language, serviceName, typeName string, schemas map[string]*op
case "string": case "string":
ret += k + fieldSeparator + stringType + fieldDelimiter ret += k + fieldSeparator + stringType + fieldDelimiter
case "number": case "number":
typ := numberType typ = numberType
switch v.Value.Format { switch v.Value.Format {
case "int32": case "int32":
typ = int32Type typ = int32Type
@@ -780,9 +781,13 @@ func schemaToType(language, serviceName, typeName string, schemas map[string]*op
case "boolean": case "boolean":
ret += k + fieldSeparator + boolType + fieldDelimiter ret += k + fieldSeparator + boolType + fieldDelimiter
} }
// go specific hack for lowercase son // go specific hack for lowercase json
if language == "go" { if language == "go" {
ret += " " + "`json:\"" + strcase.LowerCamelCase(k) + "\"`" ret += " " + "`json:\"" + strcase.LowerCamelCase(k)
if typ == int64Type {
ret += ",string"
}
ret += "\"`"
} }
if i < len(props) { if i < len(props) {

View File

@@ -11,10 +11,10 @@ func CreateArecord() {
dbService := db.NewDbService(os.Getenv("MICRO_API_TOKEN")) dbService := db.NewDbService(os.Getenv("MICRO_API_TOKEN"))
rsp, err := dbService.Create(&db.CreateRequest{ rsp, err := dbService.Create(&db.CreateRequest{
Record: map[string]interface{}{ Record: map[string]interface{}{
"id": "1",
"name": "Jane",
"age": 42, "age": 42,
"isActive": true, "isActive": true,
"id": "1",
"name": "Jane",
}, },
Table: "users", Table: "users",
}) })