2016-09-17 6 views
1

私はGolangが新しく、irisというフレームワークを使用しようとしています。Golang Iris Web - Serve 1x1 pixel

私の問題は、1x1 gifピクセルをどのように提供するのですか?c.HTMLコンテキストではなく、ブラウザタイトルが1x1イメージgifになる方法です。画像はトラッキングに使用されます。

ご協力いただければ幸いです。

答えて

1

注意:私は実際にアイリスに精通していないので、解決法は慣用ではないかもしれません。より良い理解のため

package main 

import (
    "github.com/kataras/iris" 
    "image"  
    "image/color" 
    "image/gif" 
) 

func main() { 

    iris.Get("/", func(ctx *iris.Context) { 
     img := image.NewRGBA(image.Rect(0, 0, 1, 1)) //We create a new image of size 1x1 pixels 
     img.Set(0, 0, color.RGBA{255, 0, 0, 255}) //set the first and only pixel to some color, in this case red 

     err := gif.Encode(ctx.Response.BodyWriter(), img, nil) //encode the rgba image to gif, using gif.encode and write it to the response 
     if err != nil { 
      panic(err) //if we encounter some problems panic 
     } 
     ctx.SetContentType("image/gif") //set the content type so the browser can identify that our response is actually an gif image 
    }) 

    iris.Listen(":8080") 
} 

リンク:

関連する問題