From 6c4bf4b77190fa84dd73d0f253b5059a9145b66e Mon Sep 17 00:00:00 2001 From: pj Date: Wed, 20 Apr 2022 10:43:01 +1000 Subject: [PATCH] ADD GO CODE --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 5cbe1f4..a4dfd3f 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,29 @@ function isDisposableEmail($email, $blocklist_path = null) { return in_array($domain, $disposable_domains); } ``` + +**Go** contributed by [@pjebs](https://github.com/pjebs) + +```go +import ("bufio"; "fmt"; "os"; "strings";) +var disposableList = make(map[string]struct{}, 3500) +func init() { + f, _ := os.Open("disposable_email_blocklist.conf") + for scanner := bufio.NewScanner(f); scanner.Scan(); { + disposableList[scanner.Text()] = struct{}{} + } + f.Close() +} + +func isDisposableEmail(email string) (disposable bool) { + segs := strings.Split(email, "@") + _, disposable = disposableList[strings.ToLower(segs[len(segs)-1])] + return +} +``` + +Alternatively, [anti-disposable-email](https://github.com/rocketlaunchr/anti-disposable-email) which auto-updates based on this repo. + **Ruby on Rails** contributed by [@MitsunChieh](https://github.com/MitsunChieh) In the resource model, usually it is `user.rb`: