Go, Zero to Hello World

Almost too easy

2023/02

Go with Fiber

I already had Go installed, but the process is very simple on linux following the official instructions, https://go.dev/doc/install. On Windows, I use Scoop.

It is possible to build a simple server using only the Go standard library, but this is a zero to running with dependencies test. On a whim, I chose the Fiber framework and used the front page example.

$ mkdir gofiber_test
$ cd gofiber_test
$ go mod init jantzenowens.com/gofiber-test
-> go: creating new go.mod: module jantzenowens.com/gofiber-test

I created app.go, added the code sample from https://gofiber.io, and ran go mod tidy and go run ..

// app.go
package main

import (
    "log"

    "github.com/gofiber/fiber/v2"
)

func main() {
    app := fiber.New()

    app.Get("/", func (c *fiber.Ctx) error {
        return c.SendString("Hello, World!")
    })

    log.Fatal(app.Listen(":3000"))
}

Tested with curl

$ curl localhost:3000
-> Hello, World!

Project tree

── gofiber_test
├── app.go
├── gofiber-test - 9MB executable
├── go.mod
└── go.sum

Start to finish, while writing these notes, was less than 10 minutes. go.sum listed the following transitive dependencies.

github.com/andybalholm/brotli
github.com/gofiber/fiber/v2
github.com/google/uuid
github.com/klauspost/compress
github.com/mattn/go-colorable
github.com/mattn/go-isatty
github.com/mattn/go-runewidth
github.com/philhofer/fwd
github.com/rivo/uniseg
github.com/savsgio/dictpool
github.com/savsgio/gotils
github.com/tinylib/msgp
github.com/valyala/bytebufferpool
github.com/valyala/fasthttp
github.com/valyala/tcplisten
github.com/yuin/goldmark
golang.org/x/crypto
golang.org/x/mod
golang.org/x/net
golang.org/x/sync
golang.org/x/sys
golang.org/x/term
golang.org/x/text 
golang.org/x/tools 
golang.org/x/xerrors