mirror of
https://github.com/watn3y/steamsalty.git
synced 2025-07-30 16:21:07 +02:00
v0.1
This commit is contained in:
parent
6aa64b6287
commit
3ec330e3a2
16 changed files with 408 additions and 1 deletions
48
steam/http.go
Normal file
48
steam/http.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package steam
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/rs/zerolog/log"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func getComments(steamID uint64, start int, count int) (comments CommentResponse) {
|
||||
|
||||
baseURL := "https://steamcommunity.com/comment/Profile/render/"
|
||||
|
||||
url, err := url.Parse(baseURL + strconv.FormatUint(steamID, 10))
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Unable to Parse SteamID into URL")
|
||||
return
|
||||
}
|
||||
|
||||
query := url.Query()
|
||||
query.Set("start", strconv.Itoa(start))
|
||||
query.Set("count", strconv.Itoa(count))
|
||||
url.RawQuery = query.Encode()
|
||||
|
||||
resp, err := http.Get(url.String())
|
||||
if err != nil || resp.StatusCode != http.StatusOK {
|
||||
log.Error().Err(err).Int("Response Code", resp.StatusCode).Msg("Failed to get Comments")
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Read the response body
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to parse Comments")
|
||||
log.Trace().Interface("Body", resp.Body)
|
||||
}
|
||||
|
||||
err = json.Unmarshal(body, &comments)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to parse Comments as JSON")
|
||||
}
|
||||
|
||||
log.Debug().Interface("CommentPage", comments).Msg("Successfully got Comment Page")
|
||||
return comments
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue