MCPcopy Create free account
hub / github.com/devfeel/dotweb / RegisterServerFile

Method RegisterServerFile

router.go:420–452  ·  view source on GitHub ↗

RegisterServerFile register ServerFile router with routeMethod method on http.FileServer simple demo:server.RegisterServerFile(RouteMethod_GET, "/src/*", "/var/www", nil) simple demo:server.RegisterServerFile(RouteMethod_GET, "/src/*filepath", "/var/www", []string{".zip", ".rar"})

(routeMethod string, path string, fileRoot string, excludeExtension []string)

Source from the content-addressed store, hash-verified

418// simple demo:server.RegisterServerFile(RouteMethod_GET, "/src/*", "/var/www", nil)
419// simple demo:server.RegisterServerFile(RouteMethod_GET, "/src/*filepath", "/var/www", []string{".zip", ".rar"})
420func (r *router) RegisterServerFile(routeMethod string, path string, fileRoot string, excludeExtension []string) RouterNode {
421 realPath := r.server.VirtualPath() + path
422 node := &Node{}
423 if len(realPath) < 2 {
424 panic("path length must be greater than or equal to 2")
425 }
426 if realPath[len(realPath)-2:] == "/*" { // fixed for #125
427 realPath = realPath + "filepath"
428 }
429 if len(realPath) < 10 || realPath[len(realPath)-10:] != "/*filepath" {
430 panic("path must end with /*filepath or /* in path '" + realPath + "'")
431 }
432 var root http.FileSystem
433 root = http.Dir(fileRoot)
434 if !r.server.ServerConfig().EnabledListDir {
435 root = &core.HideReaddirFS{FileSystem: root}
436 }
437 fileServer := http.FileServer(root)
438 r.add(routeMethod, realPath, r.wrapFileHandle(fileServer, excludeExtension))
439 node = r.getNode(routeMethod, realPath)
440
441 if r.server.ServerConfig().EnabledAutoHEAD {
442 if !r.existsRouter(RouteMethod_HEAD, realPath) {
443 r.add(RouteMethod_HEAD, realPath, r.wrapFileHandle(fileServer, excludeExtension))
444 }
445 }
446 if r.server.ServerConfig().EnabledAutoOPTIONS {
447 if !r.existsRouter(RouteMethod_OPTIONS, realPath) {
448 r.add(RouteMethod_OPTIONS, realPath, r.wrapRouterHandle(DefaultAutoOPTIONSHandler, false))
449 }
450 }
451 return node
452}
453
454func handlerName(h HttpHandle) string {
455 t := reflect.ValueOf(h).Type()

Callers 1

ServerFileMethod · 0.95

Calls 7

addMethod · 0.95
wrapFileHandleMethod · 0.95
getNodeMethod · 0.95
existsRouterMethod · 0.95
wrapRouterHandleMethod · 0.95
VirtualPathMethod · 0.80
ServerConfigMethod · 0.80

Tested by

no test coverage detected