Skip to content

Commit e4e2ea9

Browse files
committed
Use env vars to get information in Go API
1 parent d3b8b3d commit e4e2ea9

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

compute.json

-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
"address_space": 1800,
8383
"remapping": ["0xC000000000", 256],
8484
"max_memory": 64,
85-
"relocate_fixed_mmap": false,
8685
"concurrency": 4,
8786
"storage": true
8887
},

go/goexample/goexample.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func main() {
5353

5454
varnish.StorageRegister("my_storage", my_storage)
5555

56-
fmt.Println("Go Compute Example ready (", os.Args[2], ")")
56+
// Storage/request can be determined from environment variable KVM_TYPE
57+
fmt.Println("Go Compute Example ready (", os.Getenv("KVM_TYPE"), ")")
5758
varnish.WaitForRequests()
5859
}

go/varnish/api.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ import "C"
3232
import (
3333
"errors"
3434
"os"
35-
"strings"
3635
"unsafe"
3736
)
3837

3938
func IsLinuxMain() bool {
40-
return strings.Contains(os.Args[0], "/")
39+
// The presence of environment variable KVM_TYPE means we are running
40+
// in a KVM sandbox. Simply check if it exists:
41+
_, ok := os.LookupEnv("KVM_TYPE")
42+
return !ok
4143
}
4244

4345
type GetHandler func(string, string)

0 commit comments

Comments
 (0)