MCPcopy Create free account
hub / github.com/goadesign/goa / Files

Function Files

dsl/http_file_server.go:50–74  ·  view source on GitHub ↗

Files defines an endpoint that serves static assets via HTTP. The logic for what to do when the filename points to a file vs. a directory is the same as the standard http package ServeFile function. The path may end with a wildcard that matches the rest of the URL (e.g. {*filepath}). If it does the

(path, filename string, fns ...func())

Source from the content-addressed store, hash-verified

48// })
49// })
50func Files(path, filename string, fns ...func()) {
51 if len(fns) > 1 {
52 eval.TooManyArgError()
53 return
54 }
55 // Make sure request path starts with a "/" so codegen can rely on it.
56 if !strings.HasPrefix(path, "/") {
57 path = "/" + path
58 }
59 s, ok := eval.Current().(*expr.ServiceExpr)
60 if !ok {
61 eval.IncompatibleDSL()
62 return
63 }
64 r := expr.Root.API.HTTP.ServiceFor(s, expr.Root.API.HTTP)
65 server := &expr.HTTPFileServerExpr{
66 Service: r,
67 RequestPaths: []string{path},
68 FilePath: filename,
69 }
70 if len(fns) > 0 {
71 eval.Execute(fns[0], server)
72 }
73 r.FileServers = append(r.FileServers, server)
74}

Callers 2

TestTooManyArgErrorFunction · 0.50

Calls 5

TooManyArgErrorFunction · 0.92
CurrentFunction · 0.92
IncompatibleDSLFunction · 0.92
ExecuteFunction · 0.92
ServiceForMethod · 0.45

Tested by 1

TestTooManyArgErrorFunction · 0.40