Go is a popular programming language. It is used for many things, including web development, data science, and machine learning.

Simple

package main

import (
    "encoding/base64"
    "fmt"
)

func main() {
    data, _ := base64.StdEncoding.DecodeString("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")
    fmt.Println(data)
}

Save to file

package main

import (
    "encoding/base64"
    "io/ioutil"
)

func main() {
    data, _ := base64.StdEncoding.DecodeString("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")
    ioutil.WriteFile("empty.gif", data, 0644)
}

HTTP Server

net/http is the standard library for HTTP servers in Go.

package main

import (
    "encoding/base64"
    "net/http"
)

func main() {
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        data, _ := base64.StdEncoding.DecodeString("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")
        w.Write(data)
    })
    http.ListenAndServe(":8080", nil)
}

Gin

Gin is a popular web framework for Go.

package main

import (
    "encoding/base64"
    "github.com/gin-gonic/gin"
)

func main() {
    r := gin.Default()
    r.GET("/empty-gif", func(c *gin.Context) {
        data, _ := base64.StdEncoding.DecodeString("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")
        c.Data(200, "image/gif", data)
    })
    r.Run()
}

Echo

Echo is a popular web framework for Go.

package main

import (
    "encoding/base64"
    "github.com/labstack/echo/v4"
    "github.com/labstack/echo/v4/middleware"
)

func main() {
    e := echo.New()
    e.Use(middleware.Logger())
    e.Use(middleware.Recover())
    e.GET("/empty-gif", func(c echo.Context) error {
        data, _ := base64.StdEncoding.DecodeString("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")
        return c.Blob(200, "image/gif", data)
    })
    e.Logger.Fatal(e.Start(":1323"))
}

Beego

Beego is a popular web framework for Go.

package main

import (
    "encoding/base64"
    "github.com/astaxie/beego"
)

type MainController struct {
    beego.Controller
}

func (c *MainController) Get() {
    data, _ := base64.StdEncoding.DecodeString("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")
    c.Ctx.Output.Body(data)
}

func main() {
    beego.Router("/", &MainController{})
    beego.Run()
}

Revel

Revel is a popular web framework for Go.

package controllers

import (
    "encoding/base64"
    "github.com/revel/revel"
)

type App struct {
    *revel.Controller
}

func (c App) Index() revel.Result {
    data, _ := base64.StdEncoding.DecodeString("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")
    return c.RenderBinary(data, "empty.gif", revel.Inline)
}

Buffalo

Buffalo is a popular web framework for Go.

package actions

import (
    "encoding/base64"
    "github.com/gobuffalo/buffalo"
)

func EmptyGif(c buffalo.Context) error {
    data, _ := base64.StdEncoding.DecodeString("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")
    return c.Render(200, r.Raw(data, "image/gif"))
}

Fiber

Fiber is a popular web framework for Go.

package main

import (
    "encoding/base64"
    "github.com/gofiber/fiber/v2"
)

func main() {
    app := fiber.New()
    app.Get("/", func(c *fiber.Ctx) error {
        data, _ := base64.StdEncoding.DecodeString("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")
        return c.Send(data)
    })
    app.Listen(":3000")
}

Goa

Goa is a popular web framework for Go.

package design

import (
    . "goa.design/goa/v3/dsl"
)

var _ = Service("emptygif", func() {
    Method("emptygif", func() {
        Result(EmptyGif)
    })
})

var EmptyGif = ResultType("application/vnd.emptygif", func() {
    Attributes(func() {
        Attribute("data", ArrayOf(Byte))
    })
    View("default", func() {
        Attribute("data")
    })
})

Iris

Iris is a popular web framework for Go.

package main

import (
    "encoding/base64"
    "github.com/kataras/iris/v12"
)

func main() {
    app := iris.New()
    app.Get("/", func(ctx iris.Context) {
        data, _ := base64.StdEncoding.DecodeString("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")
        ctx.Binary(data)
    })
    app.Listen(":8080")
}