/
utils.go
29 lines (25 loc) · 852 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package rest
import (
"github.com/gorilla/mux"
"net/http"
)
// Get returns a named route.
// You can name a Route by calling Name(name string) against the route returned
// by either Handle or HandleFunc
func (s *Server) Get(name string) *mux.Route {
return s.router.Get(name)
}
// Get returns a named route.
// You can name a Route by calling Name(name string) against the route returned
// by either Handle or HandleFunc
func (c *ServerContext) Get(name string) *mux.Route {
return c.server.Get(name)
}
// Static adds a static file service at a specific prefix.
// prefix is the prefix to serve from, e.g. "/static/"
// dir is the directory to serve static content from
func (s *Server) Static(prefix, dir string) {
fileServer := http.FileServer(http.Dir(dir))
s.router.PathPrefix(prefix).
Handler(http.StripPrefix(prefix, fileServer))
}