일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- esbuild
- context7
- blank import
- redirect-gateway
- elasticsearch
- ssh 에이전트
- RDS
- Kubernetes
- go
- typescript
- sqs fifo queue
- GoF
- 구조체
- goland
- 디자인패턴
- Intellij
- 2024 톨스토이문학상 수상
- AWS
- 캡슐화
- 티스토리챌린지
- database/sql
- Infra
- 오블완
- replication lag
- AI
- authorizationpolicy
- javascript
- golang
- GIT
- go-sql-driver
Archives
- Today
- Total
목록2025/09/03 (1)
Fall in IT.
Go에서 context.WithValue() 안전하게 사용하기
Go에서 context.WithValue()를 사용해 값을 전달할 때, 습관적으로 string 타입을 key로 사용하곤 했습니다. 하지만 이 방식은 key 충돌과 같은 문제가 발생할 수 있습니다.이 글에서는 안전한 context key 사용법과 주의사항에 대해서 알아보겠습니다.string key 사용시 발생할 수 있는 문제const UserIdKey string = "user_id"func withUserId(ctx context.Context, user *User) context.Context { return context.WithValue(ctx, UserIdKey, user)}위의 코드는 go-staticcheck에서 경고를 발생시킨다.should not use built-in type string..
프로그래밍언어/Golang
2025. 9. 3. 21:29