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)
| 338 | // 3. a path on disk to the root of camlistore's source (which |
| 339 | // contains the necessary subset of Closure files) |
| 340 | func 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 | |
| 360 | func makeFileServer(sourceRoot string, pathToServe string, expectedContentPath string) (http.Handler, error) { |
| 361 | fi, err := os.Stat(sourceRoot) |
no test coverage detected