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

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

View File

@ -96,7 +96,7 @@ func TestAccountUpdate(t *testing.T) {
} }
tbool := true tbool := true
fields := []Field{{"foo", "bar", time.Time{}}, {"dum", "baz", time.Time{}}} 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{ a, err := client.AccountUpdate(context.Background(), &Profile{
DisplayName: String("display_name"), DisplayName: String("display_name"),
Note: String("note"), Note: String("note"),