refactor: use pkg directory structure
This commit is contained in:
23
pkg/web/web.go
Normal file
23
pkg/web/web.go
Normal file
@ -0,0 +1,23 @@
|
||||
// Package web provides functionality for dealing with web operations.
|
||||
package web
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Timeout is the time it takes before a web request bails out waiting for a
|
||||
// request.
|
||||
const Timeout = 10 * time.Second
|
||||
|
||||
// ReadJSON reads JSON and parses it into your chosen interface pointer
|
||||
func ReadJSON(url string, target interface{}) error {
|
||||
httpClient := &http.Client{Timeout: Timeout}
|
||||
res, err := httpClient.Get(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
return json.NewDecoder(res.Body).Decode(target)
|
||||
}
|
Reference in New Issue
Block a user