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
790
マネーフォワードクラウド経費でのフロントエンドの取り組み / 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.4k
how about Marp?
kimromi
0
110
Other Decks in Technology
See All in Technology
OTelCol_TailSampling_and_SpanMetrics
gumamon
1
220
DynamoDB でスロットリングが発生したとき/when_throttling_occurs_in_dynamodb_short
emiki
0
260
New Relicを活用したSREの最初のステップ / NRUG OKINAWA VOL.3
isaoshimizu
3
630
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
160
Terraform Stacks入門 #HashiTalks
msato
0
360
Zennのパフォーマンスモニタリングでやっていること
ryosukeigarashi
0
170
AIチャットボット開発への生成AI活用
ryomrt
0
170
Oracle Cloud Infrastructureデータベース・クラウド:各バージョンのサポート期間
oracle4engineer
PRO
29
13k
IBC 2024 動画技術関連レポート / IBC 2024 Report
cyberagentdevelopers
PRO
1
110
リンクアンドモチベーション ソフトウェアエンジニア向け紹介資料 / Introduction to Link and Motivation for Software Engineers
lmi
4
300k
Shopifyアプリ開発における Shopifyの機能活用
sonatard
4
260
あなたの知らない Function.prototype.toString() の世界
mizdra
PRO
1
160
Featured
See All Featured
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
Facilitating Awesome Meetings
lara
50
6.1k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Code Review Best Practice
trishagee
64
17k
Building Applications with DynamoDB
mza
90
6.1k
Raft: Consensus for Rubyists
vanstee
136
6.6k
4 Signs Your Business is Dying
shpigford
180
21k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
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
֬ೝ༻ϝʔϧΞυϨεͷૹ৴Λ໓