本文整理汇总了Golang中github.com/unrolled/render.Render类的典型用法代码示例。如果您正苦于以下问题:Golang Render类的具体用法?Golang Render怎么用?Golang Render使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Render类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CommonSelectFunc
func CommonSelectFunc(r *render.Render, store *sessions.CookieStore) ServePrimeFunc {
return func(w http.ResponseWriter, req *http.Request) {
id := req.PostFormValue("courseID")
_, school, ok := validateSession(req, store)
if ok {
if id == "" {
http.ServeFile(w, req, "DHUCourseChooseHTML/commonselect.html")
return
} else {
var done bool
var err error
var course CourseContent
DBsession := GetSession()
defer DBsession.Close()
cTable := DBsession.DB(school).C("CourseTable")
for i := 0; i < 3; i++ {
course, err = APICommonselect(cTable, id)
if err == nil {
done = true
break
}
}
if done {
r.JSON(w, http.StatusOK, course)
return
}
}
}
http.Redirect(w, req, "/errMessage", http.StatusMovedPermanently)
}
}
示例2: HomeSelectFunc
func HomeSelectFunc(r *render.Render, store *sessions.CookieStore) ServePrimeFunc {
return func(w http.ResponseWriter, req *http.Request) {
coursetype := req.PostFormValue("coursetype")
if ok := validateCourseType(coursetype); ok {
sessionid, school, ok := validateSession(req, store)
if ok {
var done bool
var err error
var teachSchemas []TeachSchema
DBsession := GetSession()
defer DBsession.Close()
for i := 0; i < 3; i++ {
cTable := DBsession.DB(school).C("CourseTable")
cIndex := DBsession.DB(school).C("CourseIndex")
teachSchemas, err = APIHomeSelect(cTable, cIndex, sessionid[:6], coursetype)
if err == nil {
done = true
break
} else {
fmt.Println(err)
}
}
if done {
r.JSON(w, http.StatusOK, map[string]([]TeachSchema){"TeachSchema": teachSchemas})
return
}
}
} else {
http.ServeFile(w, req, "DHUCourseChooseHTML/homeselect.html")
}
// http.Redirect(w,req,"/errMessage",http.StatusMovedPermanently)
}
}
示例3: HomeRegisterFunc
func HomeRegisterFunc(r *render.Render, store *sessions.CookieStore) ServePrimeFunc {
return func(w http.ResponseWriter, req *http.Request) {
var slist SelectLists
stuid, school, ok := validateSession(req, store)
if ok {
result, err := ioutil.ReadAll(req.Body)
if err == nil {
err = json.Unmarshal([]byte(result), &slist)
if err == nil {
DBsession := GetSession()
defer DBsession.Close()
cTable := DBsession.DB(school).C("CourseTable")
if ok := validateCourse(slist, cTable); ok {
courseInfo := saveAndRegister(stuid, school, slist)
r.JSON(w, http.StatusOK, courseInfo)
return
}
//Note:If the user post some illegal courses then we think it is a crawler or program
}
}
}
http.Redirect(w, req, "/errMessage", http.StatusMovedPermanently)
return
}
}
示例4: HomeFunc
func HomeFunc(r *render.Render, store *sessions.CookieStore) ServePrimeFunc {
return func(w http.ResponseWriter, req *http.Request) {
status := req.PostFormValue("userstatus")
if validateHomeStatus(status) {
stuid, school, ok := validateSession(req, store)
if ok {
if status == "" {
http.ServeFile(w, req, "DHUCourseChooseHTML/home.html")
return
} else {
var err error
var done bool
var courselist []RigisteredCourse
DBsession := GetSession()
defer DBsession.Close()
cRigister := DBsession.DB(school).C("RigisterInfo")
for i := 0; i < 3; i++ {
courselist, err = getrigisteredFunc(stuid, cRigister)
if err == nil {
done = true
break
}
}
if done {
r.JSON(w, http.StatusOK, map[string]([]RigisteredCourse){"RigisterCourse": courselist})
return
}
}
}
}
http.Redirect(w, req, "/errMessage", http.StatusMovedPermanently)
}
}
示例5: ScenariosByNameHandler
// ScenariosByNameHandler
func ScenariosByNameHandler(ren *render.Render, conf *config.Config) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
scenarioName := vars["name"]
ren.JSON(w, http.StatusOK, ScenarioContent(conf.Scenarios.ScenarioDir, scenarioName))
}
}
示例6: TaskDeleteByIDRouteHandler
// TaskDeleteByIDRouteHandler deletes the task data for the given ID
func TaskDeleteByIDRouteHandler(ren *render.Render, conf *config.Config, dispatch *dispatcher.Dispatcher) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
tid := vars["id"]
taskID, err := strconv.Atoi(tid)
if err != nil {
log.Println(err)
}
db, err := database.NewDatabase(conf)
if err != nil {
log.Println(err)
}
defer db.Conn.Close()
task := db.GetTaskByID(taskID)
if len(task) > 0 {
dispatch.RemoveTaskChan <- task[0]
db.DeleteTask(taskID)
} else {
ren.JSON(w, http.StatusOK, map[string]interface{}{"error": ErrNoEntryFound.Error()})
return
}
ren.JSON(w, http.StatusOK, map[string]interface{}{"task": taskID})
}
}
示例7: HomeDeleteFunc
func HomeDeleteFunc(r *render.Render, store *sessions.CookieStore) ServePrimeFunc {
return func(w http.ResponseWriter, req *http.Request) {
courseNo := req.PostFormValue("courseNo")
if courseNo == "" {
http.Redirect(w, req, "/errMessage", http.StatusMovedPermanently)
}
jsonstatus := map[string]bool{courseNo: false}
stuid, school, ok := validateSession(req, store)
if ok {
var stuInfo StudentRigisterCourse
DBsession := GetSession()
defer DBsession.Close()
cRigister := DBsession.DB(school).C("RigisterInfo")
err := cRigister.Find(bson.M{"studentid": stuid, "courselist": bson.M{"$elemMatch": bson.M{"courseno": courseNo, "coursestate": courseInQueue}}}).One(&stuInfo)
if err == nil {
conflict := true
//alterDatabase function use conflict(true) to set the course status from inqueue to deleted
for _, courseInfo := range stuInfo.CourseList {
if courseInfo.CourseNo == courseNo {
// fmt.Println(courseNo)
// fmt.Println(conflict)
alterDatabase(conflict, school, courseInfo.CourseID, courseNo, stuid, courseInfo.QueueNumber)
break
}
}
jsonstatus[courseNo] = true
}
}
r.JSON(w, http.StatusOK, jsonstatus)
}
}
示例8: LoginFunc
func LoginFunc(r *render.Render, store *sessions.CookieStore) ServePrimeFunc {
return func(w http.ResponseWriter, req *http.Request) {
loginJSON := map[string]int{"LoginStatus": networkErrStatus}
id := req.PostFormValue("UserID")
if id == "" {
http.ServeFile(w, req, "DHUCourseChooseHTML/login.html")
return
}
pw := req.PostFormValue("UserPassword")
//TODO It should be a form value that come from the user request
school := "DHU"
DBsession := GetSession()
defer DBsession.Close()
cLogin := DBsession.DB(school).C("StudentInfo")
name, err := validateLogin(id, pw, school, cLogin)
switch err {
case nil:
name = url.QueryEscape(name)
http.SetCookie(w, &http.Cookie{Name: "stuName", Value: name})
session, _ := store.Get(req, "sessionid")
session.Values["stuid"] = id
session.Values["school"] = school
session.Save(req, w)
loginJSON["LoginStatus"] = successStatus
case passwordErr:
loginJSON["LoginStatus"] = passwordErrStatus
}
r.JSON(w, http.StatusOK, loginJSON)
}
}
示例9: cookieWriteHandler
func cookieWriteHandler(formatter *render.Render) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
expiration := time.Now().Add(365 * 24 * time.Hour)
cookie := http.Cookie{Name: "sample", Value: "this is a cookie", Expires: expiration}
http.SetCookie(w, &cookie)
formatter.JSON(w, http.StatusOK, "cookie set")
}
}
示例10: MakeBuildListHandler
func MakeBuildListHandler(r *render.Render) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, req *http.Request) {
var (
buildList = []AutomatedBuild{}
)
r.JSON(w, http.StatusOK, buildList)
}
}
示例11: TasksRunningHandler
// TasksRunningHandler
func TasksRunningHandler(ren *render.Render, conf *config.Config) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
db, err := database.NewDatabase(conf)
if err != nil {
log.Fatalln(err)
return
}
ren.JSON(w, http.StatusOK, db.TasksRunning())
}
}
示例12: CommandsRouteHandler
// CommandsRouteHandler provides the handler for commands data
func CommandsRouteHandler(ren *render.Render, conf *config.Config) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
db, err := database.NewDatabase(conf)
if err != nil {
log.Println(err)
}
defer db.Conn.Close()
ren.JSON(w, http.StatusOK, map[string]interface{}{"commands": db.GetCommands()})
}
}
示例13: TorrentHandler
// TorrentHandler is now commented
func TorrentHandler(w http.ResponseWriter, req *http.Request, renderer *render.Render) {
searchString := req.FormValue("search")
log.Printf("Searching for %s", searchString)
torrents := make(map[int][]string)
torrents = SearchTorrentsFor(searchString, torrents)
// prepare response page
renderer.HTML(w, http.StatusOK, "content", torrents)
}
示例14: vcapHandler
func vcapHandler(formatter *render.Render, appEnv *cfenv.App) http.HandlerFunc {
val, err := cftools.GetVCAPServiceProperty("beer-service", "target-url", appEnv)
return func(w http.ResponseWriter, req *http.Request) {
if err != nil {
formatter.JSON(w, http.StatusInternalServerError, struct{ Error string }{err.Error()})
return
}
formatter.JSON(w, http.StatusOK, struct{ Foo string }{val})
}
}
示例15: TasksResultsByUUIDHandler
// TasksResultsByUUIDHandler
func TasksResultsByUUIDHandler(ren *render.Render, conf *config.Config) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
uuid := vars["task_uuid"]
db, err := database.NewDatabase(conf)
if err != nil {
log.Fatalln(err)
return
}
ren.JSON(w, http.StatusOK, db.TaskResultsByUUID(uuid))
}
}