Comment

Comment by andreygrehov

Another approach could be:

  package color

  type Color struct {
    val string
  }

  func (c Color) String() string {
    return c.val
  }

  var (
    Red   = Color{val: "red"}
    Green = Color{val: "green"}
    Blue  = Color{val: "blue"}
  )
Since `val` is not exported, external packages cannot create arbitrary `Color`.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton