當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Request.SetData方法代碼示例

本文整理匯總了Golang中github.com/hypertornado/prago.Request.SetData方法的典型用法代碼示例。如果您正苦於以下問題:Golang Request.SetData方法的具體用法?Golang Request.SetData怎麽用?Golang Request.SetData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/hypertornado/prago.Request的用法示例。


在下文中一共展示了Request.SetData方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: around

func (s *Sessions) around(request prago.Request, next func()) {

	if request.IsProcessed() {
		next()
		return
	}

	sessionName := s.app.Data()["appName"].(string)
	session, err := s.cookieStore.Get(request.Request(), sessionName)
	if err != nil {
		request.Log().Errorln("Session not valid")
		request.Response().Header().Set("Set-Cookie", sessionName+"=; expires=Thu, 01 Jan 1970 00:00:01 GMT;")
		panic(err)
	}

	flashes := session.Flashes()
	if len(flashes) > 0 {
		request.SetData("flash_messages", flashes)
		prago.Must(session.Save(request.Request(), request.Response()))
	}

	request.SetData("session", session)
	next()
}
開發者ID:hypertornado,項目名稱:prago,代碼行數:24,代碼來源:sessions.go

示例2: stats

func stats(request prago.Request) {
	if !AuthenticateSysadmin(GetUser(request)) {
		render403(request)
		return
	}

	stats := [][2]string{}

	stats = append(stats, [2]string{"App name", request.App().Data()["appName"].(string)})
	stats = append(stats, [2]string{"App version", request.App().Data()["version"].(string)})

	port := request.App().Data()["port"].(int)
	stats = append(stats, [2]string{"Port", fmt.Sprintf("%d", port)})

	developmentModeStr := "false"
	if request.App().DevelopmentMode {
		developmentModeStr = "true"
	}
	stats = append(stats, [2]string{"Development mode", developmentModeStr})
	stats = append(stats, [2]string{"Started at", request.App().StartedAt.Format(time.RFC3339)})

	stats = append(stats, [2]string{"Go version", runtime.Version()})
	stats = append(stats, [2]string{"Compiler", runtime.Compiler})
	stats = append(stats, [2]string{"GOARCH", runtime.GOARCH})
	stats = append(stats, [2]string{"GOOS", runtime.GOOS})
	stats = append(stats, [2]string{"GOMAXPROCS", fmt.Sprintf("%d", runtime.GOMAXPROCS(-1))})

	configStats := request.App().Config.Export()

	osStats := [][2]string{}
	osStats = append(osStats, [2]string{"EGID", fmt.Sprintf("%d", os.Getegid())})
	osStats = append(osStats, [2]string{"EUID", fmt.Sprintf("%d", os.Geteuid())})
	osStats = append(osStats, [2]string{"GID", fmt.Sprintf("%d", os.Getgid())})
	osStats = append(osStats, [2]string{"Page size", fmt.Sprintf("%d", os.Getpagesize())})
	osStats = append(osStats, [2]string{"PID", fmt.Sprintf("%d", os.Getpid())})
	osStats = append(osStats, [2]string{"PPID", fmt.Sprintf("%d", os.Getppid())})
	wd, _ := os.Getwd()
	osStats = append(osStats, [2]string{"Working directory", wd})
	hostname, _ := os.Hostname()
	osStats = append(osStats, [2]string{"Hostname", hostname})

	var mStats runtime.MemStats
	runtime.ReadMemStats(&mStats)
	memStats := [][2]string{}
	memStats = append(memStats, [2]string{"Alloc", fmt.Sprintf("%d", mStats.Alloc)})
	memStats = append(memStats, [2]string{"TotalAlloc", fmt.Sprintf("%d", mStats.TotalAlloc)})
	memStats = append(memStats, [2]string{"Sys", fmt.Sprintf("%d", mStats.Sys)})
	memStats = append(memStats, [2]string{"Lookups", fmt.Sprintf("%d", mStats.Lookups)})
	memStats = append(memStats, [2]string{"Mallocs", fmt.Sprintf("%d", mStats.Mallocs)})
	memStats = append(memStats, [2]string{"Frees", fmt.Sprintf("%d", mStats.Frees)})
	memStats = append(memStats, [2]string{"HeapAlloc", fmt.Sprintf("%d", mStats.HeapAlloc)})
	memStats = append(memStats, [2]string{"HeapSys", fmt.Sprintf("%d", mStats.HeapSys)})
	memStats = append(memStats, [2]string{"HeapIdle", fmt.Sprintf("%d", mStats.HeapIdle)})
	memStats = append(memStats, [2]string{"HeapInuse", fmt.Sprintf("%d", mStats.HeapInuse)})
	memStats = append(memStats, [2]string{"HeapReleased", fmt.Sprintf("%d", mStats.HeapReleased)})
	memStats = append(memStats, [2]string{"HeapObjects", fmt.Sprintf("%d", mStats.HeapObjects)})
	memStats = append(memStats, [2]string{"StackInuse", fmt.Sprintf("%d", mStats.StackInuse)})
	memStats = append(memStats, [2]string{"StackSys", fmt.Sprintf("%d", mStats.StackSys)})
	memStats = append(memStats, [2]string{"MSpanInuse", fmt.Sprintf("%d", mStats.MSpanInuse)})
	memStats = append(memStats, [2]string{"MSpanSys", fmt.Sprintf("%d", mStats.MSpanSys)})
	memStats = append(memStats, [2]string{"MCacheInuse", fmt.Sprintf("%d", mStats.MCacheInuse)})
	memStats = append(memStats, [2]string{"MCacheSys", fmt.Sprintf("%d", mStats.MCacheSys)})
	memStats = append(memStats, [2]string{"BuckHashSys", fmt.Sprintf("%d", mStats.BuckHashSys)})
	memStats = append(memStats, [2]string{"GCSys", fmt.Sprintf("%d", mStats.GCSys)})
	memStats = append(memStats, [2]string{"OtherSys", fmt.Sprintf("%d", mStats.OtherSys)})
	memStats = append(memStats, [2]string{"NextGC", fmt.Sprintf("%d", mStats.NextGC)})
	memStats = append(memStats, [2]string{"LastGC", fmt.Sprintf("%d", mStats.LastGC)})
	memStats = append(memStats, [2]string{"PauseTotalNs", fmt.Sprintf("%d", mStats.PauseTotalNs)})
	memStats = append(memStats, [2]string{"NumGC", fmt.Sprintf("%d", mStats.NumGC)})

	environmentStats := [][2]string{}
	for _, e := range os.Environ() {
		pair := strings.Split(e, "=")
		environmentStats = append(environmentStats, [2]string{pair[0], pair[1]})
	}

	request.SetData("stats", stats)
	request.SetData("configStats", configStats)
	request.SetData("osStats", osStats)
	request.SetData("memStats", memStats)
	request.SetData("environmentStats", environmentStats)
	request.SetData("admin_yield", "admin_stats")
	prago.Render(request, 200, "admin_layout")
}
開發者ID:hypertornado,項目名稱:prago,代碼行數:84,代碼來源:stats.go

示例3: render404

func render404(request prago.Request) {
	request.SetData("message", messages.Messages.Get(GetLocale(request), "admin_404"))
	request.SetData("admin_yield", "admin_message")
	prago.Render(request, 404, "admin_layout")
}
開發者ID:hypertornado,項目名稱:prago,代碼行數:5,代碼來源:admin.go


注:本文中的github.com/hypertornado/prago.Request.SetData方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。