本文整理汇总了Golang中github.com/unrolled/render.Render类的典型用法代码示例。如果您正苦于以下问题:Golang Render类的具体用法?Golang Render怎么用?Golang Render使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Render类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
}
开发者ID:XingLong9630,项目名称:DHUCourseSelection,代码行数:31,代码来源:WebAPI.go
示例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)
}
}
开发者ID:XingLong9630,项目名称:DHUCourseSelection,代码行数:33,代码来源:WebAPI.go
示例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
}
}
开发者ID:XingLong9630,项目名称:DHUCourseSelection,代码行数:25,代码来源:WebAPI.go
示例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)
}
}
开发者ID:XingLong9630,项目名称:DHUCourseSelection,代码行数:33,代码来源:WebAPI.go
示例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))
}
}
开发者ID:briandowns,项目名称:raceway,代码行数:8,代码来源:scenarios.go
示例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})
}
}
开发者ID:srhopkins,项目名称:aion,代码行数:26,代码来源:tasks.go
示例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)
}
}
开发者ID:XingLong9630,项目名称:DHUCourseSelection,代码行数:31,代码来源:WebAPI.go
示例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)
}
}
开发者ID:XingLong9630,项目名称:DHUCourseSelection,代码行数:31,代码来源:WebAPI.go
示例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")
}
}
开发者ID:cloudnativego,项目名称:web-application,代码行数:8,代码来源:handlers.go
示例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)
}
}
开发者ID:squishykid,项目名称:tarzan,代码行数:9,代码来源:main.go
示例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())
}
}
开发者ID:briandowns,项目名称:raceway,代码行数:11,代码来源:tasks.go
示例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()})
}
}
开发者ID:srhopkins,项目名称:aion,代码行数:11,代码来源:commands.go
示例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)
}
开发者ID:danackerson,项目名称:gotorrents,代码行数:11,代码来源:server.go
示例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})
}
}
开发者ID:cloudnativego,项目名称:vcap,代码行数:11,代码来源:server.go
示例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))
}
}
开发者ID:briandowns,项目名称:raceway,代码行数:13,代码来源:tasks.go
示例16: ListDownloadsHandler
// ListDownloadsHandler AJAX method is now commented
func ListDownloadsHandler(w http.ResponseWriter, req *http.Request, renderer *render.Render) {
dir := req.FormValue("dir")
if strings.HasPrefix(dir, "~") {
homedir := os.Getenv("HOME")
dir = homedir + dir[1:]
}
files := structures.PrepareDirectoryContents(dir)
renderer.HTML(w, http.StatusOK, "downloadDirectory", files)
}
开发者ID:danackerson,项目名称:gotorrents,代码行数:13,代码来源:server.go
示例17: addMoveHandler
func addMoveHandler(formatter *render.Render, repo matchRepository) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
matchID := vars["id"]
match, err := repo.getMatch(matchID)
if err != nil {
formatter.JSON(w, http.StatusNotFound, err.Error())
} else {
payload, _ := ioutil.ReadAll(req.Body)
var moveRequest newMoveRequest
err := json.Unmarshal(payload, &moveRequest)
newBoard, err := match.GameBoard.PerformMove(gogo.Move{Player: moveRequest.Player, Position: gogo.Coordinate{X: moveRequest.Position.X, Y: moveRequest.Position.Y}})
if err != nil {
formatter.JSON(w, http.StatusBadRequest, err.Error())
} else {
match.GameBoard = newBoard
err = repo.updateMatch(matchID, match)
if err != nil {
formatter.JSON(w, http.StatusInternalServerError, err.Error())
} else {
var mdr matchDetailsResponse
mdr.copyMatch(match)
formatter.JSON(w, http.StatusCreated, &mdr)
}
}
}
}
}
开发者ID:cloudnativego,项目名称:gogo-service,代码行数:28,代码来源:handlers.go
示例18: getMatchDetailsHandler
func getMatchDetailsHandler(formatter *render.Render, repo matchRepository) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
matchID := vars["id"]
match, err := repo.getMatch(matchID)
if err != nil {
formatter.JSON(w, http.StatusNotFound, err.Error())
} else {
var mdr matchDetailsResponse
mdr.copyMatch(match)
formatter.JSON(w, http.StatusOK, &mdr)
}
}
}
开发者ID:cloudnativego,项目名称:gogo-service,代码行数:14,代码来源:handlers.go
示例19: getMatchListHandler
func getMatchListHandler(formatter *render.Render, repo matchRepository) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
repoMatches, err := repo.getMatches()
if err == nil {
matches := make([]newMatchResponse, len(repoMatches))
for idx, match := range repoMatches {
matches[idx].copyMatch(match)
}
formatter.JSON(w, http.StatusOK, matches)
} else {
formatter.JSON(w, http.StatusNotFound, err.Error())
}
}
}
开发者ID:cloudnativego,项目名称:gogo-service,代码行数:14,代码来源:handlers.go
示例20: JobByIDRouteHandler
// JobByIDRouteHandler provides the handler for jobs data for the given ID
func JobByIDRouteHandler(ren *render.Render, conf *config.Config) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
jid := vars["id"]
jobID, err := strconv.Atoi(jid)
if err != nil {
log.Println(err)
ren.JSON(w, 400, map[string]error{"error": err})
return
}
db, err := database.NewDatabase(conf)
if err != nil {
log.Println(err)
ren.JSON(w, http.StatusOK, map[string]error{"error": err})
return
}
defer db.Conn.Close()
if t := db.GetJobByID(jobID); len(t) > 0 {
ren.JSON(w, http.StatusOK, map[string]interface{}{"task": t})
} else {
ren.JSON(w, http.StatusOK, map[string]interface{}{"task": ErrNoJobsFound.Error()})
}
}
}
开发者ID:srhopkins,项目名称:aion,代码行数:28,代码来源:jobs.go
注:本文中的github.com/unrolled/render.Render类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论