All parameters are now of pointer type and thus can be nil

pull/97/head
buckket 2019-05-14 04:44:39 +02:00 committed by mattn
parent 636b33ad1c
commit e71411ef96
2 changed files with 8 additions and 8 deletions

View File

@ -41,10 +41,10 @@ type Field struct {
// AccountSource is a Mastodon account profile field.
type AccountSource struct {
Privacy string `json:"privacy"`
Privacy *string `json:"privacy"`
Sensitive *bool `json:"sensitive"`
Language string `json:"language"`
Note string `json:"note"`
Language *string `json:"language"`
Note *string `json:"note"`
Fields *[]Field `json:"fields"`
}
@ -102,14 +102,14 @@ func (c *Client) AccountUpdate(ctx context.Context, profile *Profile) (*Account,
}
}
if profile.Source != nil {
if len(profile.Source.Privacy) > 0 {
params.Set("source[privacy]", profile.Source.Privacy)
if profile.Source.Privacy != nil {
params.Set("source[privacy]", *profile.Source.Privacy)
}
if profile.Source.Sensitive != nil {
params.Set("source[sensitive]", strconv.FormatBool(*profile.Source.Sensitive))
}
if len(profile.Source.Language) > 0 {
params.Set("source[language]", profile.Source.Language)
if profile.Source.Language != nil {
params.Set("source[language]", *profile.Source.Language)
}
}
if profile.Avatar != "" {

View File

@ -96,7 +96,7 @@ func TestAccountUpdate(t *testing.T) {
}
tbool := true
fields := []Field{{"foo", "bar", time.Time{}}, {"dum", "baz", time.Time{}}}
source := AccountSource{Language: "de", Privacy: "public", Sensitive: &tbool}
source := AccountSource{Language: String("de"), Privacy: String("public"), Sensitive: &tbool}
a, err := client.AccountUpdate(context.Background(), &Profile{
DisplayName: String("display_name"),
Note: String("note"),