aboutusesTILblog

Today I learned about...
golang

Back to all tags

golang10.10.2023

golang empty switch

TIL that golang allows for empty switch statements in the condition block. This is not possible in JavaScript! The reasoning behind this is that the switch statement in golang is not limited to only comparing values. Below you can see two versions of branching logic — one with the switch and one with else ifs 😊.

with-switch.go
package main
import "fmt"
func main() {
    i := 10
    switch {
    case i < 0:
        fmt.Println("Negative number")
    case i == 0:
        fmt.Println("Zero")
    case i > 0:
        fmt.Println("Positive number")
    }
}
no-switch.go
package main
import "fmt"
func main() {
    i := 10
    if i < 0 {
        fmt.Println("Negative number")
    } else if i == 0 {
        fmt.Println("Zero")
    } else if i > 0 {
        fmt.Println("Positive number")
    }
}
golang12.04.2023

wails.io

At a recent go meetup, I learned about a a cool thing to create cross platform applications in Go: wails.

Check it out

golang08.04.2023

Air - live reload for Go apps

While working through my golang course, I came across a tool for live-reloading golang apps: Air

Check it out