getlago / lago-go-client

Lago Go Client
MIT License
21 stars 20 forks source link

fix(inputs): Fix string encoding as paramters #190

Closed julienbourdeau closed 2 months ago

julienbourdeau commented 2 months ago

In Go, when a string attribute is explicitly noted at string for serialization, outer quotes are added ". I have no idea if it's intentional, but probably.

Typically, the WalletListInput.ExternalCustomerID will result in this URL:

/api/v1/wallets?external_customer_id=%22julien%22

Hence, the external_id we look for the DB is "julien", not julien.

SELECT
    "customers".*
FROM
    "customers"
WHERE
    "customers"."deleted_at" IS NULL
    AND "customers"."organization_id" = "external_id"
    AND "customers"."external_id" = "\"julien\""
LIMIT 1

Example

package main

import (
    "encoding/json"
    "fmt"
)

type Interesting struct {
    Quoted    string `json:"quoted,omitempty,string"`
    NotQuoted string `json:"not_quoted,omitempty"`
}

func main() {
    strings := Interesting{"lago", "lago"}
    fmt.Println(strings)
    fmt.Println()

    jsonStr, _ := json.Marshal(strings)
    fmt.Println(string(jsonStr))
    fmt.Println()

    asMap := make(map[string]string)
    json.Unmarshal(jsonStr, &asMap)
    fmt.Println(asMap)
}
$ go run main.go
{lago lago}

{"quoted":"\"lago\"","not_quoted":"lago"}

map[not_quoted:lago quoted:"lago"]