本文整理匯總了Golang中github.com/codegangsta/martini.ClassicMartini類的典型用法代碼示例。如果您正苦於以下問題:Golang ClassicMartini類的具體用法?Golang ClassicMartini怎麽用?Golang ClassicMartini使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ClassicMartini類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RouteReminders
func RouteReminders(m *martini.ClassicMartini, model models.Api) {
m.Get("/api/reminders", model.Authenticated, model.GetAllReminders)
m.Get("/reminders/:id", model.GetReminder)
m.Post("/reminders", model.PostReminder)
m.Put("/reminders/:id", model.PutReminder)
m.Delete("/reminders/:id", model.DeleteReminder)
}
示例2: AdministationHandlers
func AdministationHandlers(m *martini.ClassicMartini) {
log.Println("Initializing Administration pages.")
m.Get("/admin", adminIndexHandler)
// accounts.
m.Post("/api/admin/account", binding.Bind(UserModel{}), adminNewAccount)
}
示例3: setupTemplate
func setupTemplate(m *martini.ClassicMartini, t Template) {
handler := func(r render.Render, req *http.Request, s ServerList) {
handleTemplate(r, req, t, s)
}
for _, name := range t.Handlers {
m.Get("/"+name, handler)
}
}
示例4: configuration
/**
* Martini application configuration.
*/
func configuration(app *martini.ClassicMartini) {
app.Use(martini.Static("public"))
app.Use(render.Renderer(render.Options{
Directory: "templets",
Layout: "layout",
Extensions: []string{".tmpl", ".html"},
Charset: "UTF-8",
IndentJSON: true,
}))
}
示例5: Signup
func Signup(m *martini.ClassicMartini) {
m.Get("/signup", func(r render.Render) {
r.HTML(200, "signup", nil)
})
m.Post("/signup", binding.Bind(UserPost{}), func(userpost UserPost) string {
// This function won't execute if there were errors
if InsertUser(userpost) {
//http.Redirect(w, r, "/profile", http.StatusFound)
//return userpost.UName
s := "<html>"
s += userpost.UName
s += `,恭喜你注冊成功,請 <a href="/signin">登錄</a></html>`
return s
//return `"<html>恭喜你", userpost.UName, "通過驗證,請 <a href="/signin">登錄</a></html>"`
} else {
return "insert DB failed"
}
})
}
示例6: Signin
func Signin(m *martini.ClassicMartini) {
m.Get("/signin", func(r render.Render) {
r.HTML(200, "signin", nil)
})
m.Post("/signin", func(session sessions.Session) {
fmt.Println("session set..")
session.Set("hello", "world")
// return "OK"
})
m.Post("/signin", binding.Bind(UserSignin{}), func(usersingin UserSignin) string {
// This function won't execute if there were errors
if userpost, err := QueryUser(usersingin); err != false {
//http.Redirect(w, r, "/profile", http.StatusFound)
//return userpost.UName
s := "<html>"
s += userpost.UName
s += `,恭喜你通過驗證,請 <a href="/">回首頁</a></html>`
//sessions.Session.Set(userpost.UEmail, userpost.UName)
//sessions.Session.("hello", "world")
fmt.Println(s)
//martini.Context.Next()
return s
} else {
return "query DB failed"
}
})
}
示例7: AccountHandlers
func AccountHandlers(m *martini.ClassicMartini) {
m.Use(BearerTokenValidation)
m.Get("/account", func(r render.Render) {
r.HTML(200, "account/login", nil)
})
// Authenticate user
m.Post("/account", binding.Bind(LoginUserModel{}), func(user LoginUserModel, r *http.Request, render render.Render) {
log.Println("user", user.Username)
log.Println("pass", user.Password)
if user.Username == ValidUser && user.Password == ValidPass {
// Create JWT token
token := jwt.New(jwt.GetSigningMethod("HS256"))
token.Claims["username"] = user.Username
// Expire in 5 mins
token.Claims["exp"] = time.Now().Add(time.Minute * 5).Unix()
tokenString, err := token.SignedString([]byte(SecretKey))
if err == nil {
data := map[string]string{"token": tokenString}
render.JSON(201, data)
return
}
r.Header.Add("Authorization", tokenString)
}
render.Redirect("/")
})
}
示例8: RegisterWebService
func RegisterWebService(webservice WebService, classicMartini *martini.ClassicMartini) {
classicMartini.Get("/:id", func(params martini.Params, req *http.Request) string {
fmt.Println(params)
fmt.Println(req.Header.Get("Content-Disposition"))
fmt.Println(req.URL.RawQuery)
return "Hello"
})
classicMartini.Post("/**", webservice.InitiateMultipartUpload)
classicMartini.Put("/**", webservice.UploadPart)
}
示例9: Register
func (ctrl FoodController) Register(m *martini.ClassicMartini) {
m.Get("/food", ctrl.Get)
m.Get("/food/:name", ctrl.GetOne)
m.Post("/food", ctrl.Create)
}
示例10: RouteAuth
func RouteAuth(m *martini.ClassicMartini, model models.Api) {
m.Get("/api/login", model.Login)
m.Get("/api/logout", model.Logout)
m.Get("/api/isauthenticated", model.Authenticated, model.IsAuthenticated)
}
示例11: Route
func Route(m *martini.ClassicMartini) {
m.Use(render.Renderer())
m.Get("/", func(r render.Render) {
r.HTML(200, "index", nil)
})
//post handlers
Signup(m)
Signin(m)
m.Get("/inspect", func() string {
return "Hello inspect!"
})
m.Get("/add", func() string {
return "Hello add!"
})
m.Post("/inspect", func() string {
return "Hello inspect!"
})
m.Post("/add", func() string {
return "Hello add!"
})
}
示例12: RegisterWebService
// RegisterWebService adds martini routes to the relevant webservice methods
// based on the path returned by GetPath. Each method is registered once for
// the collection and once for each id in the collection.
func RegisterWebService(webService WebService,
classicMartini *martini.ClassicMartini) {
path := webService.GetPath()
classicMartini.Get(path, webService.WebGet)
classicMartini.Get(path+"/:id", webService.WebGet)
classicMartini.Post(path, webService.WebPost)
classicMartini.Post(path+"/:id", webService.WebPost)
classicMartini.Delete(path, webService.WebDelete)
classicMartini.Delete(path+"/:id", webService.WebDelete)
}