forked from Botanical/BotanJS
Moved closure-api into a new project
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user