Created
October 1, 2016 17:30
-
-
Save joshstrange/a3fb0c2fb2ab5ead21d5ffee2bb23d5a to your computer and use it in GitHub Desktop.
Docker-gen Closest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"strings" | |
"fmt" | |
) | |
func arrayClosest(values []string, input string) string { | |
best := "" | |
for _, v := range values { | |
if strings.Contains(input, v) && len(v) > len(best) { | |
best = v | |
} | |
} | |
return best | |
} | |
func main() { | |
certs := make([]string, 2) | |
certs[0] = "api.dev.foo.com" | |
certs[1] = "dev.foo.com" | |
fmt.Println(certs) | |
fmt.Println(arrayClosest(certs, "dev.foo.com")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment