mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-21 10:09:07 +00:00
Merge pull request #80 from justincormack/http-fetch-yaml
Add support to fetch yaml file with http
This commit is contained in:
commit
464396c63f
@ -8,6 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -198,6 +199,18 @@ func build(args []string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Cannot read stdin: %v", err)
|
log.Fatalf("Cannot read stdin: %v", err)
|
||||||
}
|
}
|
||||||
|
} else if strings.HasPrefix(arg, "http://") || strings.HasPrefix(arg, "https://") {
|
||||||
|
buffer := new(bytes.Buffer)
|
||||||
|
response, err := http.Get(arg)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Cannot fetch remote yaml file: %v", err)
|
||||||
|
}
|
||||||
|
defer response.Body.Close()
|
||||||
|
_, err = io.Copy(buffer, response.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Error reading http body: %v", err)
|
||||||
|
}
|
||||||
|
config = buffer.Bytes()
|
||||||
} else {
|
} else {
|
||||||
var err error
|
var err error
|
||||||
config, err = ioutil.ReadFile(conf)
|
config, err = ioutil.ReadFile(conf)
|
||||||
|
Loading…
Reference in New Issue
Block a user