Rejig embedded assets to a central folder

This commit is contained in:
Jamie Curnow
2021-06-30 10:50:55 +10:00
parent 4be9d4d509
commit 80a31b3041
71 changed files with 38 additions and 20 deletions

View File

@@ -3,10 +3,11 @@ package handler
import (
"encoding/json"
"fmt"
"io/fs"
"net/http"
"strings"
"npm/doc"
"npm/embed"
"npm/internal/api/schema"
"npm/internal/config"
"npm/internal/logger"
@@ -15,7 +16,10 @@ import (
"github.com/jc21/jsref/provider"
)
var swaggerSchema []byte
var (
swaggerSchema []byte
apiDocsSub fs.FS
)
// Schema simply reads the swagger schema from disk and returns is raw
// Route: GET /schema
@@ -29,8 +33,10 @@ func Schema() func(http.ResponseWriter, *http.Request) {
func getSchema() []byte {
if swaggerSchema == nil {
apiDocsSub, _ = fs.Sub(embed.APIDocFiles, "api_docs")
// nolint:gosec
swaggerSchema, _ = doc.SwaggerFiles.ReadFile("api.swagger.json")
swaggerSchema, _ = fs.ReadFile(apiDocsSub, "api.swagger.json")
// Replace {{VERSION}} with Config Version
swaggerSchema = []byte(strings.ReplaceAll(string(swaggerSchema), "{{VERSION}}", config.Version))
@@ -42,7 +48,7 @@ func getSchema() []byte {
return nil
}
provider := provider.NewIoFS(doc.SwaggerFiles, "")
provider := provider.NewIoFS(apiDocsSub, "")
resolver := jsref.New()
err := resolver.AddProvider(provider)
if err != nil {