$30 off During Our Annual Pro Sale. View Details »
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
560
ムームードメインの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
プロダクトマネージャーは 事業責任者の夢をみるのか pmconf2024
gimupop
1
8.3k
AWS re:Invent 2024登壇資料(GBL206-JA: Unleashing the power of generative AI on AWS for your business)
minorun365
PRO
7
220
12/2(月)のBedrockアプデ速報(re:Invent 2024 Daily re:Cap #1 with AWS Heroes)
minorun365
PRO
2
310
突き破って学ぶコンテナセキュリティ/container-breakout-cncj-lt
mochizuki875
6
1.1k
お悩みハンドブック紹介資料
grafferhandbook
0
1.1k
ミスが許されない領域にAIを溶け込ませる プロダクトマネジメントの裏側
t01062sy
8
8.1k
LangChainとSupabaseを活用して、RAGを実装してみた
atsushii
0
150
ドメインロジックで考えるテスタビリティ
leveragestech
1
280
深層学習のリペア技術の最新動向と実際 / DNN Repair Techniques for AI Performance Alignment for Safety Requirements
ishikawafyu
0
460
12/3(火)のBedrockアプデ速報(re:Invent 2024 Daily re:Cap #2 with AWS Heroes)
minorun365
PRO
4
140
[GDG DevFest Bangkok 2024] - The Future of Retail E-commerce with Gemini AI
punsiriboo
0
300
Will Positron accelerate us?
lycorptech_jp
PRO
1
120
Featured
See All Featured
Scaling GitHub
holman
458
140k
The Invisible Side of Design
smashingmag
298
50k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
The Language of Interfaces
destraynor
154
24k
How GitHub (no longer) Works
holman
310
140k
Into the Great Unknown - MozCon
thekraken
33
1.5k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
GraphQLとの向き合い方2022年版
quramy
44
13k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
247
1.3M
4 Signs Your Business is Dying
shpigford
181
21k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
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
֬ೝ༻ϝʔϧΞυϨεͷૹ৴Λ໓