Exemple #1
0
func show_log(session *http.Session) {
	session.Stash["Title"] = "websysd log"
	session.Stash["Page"] = "AppLog"
	session.Stash["LogOutput"] = applog.String()

	session.RenderWithLayout("applog.html", "layout.html", "Content")
}
Exemple #2
0
func list_workspaces(session *http.Session) {
	// Stash a value and render a template
	session.Stash["Title"] = "websysd"
	session.Stash["Page"] = "Workspaces"
	session.Stash["Workspaces"] = Workspaces
	session.RenderWithLayout("workspaces.html", "layout.html", "Content")
}
Exemple #3
0
func redir(session *http.Session) {
	redir := "/"

	if k := session.Request.Referer(); len(k) > 0 {
		redir = k
	}

	session.Redirect(&url.URL{Path: redir})
}
Exemple #4
0
func list_tasks(session *http.Session) {
	ws, _ := session.Stash["workspace"].(string)

	// Stash a value and render a template
	session.Stash["Title"] = "websysd"
	session.Stash["Page"] = "Tasks"
	session.Stash["Workspace"] = Workspaces[ws]
	session.Stash["Tasks"] = Workspaces[ws].Tasks
	session.RenderWithLayout("tasks.html", "layout.html", "Content")
}
Exemple #5
0
func taskHistory(session *http.Session) {
	ws, _ := session.Stash["workspace"].(string)
	id, _ := session.Stash["task"].(string)

	session.Stash["Title"] = "Task"
	session.Stash["Page"] = "History"
	session.Stash["Workspace"] = Workspaces[ws]
	session.Stash["Task"] = Workspaces[ws].Tasks[id]

	session.RenderWithLayout("task.html", "layout.html", "Content")
}
Exemple #6
0
func taskRun(session *http.Session) {
	ws, _ := session.Stash["workspace"].(string)
	id, _ := session.Stash["task"].(string)
	run, _ := strconv.Atoi(session.Stash["run"].(string))

	session.Stash["Title"] = "Task run"
	session.Stash["Page"] = "TaskRun"
	session.Stash["Workspace"] = Workspaces[ws]
	session.Stash["Task"] = Workspaces[ws].Tasks[id]
	session.Stash["TaskRun"] = Workspaces[ws].Tasks[id].TaskRuns[run]

	session.RenderWithLayout("taskrun.html", "layout.html", "Content")
}
Exemple #7
0
func taskRunStderr(session *http.Session) {
	ws, _ := session.Stash["workspace"].(string)
	id, _ := session.Stash["task"].(string)
	run, _ := strconv.Atoi(session.Stash["run"].(string))

	session.Stash["Title"] = "Task run stderr"
	session.Stash["Page"] = "TaskOutput"
	session.Stash["Type"] = "stderr"
	session.Stash["Workspace"] = Workspaces[ws]
	session.Stash["Task"] = Workspaces[ws].Tasks[id]
	session.Stash["TaskRun"] = Workspaces[ws].Tasks[id].TaskRuns[run]
	session.Stash["LogOutput"] = Workspaces[ws].Tasks[id].TaskRuns[run].StderrBuf.String()

	session.RenderWithLayout("log.html", "layout.html", "Content")
}
Exemple #8
0
func (h *Router) Serve(session *http.Session) {
	for _, route := range h.Routes {
		if matches := route.Route.Pattern.FindStringSubmatch(session.Request.URL.Path); len(matches) > 0 {
			_, ok := route.Route.Methods[session.Request.Method]
			if ok {
				for i, named := range route.Route.Pattern.SubexpNames() {
					if len(named) > 0 {
						log.Trace("Matched named pattern '%s': %s", named, matches[i])
						session.Stash[named] = matches[i]
					}
				}
				session.Route = route.Route
				defer func() {
					if e := recover(); e != nil {
						switch e.(type) {
						case string:
							session.RenderException(500, errors.New(e.(string)))
						default:
							session.RenderException(500, e.(error))
						}
						session.Response.Send()
						session.Response.Close()
					}
				}()
				var wg sync.WaitGroup
				wg.Add(1)
				// func() will be executed only if *all* event handlers call next()
				h.Config.Events.Emit(session, events.BeforeHandler, func() {
					route.Handler.ServeHTTP(session)
					h.Config.Events.Emit(session, events.AfterHandler, func() {
						session.Response.Send()
						session.Response.Close()
						wg.Done()
					})
				})
				wg.Wait()
				return
			}
		}
	}

	// no pattern matched; send 404 response
	h.Config.Events.Emit(session, events.BeforeHandler, func() {
		session.RenderNotFound()
		h.Config.Events.Emit(session, events.AfterHandler, func() {
			session.Response.Send()
		})
	})
}
Exemple #9
0
func example3(session *http.Session) {
	session.Redirect(&url.URL{Path: "/foo"})
}
Exemple #10
0
func example(session *http.Session) {
	// Stash a value and render a template
	session.Stash["Title"] = "Welcome to Gotcha"
	session.Render("index.html")
}