Made User-Agent version a variable.

This commit is contained in:
Bruce Marriner 2015-12-17 11:44:11 -06:00
parent 40a7e717f5
commit bb60b64ecb

View file

@ -39,12 +39,14 @@ func (s *Session) Request(method, urlStr string, data interface{}) (response []b
}
// Not used on initial login..
// TODO: Verify if a login, otherwise complain about no-token
if s.Token != "" {
req.Header.Set("authorization", s.Token)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", "DiscordBot (https://github.com/bwmarrin/discordgo, v0.0.0)")
// TODO: Make a configurable static variable.
req.Header.Set("User-Agent", fmt.Sprintf("DiscordBot (https://github.com/bwmarrin/discordgo, v%s", VERSION))
client := &http.Client{Timeout: (20 * time.Second)}
resp, err := client.Do(req)
@ -58,6 +60,7 @@ func (s *Session) Request(method, urlStr string, data interface{}) (response []b
}
resp.Body.Close()
// TODO check for 401 response, invalidate token if we get one.
if resp.StatusCode != 204 && resp.StatusCode != 200 {
err = fmt.Errorf("StatusCode: %d, %s", resp.StatusCode, string(response))
return