Skip to content

Commit

Permalink
added file fetch utility
Browse files Browse the repository at this point in the history
Signed-off-by: kumarabd <[email protected]>
  • Loading branch information
kumarabd committed Nov 18, 2020
1 parent f9a273d commit fb02674
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package utils

import (
"bytes"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -105,3 +106,20 @@ func CreateFile(contents []byte, filename string, location string) error {

return nil
}

func ReadRemoteFile(url string) (string, error) {
response, err := http.Get(url)
if err != nil {
return " ", err
}

defer response.Body.Close()

buf := new(bytes.Buffer)
_, err = io.Copy(buf, response.Body)
if err != nil {
return " ", err
}

return buf.String(), nil
}

0 comments on commit fb02674

Please sign in to comment.