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
800
マネーフォワードクラウド経費でのフロントエンドの取り組み / moneyforward-expense-frontend
kimromi
4
1k
エンジニアにとってのアウトプットとはなにか考えた / what-is-output
kimromi
3
1.1k
TypeScriptで作るGitHubApps / make GitHub Apps by TypeScript
kimromi
0
560
ムームードメインのJavaScript環境を整えた話 / prepare muumuu-domain's javascript
kimromi
1
510
ぼくがかんがえたさいきょうのぷるりくえすと / 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
[Ruby] Develop a Morse Code Learning Gem & Beep from Strings
oguressive
1
150
バクラクのドキュメント解析技術と実データにおける課題 / layerx-ccc-winter-2024
shimacos
2
1k
LINE Developersプロダクト(LIFF/LINE Login)におけるフロントエンド開発
lycorptech_jp
PRO
0
120
新機能VPCリソースエンドポイント機能検証から得られた考察
duelist2020jp
0
210
PHPからGoへのマイグレーション for DMMアフィリエイト
yabakokobayashi
1
160
20241214_WACATE2024冬_テスト設計技法をチョット俯瞰してみよう
kzsuzuki
3
440
AWS re:Invent 2024で発表された コードを書く開発者向け機能について
maruto
0
180
KubeCon NA 2024 Recap: How to Move from Ingress to Gateway API with Minimal Hassle
ysakotch
0
200
株式会社ログラス − エンジニア向け会社説明資料 / Loglass Comapany Deck for Engineer
loglass2019
3
31k
Turing × atmaCup #18 - 1st Place Solution
hakubishin3
0
460
私なりのAIのご紹介 [2024年版]
qt_luigi
1
120
TSKaigi 2024 の登壇から広がったコミュニティ活動について
tsukuha
0
160
Featured
See All Featured
How STYLIGHT went responsive
nonsquared
95
5.2k
Adopting Sorbet at Scale
ufuk
73
9.1k
Visualization
eitanlees
146
15k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
Code Reviewing Like a Champion
maltzj
520
39k
How to Ace a Technical Interview
jacobian
276
23k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
We Have a Design System, Now What?
morganepeng
51
7.3k
Site-Speed That Sticks
csswizardry
2
190
Typedesign – Prime Four
hannesfritz
40
2.4k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Principles of Awesome APIs and How to Build Them.
keavy
126
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
֬ೝ༻ϝʔϧΞυϨεͷૹ৴Λ໓