本文整理匯總了Golang中github.com/firstrow/logvoyage/web/context.Context.HTML方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.HTML方法的具體用法?Golang Context.HTML怎麽用?Golang Context.HTML使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/firstrow/logvoyage/web/context.Context
的用法示例。
在下文中一共展示了Context.HTML方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Login
func Login(ctx *context.Context) {
message := ""
ctx.Request.ParseForm()
form := &loginForm{
EnableValidation: &common.EnableValidation{},
}
if ctx.Request.Method == "POST" {
form.Email = ctx.Request.Form.Get("email")
form.Password = ctx.Request.Form.Get("password")
form.SetupValidation()
if !form.EnableValidation.Valid.HasErrors() {
// find user
err := userExists(form)
if err != nil {
log.Println(err.Error())
message = "User not found or wrong password"
} else {
ctx.Session.Set("email", form.Email)
ctx.Render.Redirect("/")
}
}
}
ctx.HTML("users/login", context.ViewData{
"form": form,
"message": message,
})
}
示例2: Index
func Index(ctx *context.Context) {
ctx.Request.ParseForm()
form := &profileForm{
EnableValidation: &common.EnableValidation{},
FirstName: ctx.User.FirstName,
LastName: ctx.User.LastName,
}
if ctx.Request.Method == "POST" {
form.FirstName = ctx.Request.Form.Get("firstName")
form.LastName = ctx.Request.Form.Get("lastName")
form.SetupValidation()
if !form.EnableValidation.Valid.HasErrors() {
ctx.User.FirstName = form.FirstName
ctx.User.LastName = form.LastName
ctx.User.Save()
ctx.Session.AddFlash("Your data has been successfully saved.", "success")
ctx.Render.Redirect("/profile")
}
}
ctx.HTML("profile/index", context.ViewData{
"form": form,
})
}
示例3: Register
func Register(ctx *context.Context) {
ctx.Request.ParseForm()
form := ®isterForm{
EnableValidation: &common.EnableValidation{},
}
if ctx.Request.Method == "POST" {
form.Email = ctx.Request.Form.Get("email")
form.Password = ctx.Request.Form.Get("password")
form.SetupValidation()
if !form.EnableValidation.Valid.HasErrors() && form.IsValid() {
password, err := common.HashPassword(form.Password)
if err != nil {
panic(err.Error())
}
doc := goes.Document{
Index: "users",
Type: "user",
Fields: map[string]string{
"email": form.Email,
"password": password,
"apiKey": buildApiKey(form.Email),
},
}
extraArgs := make(url.Values, 0)
common.GetConnection().Index(doc, extraArgs)
ctx.Render.Redirect("/login")
}
}
ctx.HTML("users/register", context.ViewData{
"form": form,
})
}
示例4: update
func update(ctx *context.Context, form *projectForm) {
if ctx.Request.Method == "POST" {
form.Name = ctx.Request.Form.Get("name")
form.Description = ctx.Request.Form.Get("description")
form.Types = ctx.Request.PostForm["types"]
form.SetupValidation()
if !form.EnableValidation.Valid.HasErrors() {
group := &common.Project{
Id: form.Id,
Name: form.Name,
Description: form.Description,
Types: form.Types,
}
ctx.User.AddProject(group).Save()
ctx.Session.AddFlash("Project has been successfully saved.", "success")
ctx.Render.Redirect("/projects")
}
}
ctx.HTML("projects/new", context.ViewData{
"form": form,
})
}
示例5: ProjectSearch
// This function handles two routes "/" and "/project/:id"
func ProjectSearch(ctx *context.Context, params martini.Params) {
var types []string
var project *common.Project
query_text := ctx.Request.URL.Query().Get("q")
selected_types := ctx.Request.URL.Query()["types"]
// Project scope
if _, err := params["id"]; err {
project, err := ctx.User.GetProject(params["id"])
if err != nil {
ctx.HTML("shared/error", context.ViewData{
"message": "Project not found",
})
return
}
if len(project.Types) == 0 {
ctx.HTML("home/empty_project", context.ViewData{
"project": project,
})
return
}
if len(selected_types) > 0 {
types = selected_types
} else {
types = project.Types
}
}
// Pagination
pagination := widgets.NewPagination(ctx.Request)
pagination.SetPerPage(perPage)
// Load records
searchRequest := buildSearchRequest(
query_text,
[]string{ctx.User.GetIndexName()},
types,
pagination.GetPerPage(),
pagination.DetectFrom(),
buildTimeRange(ctx.Request),
)
// Search data in elastic
data, _ := search(searchRequest)
pagination.SetTotalRecords(data.Hits.Total)
var viewName string
viewData := context.ViewData{
"project": project,
"logs": data.Hits.Hits,
"total": data.Hits.Total,
"took": data.Took,
"types": types,
"time": ctx.Request.URL.Query().Get("time"),
"time_start": ctx.Request.URL.Query().Get("time_start"),
"time_stop": ctx.Request.URL.Query().Get("time_stop"),
"query_text": query_text,
"pagination": pagination,
}
if ctx.Request.Header.Get("X-Requested-With") == "XMLHttpRequest" {
viewName = "home/table"
} else {
viewName = "home/index"
}
ctx.HTML(viewName, viewData)
}
示例6: Types
// Display list of ES types available to user.
func Types(ctx *context.Context) {
ctx.HTML("projects/types", context.ViewData{
"docCounter": common.CountTypeDocs,
})
}
示例7: Index
func Index(ctx *context.Context) {
ctx.HTML("live/index", context.ViewData{}, "layouts/simple")
}
示例8: Index
func Index(ctx *context.Context) {
ctx.HTML("projects/index", context.ViewData{})
}