mirror of
https://github.com/genuinetools/reg.git
synced 2024-05-20 03:58:32 -04:00
start of generating assets
Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
This commit is contained in:
parent
2e3c2122d7
commit
695602b303
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -46,7 +46,6 @@ reg
|
|||
testreg
|
||||
.certs
|
||||
cross/
|
||||
internal/
|
||||
server/static/index.html
|
||||
server/static/repo/
|
||||
|
||||
|
|
27
internal/binutils/generate.go
Normal file
27
internal/binutils/generate.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/shurcooL/vfsgen"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func main() {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
assets := http.Dir(filepath.Join(wd, "server/static"))
|
||||
if err := vfsgen.Generate(assets, vfsgen.Options{
|
||||
Filename: filepath.Join(wd, "internal/binutils", "static.go"),
|
||||
PackageName: "binutils",
|
||||
VariableName: "Assets",
|
||||
}); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
277
internal/binutils/static.go
Normal file
277
internal/binutils/static.go
Normal file
File diff suppressed because one or more lines are too long
1
main.go
1
main.go
|
@ -30,6 +30,7 @@ var (
|
|||
debug bool
|
||||
)
|
||||
|
||||
//go:generate go run internal/binutils/generate.go
|
||||
func main() {
|
||||
// Create a new cli program.
|
||||
p := cli.NewProgram()
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/genuinetools/reg/clair"
|
||||
"github.com/genuinetools/reg/internal/binutils"
|
||||
"github.com/gorilla/mux"
|
||||
wordwrap "github.com/mitchellh/go-wordwrap"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
@ -95,7 +96,6 @@ func (cmd *serverCommand) Run(ctx context.Context, args []string) error {
|
|||
templateDir := filepath.Join(assetDir, "templates")
|
||||
// Make sure all the paths exist.
|
||||
tmplPaths := []string{
|
||||
staticDir,
|
||||
filepath.Join(templateDir, "vulns.html"),
|
||||
filepath.Join(templateDir, "repositories.html"),
|
||||
filepath.Join(templateDir, "tags.html"),
|
||||
|
@ -132,7 +132,7 @@ func (cmd *serverCommand) Run(ctx context.Context, args []string) error {
|
|||
},
|
||||
}
|
||||
|
||||
rc.tmpl = template.Must(template.New("").Funcs(funcMap).ParseGlob(templateDir + "/*.html"))
|
||||
rc.tmpl = template.Must(template.New("").Funcs(funcMap).Parse(templateDir + "/*.html"))
|
||||
|
||||
// Create the initial index.
|
||||
logrus.Info("creating initial static index")
|
||||
|
@ -176,7 +176,7 @@ func (cmd *serverCommand) Run(ctx context.Context, args []string) error {
|
|||
}
|
||||
|
||||
// Serve the static assets.
|
||||
staticHandler := http.FileServer(http.Dir(staticDir))
|
||||
staticHandler := http.FileServer(binutils.Assets)
|
||||
mux.PathPrefix("/static/").Handler(http.StripPrefix("/static/", staticHandler))
|
||||
mux.Handle("/", staticHandler)
|
||||
|
||||
|
|
Loading…
Reference in a new issue