Moved closure-api into a new project

This commit is contained in:
2026-06-12 12:39:43 +08:00
parent c98fcfb640
commit d3072e7e18
14 changed files with 150 additions and 573 deletions
+1 -19
View File
@@ -1,8 +1,6 @@
package main
import (
"crypto/md5"
"encoding/hex"
"flag"
"log"
"net/http"
@@ -37,11 +35,6 @@ type handler struct {
closure *closure.CompileCache
}
func hashStrings(parts []string) string {
sum := md5.Sum([]byte(strings.Join(parts, "|")))
return hex.EncodeToString(sum[:])
}
func (h handler) index(w http.ResponseWriter, req *http.Request) {
path := strings.Trim(req.URL.Path, "/")
if path == "" {
@@ -76,24 +69,13 @@ func (h handler) index(w http.ResponseWriter, req *http.Request) {
}
if outMode == resolver.ModeJS {
fileHashes := make([]string, 0, len(res.JSFiles))
for _, f := range res.JSFiles {
fileHashes = append(fileHashes, f.JSHash)
}
hash := hashStrings(fileHashes)
if compiled, ok := h.closure.Get(hash); ok {
if compiled, ok := h.closure.Get(res.Hash); ok {
w.Header().Set("Content-Type", "application/javascript")
w.Header().Set("X-Botan-Compiled", "hit")
w.Write(compiled)
return
}
jsFiles := make([]string, 0, len(res.JSFiles))
for _, f := range res.JSFiles {
jsFiles = append(jsFiles, f.Src)
}
jsExterns, err := h.r.GetExterns(generated.Externs)
if err != nil {
http.Error(w, err.Error(), http.StatusNotFound)