Hello IOTA Forum

Enumerating string constants with iota

https://forum.helloiota.com/Topic18735.aspx

By nikjohn1538 - 8 Jan 2019

The following example defines a series of port numbers starting at 3333 using iota.

package main

import (
  "fmt"
)
const (
FirstPort = iota+3333
SecondPort
ThirdPort
)
func main() {
  hostAndPort := "localhost:"+fmt.Sprint(SecondPort)
  fmt.Printf("%s", hostAndPort )
  // Output:
  // localhost:3334
}

When combining hostname and ports, I'd like to avoid having to wrap the port constant in fmt.Sprint and simply write, for example, "localhost:"+SecondPort. Is there a way to use iota to define the port numbers as string constants, e.g "3334"?

The following doesn't work:

FirstPort = string(iota + 3333)
Neither does

FirstPort = fmt.Sprintf("%d", iota + 3333)


Thanks
Nikhil John
IOTA Admin