Go-sugar: a Go superset with check and or syntax - feedback welcome

I’m building go-sugar, a superset of Go that compiles .gos files to plain .go files, with full LSP support via a gopls proxy.

The first two sugars are check and or:

// test.gos - go sugar file

func printSum(a, b string) error {
  x := check strconv.Atoi(a)
  y := check strconv.Atoi(b)

  fmt.Printf("%d", x + y)
  return nil
}

func main() {
  name := config.Name or "default"
}

compiles to:

// test.gos.go

func printSum(a, b string) error {
  x, err := strconv.Atoi(a)
  if err != nil {
    return err
  }
  y, err := strconv.Atoi(b)
  if err != nil {
    return err
  }

  fmt.Printf("%d", x + y)
  return nil
}

func main() {
  name := config.Name
  if name == "" {
    name = "default"
  }
}
  • Inspired by templ - IDE support is a must.
  • Each sugar is a plugin, opt-in via a config file.
  • or performs a zero-value check, type-aware.

Still early, wasm demo and LSP coming soon. What do you think?