本文整理匯總了Golang中github.com/go-martini/martini.Static函數的典型用法代碼示例。如果您正苦於以下問題:Golang Static函數的具體用法?Golang Static怎麽用?Golang Static使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Static函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: http
func http() {
server := martini.Classic()
server.Use(martini.Static("public", martini.StaticOptions{
Prefix: "public",
}))
server.Use(martini.Static("bower_components", martini.StaticOptions{
Prefix: "bower_components",
}))
server.Use(render.Renderer(render.Options{
Extensions: []string{".tmpl", ".html"},
Delims: render.Delims{"{[{", "}]}"},
}))
server.Get("/", func(r render.Render) {
r.HTML(200, "index", nil)
})
//
server.Get("/clients/:pid", func(params martini.Params, r render.Render) {
r.HTML(200, "index", params["pid"])
})
type jd map[string]interface{}
type ja []interface{}
// json api
server.Get("/api/clients", func(r render.Render) {
client_info := ja{}
for _, c := range compositors {
var surfaces []Surface
for _, s := range c.Surfaces {
surfaces = append(surfaces, *s)
}
client_info = append(client_info, jd{
"pid": c.Pid,
"ss": surfaces,
})
}
r.JSON(200, client_info)
})
// websocket api
server.Get("/api/clients", websocket.Handler(func(ws *websocket.Conn) {
}).ServeHTTP)
server.Get("/api/clients/:pid", websocket.Handler(func(ws *websocket.Conn) {
}).ServeHTTP)
server.Run()
}
示例2: main
func main() {
m := martini.Classic()
StaticOptions := martini.StaticOptions{Prefix: "public"}
m.Use(martini.Static("public", StaticOptions))
m.Use(martini.Static("public", StaticOptions))
m.Use(martini.Static("public", StaticOptions))
m.Use(martini.Static("public", StaticOptions))
m.Use(render.Renderer(render.Options{
Directory: "templates", // Specify what path to load the templates from.
Layout: "layout", // Specify a layout template. Layouts can call {{ yield }} to render the current template.
Extensions: []string{".tmpl"}, // Specify extensions to load for templates.
Charset: "UTF-8", // Sets encoding for json and html content-types. Default is "UTF-8".
}))
m.Get("/", IndexRouter)
m.Get("/about", AboutRoute)
m.Get("/contact", ContactRoute)
m.Get("/signin", SigninRoute)
m.Get("/signup", SignupRoute)
m.Run()
}
示例3: initHandlers
func (web *MailWeb) initHandlers() {
// Public Handlers
web.martini.Get("/", web.welcome)
web.martini.Post("/", binding.Bind(auth.WatneyUser{}), web.authenticate)
// Reserved for martini sessionauth forwarding, in case the session timed out
web.martini.Get("/sessionTimeout", web.timeout)
// Private Handlers
web.martini.Get("/logout", sessionauth.LoginRequired, web.logout)
web.martini.Get("/main", sessionauth.LoginRequired, web.main)
web.martini.Post("/mailContent", sessionauth.LoginRequired, web.mailContent)
web.martini.Post("/mails", sessionauth.LoginRequired, web.mails)
web.martini.Post("/poll", sessionauth.LoginRequired, web.poll)
web.martini.Post("/sendMail", sessionauth.LoginRequired, web.sendMail)
web.martini.Post("/moveMail", sessionauth.LoginRequired, web.moveMail)
web.martini.Post("/trashMail", sessionauth.LoginRequired, web.trashMail)
web.martini.Post("/updateFlags", sessionauth.LoginRequired, web.updateFlags)
web.martini.Post("/userInfo", sessionauth.LoginRequired, web.userInfo)
// Static content
web.martini.Use(martini.Static("static/resources/libs/",
martini.StaticOptions{Prefix: "/libs/"}))
web.martini.Use(martini.Static("static/resources/js/",
martini.StaticOptions{Prefix: "/js/"}))
web.martini.Use(martini.Static("static/resources/css/",
martini.StaticOptions{Prefix: "/css/"}))
}
示例4: ListenAndServe
// ListenAndServe start the server
func ListenAndServe(addr string, core core.Core, fe fs.FileExplorer) {
log.Infof("REST listening at: http://%v", core.GetAddr())
clientHandlers := clientAPI.NewHandler(core)
mesosHandlers := mesosAPI.NewHandler(core)
fsHandlers := fsAPI.NewHandler(fe)
r := createRouter(core, clientHandlers, mesosHandlers, fsHandlers)
m := martini.New()
m.Use(cors.Allow(&cors.Options{
AllowOrigins: []string{"*"},
AllowMethods: []string{"POST", "GET", "PUT", "DELETE"},
AllowHeaders: []string{"Origin", "x-requested-with", "Content-Type", "Content-Range", "Content-Disposition", "Content-Description"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: false,
}))
m.Use(logger())
m.Use(recovery())
m.Use(martini.Static("static"))
m.Use(martini.Static("temp", martini.StaticOptions{
Prefix: "/context/",
}))
m.Use(martini.Static("executor", martini.StaticOptions{
Prefix: "/executor/",
}))
m.Action(r.Handle)
go m.RunOnAddr(addr)
}
示例5: main
func main() {
martini.Env = martini.Prod
m := martini.Classic()
m.Use(martini.Static("../../admin/static/"))
m.Use(martini.Static(APP_STORE_DIR))
m.Use(sessions.Sessions("compass_session", sessions.NewCookieStore([]byte("compass_session_cookie"))))
m.Get("/", func(w http.ResponseWriter) string {
w.Header().Set("content-type", "text/html")
return SCRIPT_LOGIN
})
m.Get("/checkcode", func(r *http.Request, w http.ResponseWriter, s sessions.Session) {
code := captcha.NewLen(4)
s.Set("checkcode", code)
captcha.WriteImage(w, code, 110, 40)
})
showTemplate([]string{"footer", "form", "index", "left", "login", "main", "right", "top"}, m)
for actionName, actionHandler := range admin.ActionHandlers {
m.Post(fmt.Sprintf("/action/%s", actionName), actionHandler)
}
m.RunOnAddr(SERVER_ADDR)
}
示例6: configureAssets
func configureAssets(m *mart.ClassicMartini, analyticsConfig AnalyticsConfig, logger boshlog.Logger) {
assetsIDBytes, err := ioutil.ReadFile("./public/assets-id")
ensureNoErr(logger, "Failed to find assets ID", err)
assetsID := strings.TrimSpace(string(assetsIDBytes))
assetsFuncs := template.FuncMap{
"cssPath": func(fileName string) (string, error) {
return "/" + assetsID + "/stylesheets/" + fileName, nil
},
"jsPath": func(fileName string) (string, error) {
return "/" + assetsID + "/javascript/" + fileName, nil
},
"imgPath": func(fileName string) (string, error) {
return "/" + assetsID + "/images/" + fileName, nil
},
}
analyticsConfigFuncs := template.FuncMap{
"analyticsConfig": func() AnalyticsConfig {
return analyticsConfig
},
}
htmlFuncs := template.FuncMap{
"href": func(s string) template.HTMLAttr {
return template.HTMLAttr(fmt.Sprintf(" href='%s' ", s))
},
}
// Use prefix to cache bust images, stylesheets, and js
m.Use(mart.Static(
"./public",
mart.StaticOptions{
Prefix: assetsID,
},
))
// Make sure docs' images are available as `docs/images/X`
m.Use(mart.Static(
"./templates/docs/images",
mart.StaticOptions{
Prefix: "docs/images",
},
))
m.Use(martrend.Renderer(
martrend.Options{
Layout: "layout",
Directory: "./templates",
Extensions: []string{".tmpl", ".html"},
Funcs: []template.FuncMap{assetsFuncs, analyticsConfigFuncs, htmlFuncs},
},
))
}
示例7: main
func main() {
arguments := os.Args[1:]
port := arguments[0]
server := martini.Classic()
server.Use(martini.Static("../public"))
server.Use(martini.Static("../assets/javascript/app"))
server.Use(nocache.UpdateCacheHeaders())
fmt.Printf(" listening on port %s\n", port)
log.Fatal(http.ListenAndServe(":"+port, server))
}
示例8: configureServer
func configureServer(server *martini.Martini, router martini.Router) {
server.Use(martini.Recovery())
server.Use(middleware.Logger())
server.Use(martini.Static("templates/public", martini.StaticOptions{SkipLogging: true}))
server.Use(martini.Static("templates/images", martini.StaticOptions{Prefix: "images", SkipLogging: true}))
server.Use(martini.Static("templates/styles", martini.StaticOptions{Prefix: "styles", SkipLogging: true}))
server.Use(martini.Static("templates/scripts", martini.StaticOptions{Prefix: "scripts", SkipLogging: true}))
server.Use(render.Renderer(render.Options{
Layout: "layout",
}))
server.MapTo(router, (*martini.Routes)(nil))
server.Action(router.Handle)
}
示例9: Configure
func Configure(m *martini.ClassicMartini) {
m.Group("/humidity", func(r martini.Router) {
r.Post("", humidity.Post)
r.Get("", humidity.Get)
})
m.Get("/current/humidity", current_humidity.Get)
m.Group("/", func(r martini.Router) {
r.Get("", index.Get)
})
static := martini.Static("templates", martini.StaticOptions{Fallback: "/index.tmpl", Exclude: "/api/v"})
m.NotFound(static, http.NotFound)
m.Use(martini.Static("static"))
}
示例10: main
func main() {
m := martini.Classic()
conf := config.LoadConf(martini.Env)
//create new session middleware
store := sessions.NewCookieStore([]byte("MushareSecret"))
store.Options(sessions.Options{
Path: "/",
Domain: conf.App.Host,
MaxAge: 60 * 60 * 60 * 24,
HttpOnly: true,
})
//middleware
m.Handlers(
middlewares.LogOutput,
middlewares.Recovery(),
martini.Logger(),
sessions.Sessions("_session", store),
martini.Static("static", martini.StaticOptions{}),
middlewares.InjectRedis(),
middlewares.InjectDB(),
)
m.Map(conf)
//routers
router.Include(m)
//start server
m.RunOnAddr(conf.App.Host + ":" + conf.App.Port)
}
示例11: init
func init() {
m = martini.New()
// I could probably just use martini.Classic() instead of configure these manually
// Static files
m.Use(martini.Static(`public`))
// Setup middleware
m.Use(martini.Recovery())
m.Use(martini.Logger())
// m.Use(auth.Basic(AuthToken, ""))
m.Use(MapEncoder)
// Setup routes
r := martini.NewRouter()
r.Get(`/albums`, server.GetAlbums)
r.Get(`/albums/:id`, server.GetAlbum)
r.Post(`/albums`, server.AddAlbum)
r.Put(`/albums/:id`, server.UpdateAlbum)
r.Delete(`/albums/:id`, server.DeleteAlbum)
// Inject database
m.MapTo(server.DBInstance, (*server.DB)(nil))
// Add the router action
m.Action(r.Handle)
}
示例12: main
func main() {
m := martini.Classic()
store := sessions.NewCookieStore([]byte("secret-isucon"))
m.Use(sessions.Sessions("isucon_go_session", store))
m.Use(martini.Static("../public"))
m.Use(render.Renderer(render.Options{
Layout: "layout",
}))
m.Get("/", func(r render.Render, session sessions.Session) {
r.HTML(200, "index", map[string]string{"Flash": getFlash(session, "notice")})
})
m.Post("/login", func(req *http.Request, r render.Render, session sessions.Session) {
user, err := attemptLogin(req)
notice := ""
if err != nil || user == nil {
switch err {
case ErrBannedIP:
notice = "You're banned."
case ErrLockedUser:
notice = "This account is locked."
default:
notice = "Wrong username or password"
}
session.Set("notice", notice)
r.Redirect("/")
return
}
session.Set("user_id", strconv.Itoa(user.ID))
r.Redirect("/mypage")
})
m.Get("/mypage", func(r render.Render, session sessions.Session) {
currentUser := getCurrentUser(session.Get("user_id"))
if currentUser == nil {
session.Set("notice", "You must be logged in")
r.Redirect("/")
return
}
currentUser.getLastLogin()
r.HTML(200, "mypage", currentUser)
})
m.Get("/report", func(r render.Render) {
r.JSON(200, map[string][]string{
"banned_ips": bannedIPs(),
"locked_users": lockedUsers(),
})
})
http.ListenAndServe(":8080", m)
}
示例13: main
func main() {
m := martini.Classic()
op := martini.StaticOptions{Prefix: "/", SkipLogging: true, IndexFile: "", Expires: func() string { return "" }}
m.Use(martini.Static(".", op))
m.RunOnAddr(":4000")
}
示例14: StartManager
//初始化並啟動web服務
func StartManager(sl *schedule.ScheduleManager) { // {{{
g = sl.Global
m := martini.Classic()
m.Use(Logger)
m.Use(martini.Static("web/public"))
m.Use(web.ContextWithCookieSecret(""))
m.Use(render.Renderer(render.Options{
Directory: "web/templates", // Specify what path to load the templates from.
Extensions: []string{".tmpl", ".html"}, // Specify extensions to load for templates.
Delims: render.Delims{"{[{", "}]}"},
Charset: "UTF-8", // Sets encoding for json and html content-types. Default is "UTF-8".
IndentJSON: true, // Output human readable JSON
IndentXML: true, // Output human readable XML
HTMLContentType: "text/html", // Output XHTML content type instead of default "text/html"
}))
m.Map(sl)
controller(m)
g.L.Println("Web manager is running in ", g.ManagerPort)
err := http.ListenAndServe(g.ManagerPort, m)
if err != nil {
log.Fatal("Fail to start server: %v", err)
}
} // }}}
示例15: main
func main() {
fmt.Println("jøkulhlaup ", Version)
r := render.New(render.Options{})
m := martini.Classic()
fizz := fizz.New()
// Dashboard
m.Get("/", func(w http.ResponseWriter, req *http.Request) {
data := map[string]string{
"title": "Jøkulhlaup",
"imgsrc": "img/jøkulhlaup.png",
"width": "1440",
"height": "900",
}
// !! Reload template !!
//r = render.New(render.Options{})
// Render the specified templates/.tmpl file as HTML and return
r.HTML(w, http.StatusOK, "black", data)
})
// Activate the permission middleware
m.Use(fizz.All())
// Share the files in static
m.Use(martini.Static("static"))
m.Run() // port 3000 by default
}