Skip to content

Commit

Permalink
Fix api requests & add timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Pepijn98 committed Nov 12, 2019
1 parent e8e1dde commit d6f10da
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions golane.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
"github.com/KurozeroPB/golane/structs"
"io"
"net/http"
"net/url"
"time"
)

const (
// Version the package version
Version = "1.0.0"
Version = "1.0.1"
baseURL = "https://azurlane-api.appspot.com/v1"
)

Expand Down Expand Up @@ -47,16 +49,18 @@ func (al *AzurLane) Init(params ...string) {
}
}

func get(url string, ua string) ([]byte, error) {
request, err := http.NewRequest("GET", url, nil)
func get(apiURL string, ua string) ([]byte, error) {
request, err := http.NewRequest("GET", url.PathEscape(apiURL), nil)
if err != nil {
return nil, err
}

request.Header.Set("User-Agent", ua)
request.Header.Set("Accept", "application/json")

client := http.Client{}
client := http.Client{
Timeout: time.Second * 10,
}
response, err := client.Do(request)
if err != nil {
return nil, err
Expand Down

0 comments on commit d6f10da

Please sign in to comment.