You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

user_email.go 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package gitea
  5. import (
  6. "bytes"
  7. "encoding/json"
  8. )
  9. type Email struct {
  10. Email string `json:"email"`
  11. Verified bool `json:"verified"`
  12. Primary bool `json:"primary"`
  13. }
  14. func (c *Client) ListEmails() ([]*Email, error) {
  15. emails := make([]*Email, 0, 3)
  16. return emails, c.getParsedResponse("GET", "/user/emails", nil, nil, &emails)
  17. }
  18. type CreateEmailOption struct {
  19. Emails []string `json:"emails"`
  20. }
  21. func (c *Client) AddEmail(opt CreateEmailOption) ([]*Email, error) {
  22. body, err := json.Marshal(&opt)
  23. if err != nil {
  24. return nil, err
  25. }
  26. emails := make([]*Email, 0, 3)
  27. return emails, c.getParsedResponse("POST", "/user/emails", jsonHeader, bytes.NewReader(body), emails)
  28. }
  29. func (c *Client) DeleteEmail(opt CreateEmailOption) error {
  30. body, err := json.Marshal(&opt)
  31. if err != nil {
  32. return err
  33. }
  34. _, err = c.getResponse("DELETE", "/user/emails", jsonHeader, bytes.NewReader(body))
  35. return err
  36. }