Helper method for HTTP requests
This commit is contained in:
parent
5d64f5d035
commit
ba5b373fa0
|
@ -0,0 +1,20 @@
|
||||||
|
package helpers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
)
|
||||||
|
|
||||||
|
func DoRequest(method string, requestURL string) (*http.Response, error) {
|
||||||
|
parsedURL, _ := url.Parse(requestURL)
|
||||||
|
request := http.Request{
|
||||||
|
Method: method,
|
||||||
|
URL: parsedURL,
|
||||||
|
Header: map[string][]string{
|
||||||
|
"User-Agent": {"github.com/fmartingr/games-screenshot-manager"},
|
||||||
|
},
|
||||||
|
ProtoMajor: 2,
|
||||||
|
ProtoMinor: 1,
|
||||||
|
}
|
||||||
|
return http.DefaultClient.Do(&request)
|
||||||
|
}
|
|
@ -5,8 +5,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
|
||||||
"net/url"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -18,6 +16,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const providerName string = "steam"
|
const providerName string = "steam"
|
||||||
|
const gameListURL string = "https://api.steampowered.com/ISteamApps/GetAppList/v2/"
|
||||||
|
|
||||||
type SteamApp struct {
|
type SteamApp struct {
|
||||||
AppID uint64 `json:"appid"`
|
AppID uint64 `json:"appid"`
|
||||||
|
@ -57,19 +56,9 @@ func getBasePathForOS() string {
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSteamAppsList(c chan SteamAppList) {
|
func getSteamAppList(c chan SteamAppList) {
|
||||||
log.Println("Updating steam game list...")
|
log.Println("Updating steam game list...")
|
||||||
steamGetAppListURL, _ := url.Parse("https://api.steampowered.com/ISteamApps/GetAppList/v2/")
|
response, err := helpers.DoRequest("GET", gameListURL)
|
||||||
request := http.Request{
|
|
||||||
Method: "GET",
|
|
||||||
URL: steamGetAppListURL,
|
|
||||||
Header: map[string][]string{
|
|
||||||
"User-Agent": {"games-screenshot-manager/0.0.1"},
|
|
||||||
},
|
|
||||||
ProtoMajor: 2,
|
|
||||||
ProtoMinor: 1,
|
|
||||||
}
|
|
||||||
response, err := http.DefaultClient.Do(&request)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -160,7 +149,7 @@ func GetScreenshotsForGame(user string, game *games.Game) {
|
||||||
func GetGames() []games.Game {
|
func GetGames() []games.Game {
|
||||||
var localGames []games.Game
|
var localGames []games.Game
|
||||||
c := make(chan SteamAppList)
|
c := make(chan SteamAppList)
|
||||||
go GetSteamAppsList(c)
|
go getSteamAppList(c)
|
||||||
users := GuessUsers()
|
users := GuessUsers()
|
||||||
steamApps := <-c
|
steamApps := <-c
|
||||||
for _, userID := range users {
|
for _, userID := range users {
|
||||||
|
|
Loading…
Reference in New Issue