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
sendmailのラッパーをGo言語で作ってみた話
Search
Hiromi Kimura
December 15, 2016
Technology
1
2k
sendmailのラッパーをGo言語で作ってみた話
Hiromi Kimura
December 15, 2016
Tweet
Share
More Decks by Hiromi Kimura
See All by Hiromi Kimura
マネーフォワード Pay for Businessのフロントエンド / Money Forward Pay for Business Frontend
kimromi
0
780
マネーフォワードクラウド経費でのフロントエンドの取り組み / moneyforward-expense-frontend
kimromi
4
1k
エンジニアにとってのアウトプットとはなにか考えた / what-is-output
kimromi
3
1.1k
TypeScriptで作るGitHubApps / make GitHub Apps by TypeScript
kimromi
0
550
ムームードメインのJavaScript環境を整えた話 / prepare muumuu-domain's javascript
kimromi
1
500
ぼくがかんがえたさいきょうのぷるりくえすと / saikyo-no-pull-request
kimromi
7
110k
Vue.js on Rails / vue-js-on-rails
kimromi
7
4.7k
本番環境にVue.jsを使った話 / Use Vue.js at production
kimromi
3
1.3k
how about Marp?
kimromi
0
110
Other Decks in Technology
See All in Technology
ABEMA のコンテンツ制作を最適化!生成 AI x クラウド映像編集システム / abema-ai-editor
cyberagentdevelopers
PRO
1
180
顧客が本当に必要だったもの - パフォーマンス改善編 / Make what is needed
soudai
24
6.7k
Aurora_BlueGreenDeploymentsやってみた
tsukasa_ishimaru
1
120
Amazon_CloudWatch_ログ異常検出_導入ガイド
tsujiba
4
1.5k
【若手エンジニア応援LT会】AWS Security Hubの活用に苦労した話
kazushi_ohata
0
160
「 SharePoint 難しい」ってよく聞くけど、そんなに言うなら8歳の息子に試してもらった
taichinakamura
1
600
Jr. Championsになって、強く連携しながらAWSをもっと使いたい!~AWSに対する期待と行動~
amixedcolor
0
190
2024-10-30-reInventStandby_StudyGroup_Intro
shinichirokawano
1
620
GitHub Universe: Evaluating RAG apps in GitHub Actions
pamelafox
0
170
分布で見る効果検証入門 / ai-distributional-effect
cyberagentdevelopers
PRO
4
690
使えそうで使われないCloudHSM
maikamibayashi
0
170
「最高のチューニング」をしないために / hack@delta 24.10
fujiwara3
21
3.4k
Featured
See All Featured
A Tale of Four Properties
chriscoyier
156
23k
The Pragmatic Product Professional
lauravandoore
31
6.3k
Product Roadmaps are Hard
iamctodd
PRO
48
10k
How to Ace a Technical Interview
jacobian
275
23k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Rails Girls Zürich Keynote
gr2m
93
13k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
RailsConf 2023
tenderlove
29
880
Thoughts on Productivity
jonyablonski
67
4.3k
Visualization
eitanlees
144
15k
Facilitating Awesome Meetings
lara
49
6k
Transcript
ଜւ(.01FQBCP *OD ϗεςΟϯάࣄۀ෦5FDI.5( TFOENBJMͷϥούʔΛ (PݴޠͰ࡞ͬͯΈͨ
ΤϯδχΞ ଜւ!LJNSPNJ ϗεςΟϯάࣄۀ෦ϜʔϜʔυϝΠϯνʔϜ
ຖि༵͓ۚனͷ (P-VODI
ͳΜ͔ॻ͍ͯΈ͍ͨͳ͊
None
ॻ͍ͯΈͨʂ
TFOENBJMMPHHFS IUUQTHJUIVCDPNLJNSPNJTFOENBJMMPHHFS ͍ͨͩ·W
TFOENBJMMPHHFSʁ ϜʔϜʔυϝΠϯ 1)1ɾ3VCZ "QQMJDBUJPO TFOENBJM Ϣʔβʔ ɾϢʔβʔొ ɾυϝΠϯऔಘɺߋ৽ ɾظݶΕؒۙͷҊ ɹɹɹɹɹɹͳͲͷϝʔϧ
TFOENBJMMPHHFSʁ ϜʔϜʔυϝΠϯ 1)1ɾ3VCZ "QQMJDBUJPO TFOENBJMMPHHFS Ϣʔβʔ ɾϢʔβʔొ ɾυϝΠϯऔಘɺߋ৽ ɾظݶΕؒۙͷҊ ɹɹɹɹɹɹͳͲͷϝʔϧ
TFOENBJM NBJM MPH
TFOENBJMMPHHFSʁ ϜʔϜʔυϝΠϯ 1)1ɾ3VCZ "QQMJDBUJPO TFOENBJMMPHHFS Ϣʔβʔ ɾϢʔβʔొ ɾυϝΠϯऔಘɺߋ৽ ɾظݶΕؒۙͷҊ ɹɹɹɹɹɹͳͲͷϝʔϧ
TFOENBJM NBJM MPH UBJM
Ͳ͏͍͍ͷʁ w ސ٬ཧ͔Βϝʔϧૹ৴ঢ়گΛӾཡͰ͖Δ ظݶΕલʹϝʔϧ͕͜ͳ͔ͬͨΜͰ͚͢ͲʂʁʹରԠ͍͢͠ w ֬ೝ༻ͷϝʔϧΞυϨεͷϝʔϧૹ৴͕ෆཁʹ Ϣʔβʔ̍௨ɺ֬ೝ༻ϝʔϧΞυϨε̍௨ͷ̎௨ૹ৴͍ͯ͠Δɾɾ
Πϯετʔϧ logfile: /var/log/sendmail.log $ wget -O /usr/local/bin/sendmail-logger https:// github.com/kimromi/sendmail-logger/releases/download/ v0.0.2/sendmail-logger_linux_amd64
$ chmod 755 /usr/local/bin/sendmail-logger ઃఆϑΝΠϧFUDTFOENBJMMPHHFSDPOpHZBNM ྫ $FOU04CJU όΠφϦΛ(JUIVCʹஔ͍͍ͯΔͷͰ 04ʹ͋ͬͨͷΛμϯϩʔυ͢Δ͚ͩ
ઃఆํ๏ 1)1 sendmail_path = /usr/sbin/sendmail -t -i sendmail_path = /usr/local/bin/sendmail-logger
QIQJOJ sendmail_path = sendmail-logger # path௨ͬͯΕ
ઃఆํ๏ 3VCZ"DUJWF.BJMFSPO3BJMT Rails.application.configure do .. config.action_mailer.delivery_method = :sendmail config.action_mailer.sendmail_settings =
{ location: "/usr/local/bin/sendmail-logger" } end DPOpHFOWJSPONFOUT3"*-4@&/7SC
࣮͔Β·ͰͷಓͷΓ w ࣮ w ΫϩείϯύΠϧ w όΠφϦ ҙ֎ͱ͢ΜͳΓ͍͚ͨΫϚʔ
࣮ 1.
TFOENBJMMPHHFSͰ͍ͬͯΔ͜ͱ w ࣮ߦϩάग़ྗ w ඪ४ೖྗಡΈࠐΈ w ZBNMϑΝΠϧಡΈࠐΈ w ϝʔϧϩάϑΝΠϧग़ྗ w
TFOENBJMίϚϯυ࣮ߦ
࣮ߦϩάग़ྗ w MPH(Pඪ४ͷMPHϥΠϒϥϦ package main import ( "log" "os" )
func init() { f, _ := os.OpenFile("out.log", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666) log.SetOutput(f) } func main() { log.Print("loglog") } ¥ 3FBEBOE8SJUF ϑΝΠϧͳ͔ͬͨΒ࡞Δ ඌʹςΩετՃ
ඪ४ೖྗಡΈࠐΈ w CVpP(Pඪ४ͷ*0όοϑΝϦϯά package main import ( "bufio" "fmt" "os"
) func main() { body := "" scanner := bufio.NewScanner(os.Stdin) for scanner.Scan() { body += scanner.Text() + "\n" } if err := scanner.Err(); err != nil { fmt.Print(err) } } ෳߦͷೖྗ͕͋Δͱ͖ GPSͰશߦऔಘ͢Δ
ZBNMϑΝΠϧಡΈࠐΈ w HPZBNMZBNMZBNMಡΈࠐΈϥΠϒϥϦ IUUQTHJUIVCDPNHPZBNMZBNM package main import ( "fmt" "io/ioutil"
yaml "gopkg.in/yaml.v2" ) type Config struct { LogFile string `yaml:"logfile"` } func main() { file, _ := ioutil.ReadFile("/etc/sendmail-logger/config.yaml") conf := Config{} yaml.Unmarshal([]byte(file), &conf) fmt.Print(conf) } ZBNMϑΝΠϧͰͷઃఆ໊Λ TUSVDUͰఆ͓ٛͯ͘͠
ϝʔϧϩάϑΝΠϧग़ྗ package main import ( "fmt" "os" ) func main()
{ file, err := os.OpenFile("mail.log", os.O_WRONLY | os.O_CREATE | os.O_APPEND, 0664) if err != nil { fmt.Print(err) } defer file.Close() file.Write(([]byte)("write")) } w PT(Pඪ४ͷ04ػೳͷΠϯλʔϑΣʔεύοέʔδ 8SJUF0OMZ EFGFSͰ࣮ߦྃ࣌ʹ ϑΝΠϧΫϩʔζ͢Δ
TFOENBJMίϚϯυ࣮ߦ w PTFYFD(Pඪ४ͷ֎෦ίϚϯυ࣮ߦύοέʔδ package main import ( "fmt" "os/exec" )
func main() { out, err := exec.Command("ls", "-la").Output() if err != nil { fmt.Print(err) } fmt.Print(string(out)) } ίϚϯυ࣮ߦͭͭ͠ ඪ४ग़ྗΛมʹऔΓࠐΉ
ΫϩείϯύΠϧ 2.
HPY w ΫϩείϯύΠϧ༻ͷύοέʔδ $ go get github.com/mitchellh/gox $ gox Number
of parallel builds: 3 --> linux/arm: _/Users/PMAC243S/repos/github.com/kimromi/sendmail-logger --> darwin/386: _/Users/PMAC243S/repos/github.com/kimromi/sendmail-logger --> linux/386: _/Users/PMAC243S/repos/github.com/kimromi/sendmail-logger --> netbsd/arm: _/Users/PMAC243S/repos/github.com/kimromi/sendmail-logger ɾɾɾ IUUQTHJUIVCDPNNJUDIFMMIHPY ίϚϯυൃͰ ֤04༻ͷόΠφϦΛ࡞ HPHFUͰΠϯετʔϧ
όΠφϦ 3.
HIS w HJUIVCDPNʹWFSTJPOUBH͖ͰϦϦʔε IUUQTHJUIVCDPNUDOLTNHIS $ go get github.com/tcnksm/ghr $ gox
-output "pkg/{{.Dir}}_{{.OS}}_{{.Arch}}" $ ghr v0.0.2 pkg/ WFSTJPOUBHΛ༩ͯ͠ϦϦʔε όΠφϦμϯϩʔυͰ͖Δ HPHFUͰΠϯετʔϧ
͓ΘΓɻ؆୯ɻ
ͳΜ͔ॻ͍ͯΈ·͠ΐʂ ͕Ͱ͖͔ͨΒΈΜͳͰ͖Δ
ࠓޙ w ςετॻ͍ͯͳ͍ɾɾɾ w TNUQͷରԠͱ͔ w qVFOUEͱ࿈ܞͯ͠5SFBTVSF%BUBʢݕূதʣ w ސ٬ཧ͔Βϝʔϧ༰ΛݟΕΔΑ͏ʹ w
֬ೝ༻ϝʔϧΞυϨεͷૹ৴Λ໓