refactor(3p/gerrit-queue): use go:embed, bump go1.16, drop shell.nix
Previously, gerrit-queue used statik to embed files. Since go1.16, we have go:embed, which solves this much nicer, without any requirements to have the statik binary around. As the only other thing the shell.nix and .envrc plumbing did was bring a version of Go in scope, it's dropped now. We assume to have a recent-enough go binary around, else go will complain. Imported from https://github.com/flokli/gerrit-queue/pull/9 Change-Id: I851b06777a29d4f2d955cf3a7db6455a7189bc46 Reviewed-on: https://cl.tvl.fyi/c/depot/+/4329 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in> Autosubmit: tazjin <mail@tazj.in>
This commit is contained in:
parent
b68f7eebb9
commit
b3c4057f4b
10 changed files with 10 additions and 52 deletions
18
third_party/gerrit-queue/frontend/frontend.go
vendored
18
third_party/gerrit-queue/frontend/frontend.go
vendored
|
|
@ -1,36 +1,34 @@
|
|||
package frontend
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"encoding/json"
|
||||
|
||||
"html/template"
|
||||
|
||||
"github.com/rakyll/statik/fs"
|
||||
|
||||
"github.com/apex/log"
|
||||
|
||||
"github.com/tweag/gerrit-queue/gerrit"
|
||||
"github.com/tweag/gerrit-queue/misc"
|
||||
_ "github.com/tweag/gerrit-queue/statik" // register static assets
|
||||
"github.com/tweag/gerrit-queue/submitqueue"
|
||||
)
|
||||
|
||||
//loadTemplate loads a list of templates, relative to the statikFS root, and a FuncMap, and returns a template object
|
||||
//go:embed templates
|
||||
var templates embed.FS
|
||||
|
||||
//loadTemplate loads a list of templates, relative to the templates root, and a
|
||||
//FuncMap, and returns a template object
|
||||
func loadTemplate(templateNames []string, funcMap template.FuncMap) (*template.Template, error) {
|
||||
if len(templateNames) == 0 {
|
||||
return nil, fmt.Errorf("templateNames can't be empty")
|
||||
}
|
||||
tmpl := template.New(templateNames[0]).Funcs(funcMap)
|
||||
statikFS, err := fs.New()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, templateName := range templateNames {
|
||||
r, err := statikFS.Open("/" + templateName)
|
||||
r, err := templates.Open("/" + templateName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue