GetJson and GetCsv have now variadic URL parts so that you can submit pre or post parts of an URL. The parts will be joined to the final URL.

This commit is contained in:
Cyrill Schumacher 2015-02-08 15:33:30 +11:00 committed by spf13
parent 10c2b41b85
commit 076b618ff2

View file

@ -173,9 +173,11 @@ func resGetResource(url string) ([]byte, error) {
return resGetLocal(url, hugofs.SourceFs)
}
// GetJson expects the url to a resource which can either be a local or a remote one.
// GetJson expects one or n-parts of a URL to a resource which can either be a local or a remote one.
// If you provide multiple parts they will be joined together to the final URL.
// GetJson returns nil or parsed JSON to use in a short code.
func GetJson(url string) interface{} {
func GetJson(urlParts ...string) interface{} {
url := strings.Join(urlParts, "")
c, err := resGetResource(url)
if err != nil {
jww.ERROR.Printf("Failed to get json resource %s with error message %s", url, err)
@ -204,11 +206,13 @@ func parseCsv(c []byte, sep string) ([][]string, error) {
return r.ReadAll()
}
// GetCsv expects the url to a resource which can either be a local or a remote one and the type
// of the data separator which can be comma, semi-colon, pipe, but only one character.
// GetCsv expects a data separator and one or n-parts of a URL to a resource which
// can either be a local or a remote one.
// The data separator can be a comma, semi-colon, pipe, etc, but only one character.
// If you provide multiple parts for the URL they will be joined together to the final URL.
// GetCsv returns nil or a slice slice to use in a short code.
func GetCsv(url string, sep string) [][]string {
func GetCsv(sep string, urlParts ...string) [][]string {
url := strings.Join(urlParts, "")
c, err := resGetResource(url)
if err != nil {
jww.ERROR.Printf("Failed to get csv resource %s with error message %s", url, err)