You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
660 B
38 lines
660 B
1 year ago
|
package utils
|
||
|
|
||
|
import (
|
||
|
"io/ioutil"
|
||
|
"net/http"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
func GetURI(url string, f func(i []byte) error) error {
|
||
|
if strings.HasPrefix(url, "file://") {
|
||
|
rawURL := strings.TrimPrefix(url, "file://")
|
||
|
// Read the response body
|
||
|
body, err := ioutil.ReadFile(rawURL)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
// Unmarshal YAML data into a struct
|
||
|
return f(body)
|
||
|
}
|
||
|
|
||
|
// Send a GET request to the URL
|
||
|
response, err := http.Get(url)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer response.Body.Close()
|
||
|
|
||
|
// Read the response body
|
||
|
body, err := ioutil.ReadAll(response.Body)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
// Unmarshal YAML data into a struct
|
||
|
return f(body)
|
||
|
}
|