i'm coming from Java, and there you always do something like:
Http http = new Http(...);
http.ListenAndServe();
So all information are stored in the local variable "http".
It's different in go. There most of the information is stored directly "in another package".
You do:
import "net/http"
...
http.ListenAndServe(...)
So you dont have to explicitly (well you could) instantiate a server struct. Just call a function from the package and all the structs will be created from there. (So compared to Java, it acts like static functions with static member variables to store all information ?)
So this is how you do it (everytime) in go ?
Coming from Java, this is a little bit hard to understand.
Especially when to use this method, when to use a factory pattern (like: NewHttpServer(...)
) and when to explicitly create a struct from another package ( like: var http http.Server = http.Server{...}
)
Everything might be possible, but what is the idiomatic golang code ?
Is there any good document/tutorial which explains it ?