So without making a conscious choice I’ve been using and loving some excellent Go-lang software: Hugo, GoToSocial, and Readeck. I don’t know Go but I’ve picked up some templating from customizing Hugo (which powers this blog), is it time I learned more? Let’s Go!!!

I don’t engineer/code for work anymore so I don’t have proficiency in any specific language and for some reason that has been bothersome. I do write some ad-hoc and nominal (terrible) Python and SQL, neither of which I have written professionally before, so I’ve been thinking about increasing my Python proficiency. But… that’s not where my tinkering/crafting heart has been, although FastHTML for Python is a really interesting proposition.

I’ve also rooted around in Rust-Lang and really love the core concepts of borrow-checker and memory-safety; wish I had that when I was (poorly) working in embedded software (so. many. segfaults.). I’ve read some of the Rust book and even contribute a bit to a Rust project (Ringfairy) but realistically I do not have the focus and drive to gain any proficiency in Rust.

Black and white photo of a taxidermied polar bear dyed black holding a coffee cup in front of a brick wall and very bright windows to either side.
I don't have a gopher (Go mascot) photo but I do feel like a coffe'ed up bear

But since I’ve burrowing around in Go software and would love to scratch a few itches and contribute back, I decided to take advantage of a bit time off to learn a bit of Go-lang. The cross-platform, single-binary, C-like paradigm, with a massive standard library is pretty appealing. I’m getting along fine with the syntax for the most part but putting the type after the variable is going to be an adjustment.

I wrote a toy “hello world” with the most common syntax I need as a reference (based on reading and watching YouTube snippets). To get up and running I created a nix-shell environment, and since I didn’t have emacs setup for Go dev, I fired up VS Codium, instead of yak-shaving (for once). 😬 VS Codium works really well out of the box with click-ops extensions installation. Someone better give me a nicely configured Go setup for Emacs quick. Update: I was pointed to this great video made by @skybert@hachyderm.io for Go development in Emacs (linked config).

So what? This 100 lines of reference between Go and HTML (with comments) prints to console, starts and serves a webpage and conditionally shows information from structured data on a webpage; that’s pretty cool and compact. Nothing I am going to make with Go can’t just easily be slopped together and probably better, but learning things with your own brain is punk AF!

If you have tips or want to chat, catch me on the fedi.

main.go

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  package main

import (
      "fmt"
      "html/template"
      "net/http"
      "strconv"
)

// global variables go here
var message = "Http World!"

// slice, array is fixed size, put size in []
var items = []string{message, "val1", "val2"}

type language struct {
      Id       int
      Language string
      Hello    string
      Active   bool //defaults to false
}

var english = language{
      Id:       0,
      Language: "English",
      Hello:    "Hello",
      Active:   true,
}
var spanish = language{
      Id:       1,
      Language: "Spanish",
      Hello:    "Hola",
      //Active defaults to false, but needs expanded declaration
}
var bangla = language{2, "Bangla", "নমস্কার", true}
var japanese = language{2, "Japanese", "こんにちは", true}
var languages = []language{english, bangla, spanish, japanese}

func main() {
      items = addItem(items, "hola")
      printItems(items)

      http.HandleFunc("/", app)
      http.ListenAndServe(":9090", nil)
}

func printItems(items []string) {
      //if index is not needed use _
      for index, item := range items {
              //fmt.Println(index, ":", item) //will print space between strings
              fmt.Printf("%d: %s\n", index, item)
      }
}

// return multiple values by specifying types in (): ([]string, int)
func addItem(items []string, newItem string) []string {
      return append(items, newItem)
}

func showItems(writer http.ResponseWriter) {
      for index, item := range items {
              var showItem = strconv.Itoa(index) + ": " + item
              fmt.Fprintln(writer, showItem)
      }
}

func app(writer http.ResponseWriter, request *http.Request) {
      //fmt.Fprintln(writer, message)
      //showItems(writer)
      renderTemplate(writer, languages)
}

func renderTemplate(writer http.ResponseWriter, languages []language) {
      var htmlTemplates *template.Template
      htmlTemplates, _ = htmlTemplates.ParseGlob("templates/*.html")
      htmlTemplates.ExecuteTemplate(writer, "index.html", languages)
}

templates/index.html

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
  <!DOCTYPE html>
<html>

<head>
    <title>Greetings</title>
</head>

<body>
    {{range .}}
    {{if .Active}}
    <div id="{{.Id}}">
        <span>{{.Language}}: </span>
        <span>{{.Hello}}</span>
    </div>
    {{end}}
    {{end}}
</body>

</html>

shell.nix

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
  let
  nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-25.11";
  pkgs = import nixpkgs { config = {}; overlays = []; };
in

pkgs.mkShellNoCC {
  packages = with pkgs; [
    go
    gopls
    vscodium
  ];
}