Golang, which is an imported side effect

import (
    _ "github.com/lib/pq"
    _ "image/png"
    ...
)

The effective option says that these types of imports mean a side effect. I read a few SO answers, but no one explains what it is import side effect. Can someone clarify the term import side effect?

+4
source share
1 answer

" ", /​​, . , , , , (, init(), , , , ect). go , , , .. import _ "somepackageImNotUsingReally"

EDIT: , init() ; https://golang.org/doc/effective_go.html#init - init, main. , init(), . , , , , , , - .

EDIT2: init , " , ", , PackageScopeVar := unexportedInitializerThatWritesToDisc() .

+8

Source: https://habr.com/ru/post/1606475/


All Articles