main.go 의 import 부분을 보면, _ "github.com/benthosdev/benthos/v4/public/compoennts/all"
을 import 하고 있다. 사용하지도 않을 패키지를 뭐하러 import 하고 있을까?
/github.com/benthosdev/benthos/v4/public/components/all
을 보면 더 이상하다.
_ "github.com/benthosdev/benthos/v4/public/components/amqp09"
_ "github.com/benthosdev/benthos/v4/public/components/amqp1"
_ "github.com/benthosdev/benthos/v4/public/components/avro"
...
이렇게 패키지를 import만 하고 있다.
이렇게 하는 이유는 go 언어의 main 함수 실행전 처리 과정 때문이라고 생각한다.
어떤 패키지에서 다른 패키지를 import 하게되면, go 언어는 다음과 같은 순서로 처리한다.
import -> const -> var -> init()
main() 실행 전 미리 모든 패키지의 const, value, init() 등을 실행해서 main() 실행 전 모든 준비를 하기 위해 패키지를 명시적으로 import 시키는 것이다.
'benthos > 코드 분석' 카테고리의 다른 글
input - generate (0) | 2023.06.28 |
---|---|
manager (0) | 2023.02.01 |