当前位置: 首页>>代码示例>>Golang>>正文


Golang Request.Respond方法代码示例

本文整理汇总了Golang中vendor/github.com/garyburd/twister/web.Request.Respond方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.Respond方法的具体用法?Golang Request.Respond怎么用?Golang Request.Respond使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vendor/github.com/garyburd/twister/web.Request的用法示例。


在下文中一共展示了Request.Respond方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: feedHandler

func feedHandler(req *web.Request) {
	if !feedburner.Match([]byte(req.Header.Get(web.HeaderUserAgent))) {
		// Not Feedburner
		if "" == req.Param.Get("no_fb") {
			// And nothing saying to ignore
			req.Respond(web.StatusMovedPermanently, web.HeaderLocation, feedburnerUrl)
			return
		}
	}

	posts, err := posts.FindLatest(10)
	if err != nil {
		logger.Printf("failed getting posts for feed: %s", err)
		serverError(req, err)
	} else {
		w := req.Respond(web.StatusOK, web.HeaderContentType, "application/rss+xml; charset=utf-8")
		view.RenderPartial(w, "feed.tmpl", &view.RenderInfo{
			Post:            posts,
			SiteTitle:       config.SiteTitle,
			SiteDescription: config.SiteDescription,
			SiteContact:     config.SiteContact,
			SiteAuthor:      config.SiteAuthor,
		})
	}
}
开发者ID:darkhelmet,项目名称:verboselogging,代码行数:25,代码来源:handlers.go

示例2: permalinkHandler

func permalinkHandler(req *web.Request) {
	slug := req.URLParam["slug"]
	year, month, day := req.URLParam["year"], req.URLParam["month"], req.URLParam["day"]
	y, _ := strconv.Atoi(year)
	m, _ := strconv.Atoi(month)
	d, _ := strconv.Atoi(day)
	post, err := posts.FindByPermalink(y, time.Month(m), d, slug)
	if err != nil {
		switch err.(type) {
		case errors.NotFound:
			notFound(req)
		default:
			logger.Printf("failed finding post with year(%#v) month(%#v) day(%#v) slug(%#v): %s (%T)", year, month, day, slug, err, err)
			serverError(req, err)
		}
	} else {
		w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8")
		view.RenderLayout(w, &view.RenderInfo{
			Post:        post,
			Title:       post.Title,
			Canonical:   view.PostCanonical(post),
			Description: post.Description,
		})
	}
}
开发者ID:darkhelmet,项目名称:verboselogging,代码行数:25,代码来源:handlers.go

示例3: notFound

func notFound(req *web.Request) {
	w := req.Respond(web.StatusNotFound, web.HeaderContentType, "text/html; charset=utf-8")
	view.RenderLayout(w, &view.RenderInfo{
		NotFound: true,
		Title:    "Not Found",
	})
}
开发者ID:darkhelmet,项目名称:verboselogging,代码行数:7,代码来源:handlers.go

示例4: serverError

func serverError(req *web.Request, err error) {
	w := req.Respond(web.StatusInternalServerError, web.HeaderContentType, "text/html; charset=utf-8")
	view.RenderLayout(w, &view.RenderInfo{
		Error: true,
		Title: "Oh. Sorry about that.",
	})
}
开发者ID:darkhelmet,项目名称:verboselogging,代码行数:7,代码来源:handlers.go

示例5: sitemapHandler

func sitemapHandler(req *web.Request) {
	posts, err := posts.FindLatest(posts.Len())
	if err != nil {
		logger.Printf("failed getting posts for sitemap: %s", err)
		serverError(req, err)
	} else {
		w := req.Respond(web.StatusOK, web.HeaderContentType, "application/xml; charset=utf-8")
		view.RenderPartial(w, "sitemap.tmpl", &view.RenderInfo{Post: posts})
	}
}
开发者ID:darkhelmet,项目名称:verboselogging,代码行数:10,代码来源:handlers.go

示例6: rootHandler

func rootHandler(req *web.Request) {
	posts, err := posts.FindLatest(6)
	if err != nil {
		logger.Printf("failed finding latest posts: %s", err)
		serverError(req, err)
	} else {
		w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8")
		view.RenderLayout(w, &view.RenderInfo{
			PostPreview:  posts,
			Canonical:    "/",
			ArchiveLinks: true,
			Description:  config.SiteDescription,
		})
	}
}
开发者ID:darkhelmet,项目名称:verboselogging,代码行数:15,代码来源:handlers.go

示例7: searchHandler

func searchHandler(req *web.Request) {
	query := req.Param.Get("query")
	posts, err := posts.Search(query)
	if err != nil {
		logger.Printf("failed finding posts with query %#v: %s", query, err)
		serverError(req, err)
	} else {
		w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8")
		title := fmt.Sprintf("Search results for %#v", query)
		view.RenderLayout(w, &view.RenderInfo{
			PostPreview:  posts,
			Title:        title,
			PageTitle:    title,
			ArchiveLinks: true,
		})
	}
}
开发者ID:darkhelmet,项目名称:verboselogging,代码行数:17,代码来源:handlers.go

示例8: fullArchiveHandler

func fullArchiveHandler(req *web.Request) {
	posts, err := posts.FindLatest(posts.Len())
	if err != nil {
		logger.Printf("failed getting posts for full archive: %s", err)
		serverError(req, err)
	} else {
		w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8")
		title := "Full archives"
		view.RenderLayout(w, &view.RenderInfo{
			FullArchive:  posts,
			Description:  title,
			Title:        title,
			ArchiveLinks: true,
			Canonical:    req.URL.Path,
		})
	}
}
开发者ID:darkhelmet,项目名称:verboselogging,代码行数:17,代码来源:handlers.go

示例9: tagHandler

func tagHandler(req *web.Request) {
	tag := req.URLParam["tag"]
	posts, err := posts.FindByTag(tag)
	if err != nil {
		logger.Printf("failed finding posts with tag %#v: %s", tag, err)
		serverError(req, err)
	} else {
		w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8")
		title := fmt.Sprintf("Articles tagged with %#v", tag)
		view.RenderLayout(w, &view.RenderInfo{
			PostPreview: posts,
			Title:       title,
			PageTitle:   title,
			Canonical:   req.URL.Path,
			Description: fmt.Sprintf("Articles with the %#v tag", tag),
		})
	}
}
开发者ID:darkhelmet,项目名称:verboselogging,代码行数:18,代码来源:handlers.go

示例10: categoryHandler

func categoryHandler(req *web.Request) {
	category := req.URLParam["category"]
	posts, err := posts.FindByCategory(category)
	if err != nil {
		logger.Printf("failed finding posts with category %#v: %s", category, err)
		serverError(req, err)
	} else {
		w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8")
		category = strings.Title(category)
		title := fmt.Sprintf("%s Articles", category)
		view.RenderLayout(w, &view.RenderInfo{
			PostPreview: posts,
			Title:       title,
			PageTitle:   title,
			Canonical:   req.URL.Path,
			Description: fmt.Sprintf("Articles in the %s category", category),
		})
	}
}
开发者ID:darkhelmet,项目名称:verboselogging,代码行数:19,代码来源:handlers.go

示例11: monthlyHandler

func monthlyHandler(req *web.Request) {
	year, month := req.URLParam["year"], req.URLParam["month"]
	y, _ := strconv.Atoi(year)
	m, _ := strconv.Atoi(month)
	posts, err := posts.FindByMonth(y, time.Month(m))
	if err != nil {
		logger.Printf("failed finding posts in month %#v of %#v: %s", month, year, err)
		serverError(req, err)
	} else {
		w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8")
		title := fmt.Sprintf("Archives for %s-%s", month, year)
		view.RenderLayout(w, &view.RenderInfo{
			PostPreview:  posts,
			Title:        title,
			Canonical:    req.URL.Path,
			ArchiveLinks: true,
			Description:  title,
		})
	}
}
开发者ID:darkhelmet,项目名称:verboselogging,代码行数:20,代码来源:handlers.go

示例12: pageHandler

func pageHandler(req *web.Request) {
	slug := req.URLParam["slug"]
	page, err := pages.FindBySlug(slug)
	if err != nil {
		switch err.(type) {
		case errors.NotFound:
			notFound(req)
		default:
			logger.Printf("failed finding page with slug %#v: %s (%T)", slug, err, err)
			serverError(req, err)
		}
	} else {
		w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8")
		view.RenderLayout(w, &view.RenderInfo{
			Page:        page,
			Title:       page.Title,
			Canonical:   view.PageCanonical(page),
			Description: page.Description,
		})
	}
}
开发者ID:darkhelmet,项目名称:verboselogging,代码行数:21,代码来源:handlers.go

示例13: categoryArchiveHandler

func categoryArchiveHandler(req *web.Request) {
	posts, err := posts.FindLatest(posts.Len())
	if err != nil {
		logger.Printf("failed getting posts for category archive: %s", err)
		serverError(req, err)
	} else {
		grouped := make(map[string][]*post.Post)
		for _, post := range posts {
			key := post.Category
			grouped[key] = append(grouped[key], post)
		}

		w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8")
		view.RenderLayout(w, &view.RenderInfo{
			CategoryArchive: grouped,
			Description:     "Archives by category",
			Title:           "Category archives",
			ArchiveLinks:    true,
			Canonical:       req.URL.Path,
		})
	}
}
开发者ID:darkhelmet,项目名称:verboselogging,代码行数:22,代码来源:handlers.go

示例14: monthlyArchiveHandler

func monthlyArchiveHandler(req *web.Request) {
	posts, err := posts.FindLatest(posts.Len())
	if err != nil {
		logger.Printf("failed getting posts for monthly archive: %s", err)
		serverError(req, err)
	} else {
		grouped := make(map[int64][]*post.Post)
		for _, post := range posts {
			t := post.PublishedOn
			key := -time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, time.Local).Unix()
			grouped[key] = append(grouped[key], post)
		}

		w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8")
		view.RenderLayout(w, &view.RenderInfo{
			MonthlyArchive: grouped,
			Description:    "Archives by month",
			Title:          "Monthly archives",
			ArchiveLinks:   true,
			Canonical:      req.URL.Path,
		})
	}
}
开发者ID:darkhelmet,项目名称:verboselogging,代码行数:23,代码来源:handlers.go

示例15: opensearchHandler

func opensearchHandler(req *web.Request) {
	w := req.Respond(web.StatusOK, web.HeaderContentType, "application/xml; charset=utf-8")
	view.RenderPartial(w, "opensearch.tmpl", nil)
}
开发者ID:darkhelmet,项目名称:verboselogging,代码行数:4,代码来源:handlers.go


注:本文中的vendor/github.com/garyburd/twister/web.Request.Respond方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。