Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
printf-args-num-ok?
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
decafe09
February 24, 2018
Programming
160
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
printf-args-num-ok?
goでprintfの引数の数をチェックするときの諸々について。
decafe09
February 24, 2018
More Decks by decafe09
See All by decafe09
プロダクト組織の変化 - PM Kansai #1 2026.01.22
decafe09
0
3
GoならわかるGIF
decafe09
0
360
よくあるWebサービスのAPIを作ったらいろいろ勉強になった話/WebApplicationAPITips
decafe09
1
390
goaを使ったAPI開発/api-development-with-goa
decafe09
0
2.1k
Other Decks in Programming
See All in Programming
Jindong: Introducing Declarative Haptics in Compose Multiplatform
l2hyunwoo
0
120
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
210
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
320
これって Effect でできたのでは? / TSKaigi Mashup Kansai #2
susisu
0
240
AWS DevOps AgentのAzure接続機能を検証して見えた活用法/Use Cases Verified for the AWS DevOps Agent's Azure Connectivity Feature
masakiokuda
1
240
SlackアプリとLambdaの 連携を構築した話
pawn_4_s
1
120
Cloudflare is Agents
chimame
0
170
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
200
使いながら育てる Claude Code — 開発フローの1コマンド化 × 繰り返し指摘の自動仕組み化
shiki_kakaku
0
1.8k
AIが無かった頃の素敵な出会いの話
codmoninc
1
440
ソフトウェアエンジニアにとっての生成AI - 特性を知って使い倒す / generative ai for software enginner
kishida
5
1.7k
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
520
Featured
See All Featured
Embracing the Ebb and Flow
colly
88
5.1k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.6k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
Scaling GitHub
holman
464
140k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
200
What's in a price? How to price your products and services
michaelherold
247
13k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
370
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
64
56k
Thoughts on Productivity
jonyablonski
76
5.3k
Transcript
printf - args num ok? Umeda.go #3 2018 - 02
- 24 @decafe09
fmt.Printf fmt.Printf("%s", "moji")
fmt.Printf fmt.Printf("%s", "moji", "yobun")
fmt.Printf $ go build # ここでは気づけない $ go run main.go
# ここで気づける moji%!(EXTRA string=yobun)
fmt.Printf $ go build # ここでは気づけない $ go run main.go
# ここで気づける moji%!(EXTRA string=yobun) func main() { http.HandleFunc( "/xxx", func(w http.ResponseWriter, r *http.Request) { fmt.Printf("%s", "moji", "yobun") return }, ) http.ListenAndServe(":8080", nil) }
fmt.Printf $ go build # ここでは気づけない $ go run main.go
# ここでは気づけない $ curl localhost:8080/xxx # ここで気づける moji%!(EXTRA string=yobun)
go vet $ go vet ./main.go:6: Printf call needs 1
arg but has 2 args go vet ! curl " go vet CI go vet
go vet –printfuncs $ go vet –printfuncs=Infof ./main.go:6: Infof call
needs 1 arg but has 2 args func Infof(format string, a ...interface{}) (n int, err error) { return fmt.Printf(format, a...) }
go vet @ Go 1.10 $ go test ./main.go:6: Printf
call needs 1 arg but has 2 args go1.9.3 main.go:6: wrong number of args for format in Printf call: 1 needed but 2 args go1.10 main.go:6: Printf call needs 1 arg but has 2 args go test go vet go test -printfuncs
Humm... format := "%s" fmt.Printf(format, "moji", ”yobun")
Humm... $ go build # ここでは気づけない $ go vet #
ここでは気づけない $ go run main.go # ここで気づける moji%!(EXTRA string=yobun) http ! % # &$"%
Background API6=3.;?>/2,BW!:20/)O APIVK" C %!8>?4+?5JSAPIRFP XXNTL@YYNTLIEH XXYYEH
XX, YY O(&'!format!O(& %D 71? +<:20/GQ&72-/M%A format#xx,yy*9=-.;?U$
Thinking... "0(' ! 0(',1#%$ /0( $ !
+.)*format !format !&-...
Result func check(format string) error 1. format %! 2. format
message 3. format %! 4. %! func main() { format := "%s" err := check(format) if err != nil { panic(err) } fmt.Println(message(format)) } func message(format string) string { return fmt.Sprintf(format, "moji", "yobun") } func check(format string) error { pre := strings.Count(format, "%!") msg := message(format) post := strings.Count(msg, "%!") if post > pre { return errors.New("format error: " + msg) } return nil }
OK All errors begin with the string "%!" followed sometimes
by a single character (the verb) and end with a parenthesized description. https://golang.org/pkg/fmt/
Check $ go run main.go panic: format error: moji%!(EXTRA string=yobun)
Profile decafe09