test, examples: lang: Add new syntax for map lookup
Sugar at last!
This commit is contained in:
@@ -2,7 +2,7 @@ import "fmt"
|
||||
import "sys"
|
||||
|
||||
$env = sys.env()
|
||||
$m = map_lookup_optional($env, "GOPATH", "")
|
||||
$m = $env["GOPATH"] || ""
|
||||
|
||||
print "print0" {
|
||||
msg => if sys.hasenv("GOPATH") {
|
||||
|
||||
@@ -2,13 +2,13 @@ import "fmt"
|
||||
|
||||
$m = {"k1" => 42, "k2" => 13,}
|
||||
|
||||
$found = map_lookup_optional($m, "k1", 99)
|
||||
$found = $m["k1"] || 99
|
||||
|
||||
print "print1" {
|
||||
msg => fmt.printf("found value of: %d", $found),
|
||||
}
|
||||
|
||||
$notfound = map_lookup_optional($m, "k3", 99)
|
||||
$notfound = $m["k3"] || 99
|
||||
|
||||
print "print2" {
|
||||
msg => fmt.printf("notfound value of: %d", $notfound),
|
||||
|
||||
@@ -3,7 +3,7 @@ import "world"
|
||||
|
||||
$ns = "estate"
|
||||
$exchanged = world.kvlookup($ns)
|
||||
$state = map_lookup_optional($exchanged, $hostname, "default")
|
||||
$state = $exchanged[$hostname] || "default"
|
||||
|
||||
exec "exec0" {
|
||||
cmd => "echo hello world && echo goodbye world 1>&2", # to stdout && stderr
|
||||
|
||||
@@ -2,7 +2,7 @@ import "world"
|
||||
|
||||
$ns = "estate"
|
||||
$exchanged = world.kvlookup($ns)
|
||||
$state = map_lookup_optional($exchanged, $hostname, "default")
|
||||
$state = $exchanged[$hostname] || "default"
|
||||
|
||||
if $state == "one" or $state == "default" {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user