ut_rank.go 967 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package dao
  2. import (
  3. "context"
  4. "net/http"
  5. "net/url"
  6. "strings"
  7. "go-common/app/admin/main/apm/conf"
  8. "go-common/app/admin/main/apm/model/ut"
  9. "go-common/library/log"
  10. )
  11. const (
  12. _gitUsersAPI = "http://git.bilibili.co/api/v4/users"
  13. )
  14. // GitLabFace return face of gitlab.
  15. func (d *Dao) GitLabFace(c context.Context, username string) (avatarURL string, err error) {
  16. params := url.Values{}
  17. params.Set("username", username)
  18. params.Set("private_token", conf.Conf.Gitlab.Token)
  19. var req *http.Request
  20. if req, err = http.NewRequest(http.MethodGet, _gitUsersAPI, strings.NewReader(params.Encode())); err != nil {
  21. log.Error("http.NewRequest(%s) error(%v)", username, err)
  22. return
  23. }
  24. res := make([]*ut.Image, 0)
  25. req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
  26. if err = d.client.Do(c, req, &res); err != nil {
  27. log.Error("d.client.Do(%s) error(%v)", username, err)
  28. return
  29. }
  30. for _, v := range res {
  31. avatarURL = v.AvatarURL
  32. }
  33. return
  34. }