1
0
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:
Tom Limoncelli
2021-06-04 15:50:47 -04:00
committed by GitHub
parent fdd6387aad
commit 1cea854e1c
10 changed files with 25 additions and 402 deletions

View File

@ -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 {