2016-11-30 18:55:56 +01:00
|
|
|
package aur
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2016-12-17 01:40:51 +01:00
|
|
|
// BaseURL givers the AUR default address.
|
|
|
|
const BaseURL string = "https://aur.archlinux.org"
|
|
|
|
|
2017-01-05 17:13:52 +01:00
|
|
|
// Editor gives the default system editor, uses vi in last case
|
|
|
|
var Editor = "vi"
|
2016-12-17 01:40:51 +01:00
|
|
|
|
2016-11-30 18:55:56 +01:00
|
|
|
func init() {
|
|
|
|
if os.Getenv("EDITOR") != "" {
|
|
|
|
Editor = os.Getenv("EDITOR")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// getJSON handles JSON retrieval and decoding to struct
|
|
|
|
func getJSON(url string, target interface{}) error {
|
|
|
|
r, err := http.Get(url)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer r.Body.Close()
|
|
|
|
|
|
|
|
return json.NewDecoder(r.Body).Decode(target)
|
|
|
|
}
|
|
|
|
|
|
|
|
func downloadFile(filepath string, url string) (err error) {
|
|
|
|
// Create the file
|
|
|
|
out, err := os.Create(filepath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer out.Close()
|
|
|
|
|
|
|
|
// Get the data
|
|
|
|
resp, err := http.Get(url)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
// Writer the body to file
|
|
|
|
_, err = io.Copy(out, resp.Body)
|
2016-12-01 00:08:28 +01:00
|
|
|
return err
|
2016-11-30 18:55:56 +01:00
|
|
|
}
|