github.com/grailbio/base@v0.0.11/cmd/ticket-server/support.go (about) 1 // Copyright 2020 GRAIL, Inc. All rights reserved. 2 // Use of this source code is governed by the Apache-2.0 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "strings" 9 ) 10 11 // Return true if a string matches a value in a list 12 func stringInSlice(haystack []string, needle string) bool { 13 for _, s := range haystack { 14 if needle == s { 15 return true 16 } 17 } 18 return false 19 } 20 21 // Return a new list after applying a function to the provided list 22 func fmap(stringList []string, f func(string) string) []string { 23 resultList := make([]string, len(stringList)) 24 for i, v := range stringList { 25 resultList[i] = f(v) 26 } 27 return resultList 28 } 29 30 // Returns the domain part of an email, or "" if it did not split correctly 31 func emailDomain(email string) string { 32 components := strings.Split(email, "@") 33 // Email should have 2 parts. 34 if len(components) != 2 { 35 return "" 36 } else { 37 return components[1] // domain part 38 } 39 }