Skip to content

Commit d3f81a9

Browse files
committed
Switch toolchain formatting to json.
Signed-off-by: David Calavera <[email protected]>
1 parent fb8b62e commit d3f81a9

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

go/porcelain/deploy.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"crypto/sha256"
99
"debug/elf"
1010
"encoding/hex"
11+
"encoding/json"
1112
"fmt"
1213
"io"
1314
"io/ioutil"
@@ -103,6 +104,10 @@ type FileBundle struct {
103104
Buffer io.ReadSeeker
104105
}
105106

107+
type toolchainSpec struct {
108+
Runtime string `json:"runtime"`
109+
}
110+
106111
func (f *FileBundle) Read(p []byte) (n int, err error) {
107112
return f.Buffer.Read(p)
108113
}
@@ -630,22 +635,13 @@ func readZipRuntime(filePath string) (string, error) {
630635
}
631636
defer fc.Close()
632637

633-
reader := bufio.NewReader(fc)
634-
for {
635-
line, err := reader.ReadString('\n')
636-
if err != nil && err != io.EOF {
637-
// Ignore any errors and choose the default runtime.
638-
// This preserves the current behavior in this library.
639-
return jsRuntime, nil
640-
}
641-
642-
if strings.HasPrefix(line, "runtime=") {
643-
split := strings.SplitN(line, "=", 2)
644-
if len(split) == 2 && split[1] != "" {
645-
return split[1], nil
646-
}
647-
}
638+
var tc toolchainSpec
639+
if err := json.NewDecoder(fc).Decode(&tc); err != nil {
640+
// Ignore any errors and choose the default runtime.
641+
// This preserves the current behavior in this library.
642+
return jsRuntime, nil
648643
}
644+
return tc.Runtime, nil
649645
}
650646
}
651647

go/porcelain/deploy_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func TestConcurrentFileUpload(t *testing.T) {
132132
}
133133

134134
func TestReadZipRuntime(t *testing.T) {
135-
runtime, err := readZipRuntime("../internal/data/hello-world.zip")
135+
runtime, err := readZipRuntime("../internal/data/hello-rs-function-test.zip")
136136
if err != nil {
137137
t.Fatalf("unexpected error reading zip file: %v", err)
138138
}

0 commit comments

Comments
 (0)