go - Managing errors in golang -


i'm coming ruby , looking @ go @ moment. start writing little bit of code check tls support given host.

 var tls_versions = map[uint16]string{   tls.versionssl30:  "sslv3",   tls.versiontls10:  "tlsv1.0",   tls.versiontls11:  "tlsv1.1",   tls.versiontls12:  "tlsv1.2", }  var refused_re = regexp.mustcompile(": connection refused") var nodns_re = regexp.mustcompile(": no such host") var versionnotsupported_re = regexp.mustcompile(": protocol version not supported")  func checkversion(host string) (map[string]bool, error) { // {{   ret := map[string]bool{}    version := tls.versionssl30; version <= tls.versiontls12; version++ {     conn, err := tls.dial("tcp", host+":443", &tls.config{        minversion: uint16(version),     })      if err != nil &&          (refused_re.matchstring(err.error()) == true || nodns_re.matchstring(err.error()) == true) {        log.println(err)       return ret, err     }      if err != nil && versionnotsupported_re.matchstring(err.error()) == true  {       ret[tls_versions[uint16(version)]] = false       log.println("not supported: "+host+"  "+tls_versions[uint16(version)])     }     ret[tls_versions[uint16(version)]] = true      if conn != nil {       conn.close()     }   }   return ret, nil }  

coming ruby found error management in code pretty ugly i'm 1 typo/change away not getting right reason error. tried play reflect couldn't wanted. wondering if missing obvious or if go way? or specific crypto/tls library avoid recovering issue?

thanks help.

there possibility error management in go.

see this answer dave c nice summary , examples.

unfortunately in case of tls package, you're out of luck. errors try detect generated fmt.errorf() calls (which delegate errors.new()) not special in way , not pre-declared can't better current solution distinguish them. developers lazy provide more sophisticated or more traceable errors or thought not important , left out simplicity; serve more informational developer.

further reading (quoted dave c's answer):


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -