• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang traffic.ResponseWriter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/pilu/traffic.ResponseWriter的典型用法代码示例。如果您正苦于以下问题:Golang ResponseWriter类的具体用法?Golang ResponseWriter怎么用?Golang ResponseWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: RequireValidImageParameters

func RequireValidImageParameters(w traffic.ResponseWriter, r *traffic.Request) {

	width, err := strconv.Atoi(r.Param("width"))
	if err != nil {
		w.WriteHeader(http.StatusNotFound)
		return
	}

	height, err := strconv.Atoi(r.Param("height"))
	if err != nil {
		height = width
	}

	if (width <= 2560 && width > 0) && (height <= 2560 && height > 0) {

		w.SetVar("width", width)
		w.SetVar("height", height)

		// log latest greatest creation
		if err := ioutil.WriteFile(filepath.Join(cache_folder, "/latest"), []byte(fmt.Sprintf("%d/%d", width, height)), 0644); err != nil {
			// panic is trapped by Traffic and show us a nice stack trace in the browser
			// a proper error handling should be provided, but in this simple example
			// it's used to remind you to always check for errors
			panic(err)
		}

	} else {
		// bad request
		w.WriteHeader(http.StatusBadRequest)
		w.Render("400")
	}

}
开发者ID:jmptrader,项目名称:purrraceholder,代码行数:33,代码来源:image_handler.go


示例2: GenerateImageCache

func GenerateImageCache(w traffic.ResponseWriter, r *traffic.Request) {

	if !exists(cache_folder) {
		if err := os.Mkdir(cache_folder, 0644); err != nil {
			panic(err)
		}
	}

	filename := fmt.Sprintf("%s/%dx%d.jpg", cache_folder, w.GetVar("width"), w.GetVar("height"))
	w.SetVar("filename", filename)

	if !exists(filename) {
		// file does not exists, generate a cached version
		width := w.GetVar("width").(int)
		height := w.GetVar("height").(int)

		src_image := loadImageFromFile(image_file)
		pattern := resizeImage(src_image, width, height)

		var dst_image image.Image
		if width > height {
			dst_image = tileImageHorizontally(pattern, width, height)
		} else {
			dst_image = tileImageVertically(pattern, width, height)
		}

		saveImageToFile(filename, dst_image)
	}
}
开发者ID:jmptrader,项目名称:purrraceholder,代码行数:29,代码来源:image_handler.go


示例3: CheckReleaseFilter

func CheckReleaseFilter(w traffic.ResponseWriter, r *traffic.Request) {
	artistId := r.URL.Query().Get("artist_id")
	releaseId := r.URL.Query().Get("release_id")

	if releaseId == "" {
		return
	}

	if !models.IsValidUUID(releaseId) {
		w.WriteHeader(http.StatusBadRequest)
		return
	}

	if artistId != "" {
		if !models.IsValidUUID(artistId) {
			w.WriteHeader(http.StatusBadRequest)
			return
		}

		if artist.HasRelease(artistId, releaseId) {
			return
		}

		ReleaseNotFoundHandler(w, r)
		return
	}

	if !release.Exists(releaseId) {
		ReleaseNotFoundHandler(w, r)
		return
	}
}
开发者ID:pilu,项目名称:cerebellum,代码行数:32,代码来源:common_handlers.go


示例4: rootHandler

func rootHandler(w traffic.ResponseWriter, r *traffic.Request) {
	response := map[string]string{
		"version": VERSION,
	}
	w.Header().Set("Content-Type", "application/json")
	json.NewEncoder(w).Encode(response)
}
开发者ID:pilu,项目名称:stickerl,代码行数:7,代码来源:stickerl.go


示例5: RootHandler

func RootHandler(w traffic.ResponseWriter, r *traffic.Request) {
	last_image_generated, err := ioutil.ReadFile("cache/latest")

	if err != nil {
		responseData := &ResponseData{string(last_image_generated)}
		w.Render("index", responseData)
	}
}
开发者ID:jmptrader,项目名称:purrraceholder,代码行数:8,代码来源:root_handler.go


示例6: pageHandler

func pageHandler(w traffic.ResponseWriter, r *traffic.Request) {
	pagePath := r.Param("page_path")

	responseData := &ResponseData{
		PagePath: pagePath,
	}

	w.Render("index", responseData)
}
开发者ID:jmptrader,项目名称:traffic,代码行数:9,代码来源:main.go


示例7: CheckForDdosString

func CheckForDdosString(w traffic.ResponseWriter, r *traffic.Request) {
	for k, _ := range uriFragments {
		fmt.Printf("Searching for %s in %s", k, r.RequestURI)
		if strings.Contains(r.RequestURI, k) {
			fmt.Printf("Found %s", k)
			w.WriteHeader(http.StatusGatewayTimeout)
			w.WriteText("connection timed out")
		}
	}
}
开发者ID:dvwallin,项目名称:goddos,代码行数:10,代码来源:goddos.go


示例8: rootHandler

func rootHandler(w traffic.ResponseWriter, r *traffic.Request) {
	logger := w.GetVar("chromelogger").(*chromelogger.Logger)

	logger.Log("Hello")
	logger.Log(map[string]string{
		"foo": "bar",
	})

	w.WriteText("Hello, check your Chrome console after activating the Chrome Logger extension.\n")
}
开发者ID:pilu,项目名称:traffic-chromelogger,代码行数:10,代码来源:main.go


示例9: xmlTestHandler

func xmlTestHandler(w traffic.ResponseWriter, r *traffic.Request) {
	type Person struct {
		FirstName string `xml:"name>first"`
		LastName  string `xml:"name>last"`
	}

	w.WriteXML(&Person{
		FirstName: "foo",
		LastName:  "bar",
	})
}
开发者ID:jmptrader,项目名称:traffic,代码行数:11,代码来源:main.go


示例10: codesHandler

func codesHandler(w traffic.ResponseWriter, r *traffic.Request) {
	code := r.Param("code")
	url := fmt.Sprintf("%s%s", baseUrl, code)

	grid, err := qrencode.Encode(url, qrencode.ECLevelQ)
	if err != nil {
		panic(err)
	}

	w.Header().Set("Content-Type", "image/png")
	png.Encode(w, grid.Image(8))
}
开发者ID:pilu,项目名称:stickerl,代码行数:12,代码来源:stickerl.go


示例11: deleteHandler

func (api *ImgServerApi) deleteHandler(w traffic.ResponseWriter, r *traffic.Request) {

	filename := r.URL.Query().Get("image")
	err := api.imageDir.DeleteFile(filename)
	api.imageCache.Remove(api.imageCache.FindKeys(filename))

	if err != nil {
		traffic.Logger().Print(err.Error())
		w.WriteHeader(http.StatusNotFound)
	} else {
		w.WriteHeader(http.StatusOK)
	}
}
开发者ID:jhyle,项目名称:imgserver,代码行数:13,代码来源:api.go


示例12: ServeHTTP

// If the request path is "/ping", it writes PONG in the response and returns without calling the next middleware
// Otherwise it sets the variable "PING" with PONG as value and calls the next  middleware.
// The next middleware and the final handler can get that variable with:
//   w.GetVar("ping")
func (c *PingMiddleware) ServeHTTP(w traffic.ResponseWriter, r *traffic.Request, next traffic.NextMiddlewareFunc) {
	if r.URL.Path == "/ping" {
		w.WriteText("pong\n")

		return
	}

	if nextMiddleware := next(); nextMiddleware != nil {
		w.SetVar("ping", "pong")
		nextMiddleware.ServeHTTP(w, r, next)
	}

	return
}
开发者ID:jmptrader,项目名称:traffic,代码行数:18,代码来源:main.go


示例13: rootHandler

func rootHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.WriteText("%s<br />", w.GetVar("foo"))

	// run with TRAFFIC_ENV=production to get the "bar" value
	// from the production section of the config file
	w.WriteText("%s<br />", w.GetVar("bar"))
}
开发者ID:jmptrader,项目名称:traffic,代码行数:7,代码来源:main.go


示例14: ArtistHandler

func ArtistHandler(w traffic.ResponseWriter, r *traffic.Request) {
	id := r.URL.Query().Get("id")
	Artist, err := artist.ById(id)

	if err == nil {
		json.NewEncoder(w).Encode(Artist)
	} else if err == sql.ErrNoRows {
		ArtistNotFoundHandler(w, r)
	} else if _, ok := err.(models.InvalidUUID); ok {
		w.WriteHeader(http.StatusBadRequest)
	} else {
		panic(err)
	}
}
开发者ID:pilu,项目名称:cerebellum,代码行数:14,代码来源:artist_handler.go


示例15: ReleaseGroupsHandler

func ReleaseGroupsHandler(w traffic.ResponseWriter, r *traffic.Request) {
	artistId := r.URL.Query().Get("artist_id")

	ReleaseGroups, err := releasegroup.AllByArtistId(artistId)

	if err == nil {
		json.NewEncoder(w).Encode(ReleaseGroups)
	} else if err == sql.ErrNoRows {
		w.WriteHeader(http.StatusNotFound)
	} else if _, ok := err.(models.InvalidUUID); ok {
		w.WriteHeader(http.StatusBadRequest)
	} else {
		panic(err)
	}
}
开发者ID:pilu,项目名称:cerebellum,代码行数:15,代码来源:release_groups_handler.go


示例16: listHandler

func (api *ImgServerApi) listHandler(w traffic.ResponseWriter, r *traffic.Request) {

	age, err := strconv.Atoi(r.Param("age"))
	if err != nil {
		age = 0
	}

	files, err := api.imageDir.ListFiles(time.Duration(age) * time.Second)
	if err != nil {
		traffic.Logger().Print(err.Error())
		w.WriteHeader(http.StatusInternalServerError)
	} else {
		w.WriteJSON(files)
	}
}
开发者ID:jhyle,项目名称:imgserver,代码行数:15,代码来源:api.go


示例17: CheckArtistFilter

func CheckArtistFilter(w traffic.ResponseWriter, r *traffic.Request) {
	artistId := r.URL.Query().Get("artist_id")
	if artistId == "" {
		return
	}

	if !models.IsValidUUID(artistId) {
		w.WriteHeader(http.StatusBadRequest)
		return
	}

	if !artist.Exists(artistId) {
		ArtistNotFoundHandler(w, r)
		return
	}
}
开发者ID:pilu,项目名称:cerebellum,代码行数:16,代码来源:common_handlers.go


示例18: ServeHTTP

func (c *Middleware) ServeHTTP(w traffic.ResponseWriter, r *traffic.Request, next traffic.NextMiddlewareFunc) {
	ok := miniprofiler.Enable(r.Request)
	if ok && strings.HasPrefix(r.Request.URL.Path, miniprofiler.PATH) {
		miniprofiler.MiniProfilerHandler(w, r.Request)
		return
	}
	p := miniprofiler.NewProfile(w, r.Request, r.URL.Path)
	w.SetVar("miniprofiler", p.Includes())
	w.SetVar("miniprofiler_timer", p)
	if nextMiddleware := next(); nextMiddleware != nil {
		nextMiddleware.ServeHTTP(w, r, next)
	}
	if ok {
		p.Finalize()
	}
	return
}
开发者ID:jango2015,项目名称:go,代码行数:17,代码来源:miniprofiler_traffic.go


示例19: RecordingsHandler

func RecordingsHandler(w traffic.ResponseWriter, r *traffic.Request) {
	releaseId := r.URL.Query().Get("release_id")

	var recordings []*models.Recording
	var err error

	recordings, err = recording.AllByReleaseId(releaseId)

	if err == nil {
		json.NewEncoder(w).Encode(recordings)
	} else if err == sql.ErrNoRows {
		w.WriteHeader(http.StatusNotFound)
	} else if _, ok := err.(models.InvalidUUID); ok {
		w.WriteHeader(http.StatusBadRequest)
	} else {
		panic(err)
	}
}
开发者ID:pilu,项目名称:cerebellum,代码行数:18,代码来源:recordings_handler.go


示例20: RecordingHandler

func RecordingHandler(w traffic.ResponseWriter, r *traffic.Request) {
	releaseId := r.URL.Query().Get("release_id")
	id := r.URL.Query().Get("id")

	var Recording *models.Recording
	var err error

	if releaseId != "" {
		Recording, err = recording.ByReleaseIdAndId(releaseId, id)
	} else {
		Recording, err = recording.ById(id)
	}

	if err == nil {
		json.NewEncoder(w).Encode(Recording)
	} else if err == sql.ErrNoRows {
		RecordingNotFoundHandler(w, r)
	} else if _, ok := err.(models.InvalidUUID); ok {
		w.WriteHeader(http.StatusBadRequest)
	} else {
		panic(err)
	}
}
开发者ID:pilu,项目名称:cerebellum,代码行数:23,代码来源:recording_handler.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang check.C类代码示例发布时间:2022-05-28
下一篇:
Golang traffic.Request类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap