mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
MAINT: Adopt go 1.16's embed feature (#1162)
* MAINT: Switch from esc to embed * Simplify * Update minimum go version in docs and pipelines * go generate
This commit is contained in:
20
pkg/js/js.go
20
pkg/js/js.go
@ -1,9 +1,11 @@
|
||||
package js
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@ -21,6 +23,10 @@ import (
|
||||
"github.com/StackExchange/dnscontrol/v3/pkg/transform"
|
||||
)
|
||||
|
||||
//go:embed helpers.js
|
||||
var helpersJsStatic string
|
||||
var helpersJsFileName = "pkg/js/helpers.js"
|
||||
|
||||
// currentDirectory is the current directory as used by require().
|
||||
// This is used to emulate nodejs-style require() directory handling.
|
||||
// If require("a/b/c.js") is called, any require() statement in c.js
|
||||
@ -101,9 +107,19 @@ func ExecuteJavascript(file string, devMode bool, variables map[string]string) (
|
||||
return conf, nil
|
||||
}
|
||||
|
||||
// GetHelpers returns the filename of helpers.js, or the esc'ed version.
|
||||
// GetHelpers returns the contents of helpers.js, or the embedded version.
|
||||
func GetHelpers(devMode bool) string {
|
||||
return _escFSMustString(devMode, "/helpers.js")
|
||||
if devMode {
|
||||
// Load the file:
|
||||
b, err := ioutil.ReadFile(helpersJsFileName)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// Return the embedded bytes:
|
||||
return helpersJsStatic
|
||||
}
|
||||
|
||||
func require(call otto.FunctionCall) otto.Value {
|
||||
|
Reference in New Issue
Block a user