Enumerating string constants with iota


Author
Message
nikjohn1538
n
Attaching to Tangle (25 reputation)Attaching to Tangle (25 reputation)Attaching to Tangle (25 reputation)Attaching to Tangle (25 reputation)Attaching to Tangle (25 reputation)Attaching to Tangle (25 reputation)Attaching to Tangle (25 reputation)Attaching to Tangle (25 reputation)Attaching to Tangle (25 reputation)
Group: Forum Members
Posts: 1, Visits: 0
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

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Login

Explore
Messages
Mentions
Search