MCPcopy Create free account
hub / github.com/perkeep/perkeep / makeClosureHandler

Function makeClosureHandler

pkg/server/ui.go:340–358  ·  view source on GitHub ↗

makeClosureHandler returns a handler to serve Closure files. root is either: 1. empty: use the Closure files compiled in to the binary (if available), else redirect to the Internet. 2. a URL prefix: base of Perkeep to get Closure to redirect to 3. a path on disk to the root of camlistore's source (w

(root, handlerName string)

Source from the content-addressed store, hash-verified

338// 3. a path on disk to the root of camlistore's source (which
339// contains the necessary subset of Closure files)
340func makeClosureHandler(root, handlerName string) (http.Handler, error) {
341 // devcam server environment variable takes precedence:
342 if d := os.Getenv("CAMLI_DEV_CLOSURE_DIR"); d != "" {
343 log.Printf("%v: serving Closure from devcam server's $CAMLI_DEV_CLOSURE_DIR: %v", handlerName, d)
344 return http.FileServer(http.Dir(d)), nil
345 }
346 if root == "" {
347 fs := closurestatic.Closure
348 log.Printf("%v: serving Closure from embedded resources", handlerName)
349 return http.FileServer(http.FS(fs)), nil
350 }
351 if strings.HasPrefix(root, "http") {
352 log.Printf("%v: serving Closure using redirects to %v", handlerName, root)
353 return closureRedirector(root), nil
354 }
355
356 path := filepath.Join(vendorEmbed, "closure", "lib", "closure")
357 return makeFileServer(root, path, filepath.Join("goog", "base.js"))
358}
359
360func makeFileServer(sourceRoot string, pathToServe string, expectedContentPath string) (http.Handler, error) {
361 fi, err := os.Stat(sourceRoot)

Callers 1

makeClosureHandlerMethod · 0.85

Calls 4

closureRedirectorTypeAlias · 0.85
makeFileServerFunction · 0.85
PrintfMethod · 0.80
HasPrefixMethod · 0.80

Tested by

no test coverage detected