From ce3182d4c3f5fb723a16bece3157a5058b1236f9 Mon Sep 17 00:00:00 2001 From: Grégoire Duchêne Date: Sun, 14 Mar 2021 15:41:22 +0000 Subject: Move Twilio authn code into its own package --- pkg/twilio/sms.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 pkg/twilio/sms.go (limited to 'pkg/twilio/sms.go') diff --git a/pkg/twilio/sms.go b/pkg/twilio/sms.go new file mode 100644 index 0000000..0a7dba8 --- /dev/null +++ b/pkg/twilio/sms.go @@ -0,0 +1,34 @@ +// SPDX-FileCopyrightText: © 2021 Grégoire Duchêne +// SPDX-License-Identifier: ISC + +package twilio + +import ( + "net/http" + "time" +) + +type SMS struct { + DateReceived time.Time + From, To, Body string +} + +type SMSTee struct { + Chan chan<- SMS + Handler http.Handler +} + +var _ http.Handler = &SMSTee{} + +func (th *SMSTee) ServeHTTP(w http.ResponseWriter, r *http.Request) { + select { + case th.Chan <- SMS{ + DateReceived: time.Now(), + From: r.FormValue("From"), + To: r.FormValue("To"), + Body: r.FormValue("Body"), + }: + th.Handler.ServeHTTP(w, r) + case <-r.Context().Done(): + } +} -- cgit v1.2.3-70-g09d2