What is the point of using _ in import in go -
this question has answer here:
i have seen strange syntax in go while importing packages: import _ fmt.
i aware import f fmt works alias package , know _ used variable should not cared about.
so no prize guessing here importing package not going use. , in fact looks happening here.
what fail understand why might helpful. if use for _, v := range(arr){} use _ because have no choice , need specify compiler should not worry variable not using.
but if not intend use package, omit (if might useful later, comment it). no reason compiled , added source code.
so there point of using syntax, or useless artifact combining aliasing , unused variables?
it means want import side effects. it's used packages include init. of course import normally, too, _ makes clear wanted side effects.
search "import side effect" in effective go discussion.
a common example net/http/pprof, attaches new handlers default mux. packages github.com/slymarbo/spdy use in same way silently modify default http client.
Comments
Post a Comment