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.
38 lines
967 B
38 lines
967 B
package dao |
|
|
|
import ( |
|
"context" |
|
"net/http" |
|
"net/url" |
|
"strings" |
|
|
|
"go-common/app/admin/main/apm/conf" |
|
"go-common/app/admin/main/apm/model/ut" |
|
"go-common/library/log" |
|
) |
|
|
|
const ( |
|
_gitUsersAPI = "http://git.bilibili.co/api/v4/users" |
|
) |
|
|
|
// GitLabFace return face of gitlab. |
|
func (d *Dao) GitLabFace(c context.Context, username string) (avatarURL string, err error) { |
|
params := url.Values{} |
|
params.Set("username", username) |
|
params.Set("private_token", conf.Conf.Gitlab.Token) |
|
var req *http.Request |
|
if req, err = http.NewRequest(http.MethodGet, _gitUsersAPI, strings.NewReader(params.Encode())); err != nil { |
|
log.Error("http.NewRequest(%s) error(%v)", username, err) |
|
return |
|
} |
|
res := make([]*ut.Image, 0) |
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded") |
|
if err = d.client.Do(c, req, &res); err != nil { |
|
log.Error("d.client.Do(%s) error(%v)", username, err) |
|
return |
|
} |
|
for _, v := range res { |
|
avatarURL = v.AvatarURL |
|
} |
|
return |
|
}
|
|
|