9005: Replace matchTrue regexp with StringBool func.
[arvados.git] / sdk / go / arvadosclient / arvadosclient.go
index 7e33ec0ce6fc3b2a5ba50ce4294916f6601f1280..4cfda94581518fd9360ebc4f3268e231893797c7 100644 (file)
@@ -74,6 +74,13 @@ func (e APIServerError) Error() string {
        }
 }
 
+// StringBool tests whether s is suggestive of true. It returns true
+// if s is a mixed/uppoer/lower-case variant of "1", "yes", or "true".
+func StringBool(s string) bool {
+       s = strings.ToLower(s)
+       return s == "1" || s == "yes" || s == "true"
+}
+
 // Helper type so we don't have to write out 'map[string]interface{}' every time.
 type Dict map[string]interface{}
 
@@ -175,12 +182,11 @@ func New(c *arvados.Client) (*ArvadosClient, error) {
 // ARVADOS_API_HOST_INSECURE, ARVADOS_EXTERNAL_CLIENT, and
 // ARVADOS_KEEP_SERVICES.
 func MakeArvadosClient() (ac *ArvadosClient, err error) {
-       var matchTrue = regexp.MustCompile("^(?i:1|yes|true)$")
        ac, err = New(arvados.NewClientFromEnv())
        if err != nil {
                return
        }
-       ac.External = matchTrue.MatchString(os.Getenv("ARVADOS_EXTERNAL_CLIENT"))
+       ac.External = StringBool(os.Getenv("ARVADOS_EXTERNAL_CLIENT"))
        return
 }