func (p dataProvider) Get(c schema.Content) (schema.Content, error) { schemeRest := strings.SplitN(c.Url, ":", 2) if len(schemeRest) < 2 || schemeRest[0] != "data" { return c, ErrInvalidDataURI } paramData := strings.SplitN(schemeRest[1], ",", 2) b64 := false if len(paramData) > 1 { params := strings.Split(paramData[0], ";") c.Type = params[0] if params[len(params)-1] == "base64" { b64 = true } } data, err := url.QueryUnescape(paramData[len(paramData)-1]) if err != nil { return c, err } if b64 { if c.Data, err = base64.StdEncoding.DecodeString(data); err != nil { return c, err } } else { c.Data = []byte(data) } if c.Type == "" { c.Type = "text/plain" } return c, nil }
func (p httpProvider) Get(c schema.Content) (schema.Content, error) { resp, err := http.Get(c.Url) if err != nil { return c, err } defer resp.Body.Close() if resp.StatusCode != 200 { return c, errors.New("unexpected status " + resp.Status) } body, err := ioutil.ReadAll(resp.Body) if err != nil { return c, err } c.Data = body c.Type = http.DetectContentType(c.Data) return c, err }