Files
mgmt/examples/lang/readonlyfriday.mcl
James Shubin 29eebd0d07 lang: core: Move template to golang namespace
I don't think this template function should be in any way authoritative,
so let's namespace it.
2024-09-13 15:51:24 -04:00

32 lines
635 B
Plaintext

import "datetime"
import "fmt"
import "golang"
$now = datetime.now()
$day = datetime.weekday($now)
$is_friday = $day == "friday"
$s1 = golang.template("Hello! It is now: {{ datetime_print . }}\n", $now)
$s2 = if $is_friday {
"It's friday!!! (don't break anything, read-only)"
} else {
if $day == "saturday" or $day == "sunday" {
"It's the weekend!"
} else {
fmt.printf("Unfortunately, it is %s. Go to work!", $day)
}
}
print "msg" {
msg => $s1 + $s2,
}
file "/tmp/files/" {
state => $const.res.file.state.exists,
mode => if $is_friday { # this updates the mode, the instant it changes!
"0550"
} else {
"0770"
},
}