- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: go-best-practices/duplicate-imports
Language: Go
Severity: Notice
Category: Best Practices
In Go, duplicate imports refer to importing the same package multiple times in a single file. It is considered a best practice to avoid duplicate imports in Go for the following reasons:
init()
, which is executed during package initialization. When the same package is imported multiple times, the init()
function is run multiple times as well. This can lead to unexpected side effects and violate assumptions made by the package initialization code.To avoid these issues, it is recommended to keep imports concise and remove any duplicates. Go provides a handy feature where you can group multiple imports from the same package on a single line, reducing duplication. Additionally, using aliases when necessary can help resolve naming conflicts between symbols from different packages.
import (
"fmt"
fmt2 "fmt"
fmt3 "fmt"
_ "fmt"
"io"
io2 "io"
"log"
)
import (
"fmt"
log1 "log"
)