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
Terraform未経験の御様に対してどの ように導⼊を進めていったか
tkikuchi
2
430
隣接領域をBeyondするFinatextのエンジニア組織設計 / beyond-engineering-areas
stajima
1
270
ISUCONに強くなるかもしれない日々の過ごしかた/Findy ISUCON 2024-11-14
fujiwara3
8
860
開発生産性を上げながらビジネスも30倍成長させてきたチームの姿
kamina_zzz
2
1.6k
The Rise of LLMOps
asei
5
1.2k
iOSチームとAndroidチームでブランチ運用が違ったので整理してます
sansantech
PRO
0
120
Amazon Personalizeのレコメンドシステム構築、実際何するの?〜大体10分で具体的なイメージをつかむ〜
kniino
1
100
【若手エンジニア応援LT会】ソフトウェアを学んできた私がインフラエンジニアを目指した理由
kazushi_ohata
0
140
OCI Network Firewall 概要
oracle4engineer
PRO
0
4.1k
AGIについてChatGPTに聞いてみた
blueb
0
130
TanStack Routerに移行するのかい しないのかい、どっちなんだい! / Are you going to migrate to TanStack Router or not? Which one is it?
kaminashi
0
560
TypeScript、上達の瞬間
sadnessojisan
46
13k
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Become a Pro
speakerdeck
PRO
25
5k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Facilitating Awesome Meetings
lara
50
6.1k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
120
How to train your dragon (web standard)
notwaldorf
88
5.7k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
RailsConf 2023
tenderlove
29
900
It's Worth the Effort
3n
183
27k
Git: the NoSQL Database
bkeepers
PRO
427
64k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
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
֬ೝ༻ϝʔϧΞυϨεͷૹ৴Λ໓