Your port variable is of type *string (this is what flag.String() returns). To get a value of type string, there's no other way than to dereference it: *port.
You may do so at every place where you need to pass it as a string, or you may use flag.StringVar() instead:
var port string
func init() {
flag.StringVar(&port, "port", "", "port")
}
In this case, your port variable is of type string, so no dereferencing is needed. Here you explicitly provide a *string value to the flag package to be used: the address of your variable of type string, which will be of type *string of course (so the flag package will be able to modify / set the pointed value). The flag.String() is a convenience function which allocates a string value and returns you the pointer to it.
Another option would be to dereference it once and store the string value in another variable of type string, for example:
var portp = flag.String("port", "", "port")
var port string
func main() {
flag.Parse()
port = *portp
// Now you can use port which is of type string
}
But I prefer the flag.StringVar() solution.
Note that however a port is a number, you may be better off using flag.Int() or flag.IntVar():
var port int
func init() {
flag.IntVar(&port, "port", 0, "port")
}
flagpackage functions is a pointer, since it needs to be modified "behind the scenes". You're probably better off using aflag.Int, though, since you're currently open for someone to call your program with "-flag crashy", which will most likely cause a panic.flag.StringVar. Sometimes reading the package documentation really does help.