Skip to content

Instantly share code, notes, and snippets.

@maddygoround
Last active October 17, 2015 12:42
Show Gist options
  • Save maddygoround/90eb728686b26c03ba24 to your computer and use it in GitHub Desktop.
Save maddygoround/90eb728686b26c03ba24 to your computer and use it in GitHub Desktop.
Find Error code from the given error in golang
package main
import ("regexp"
"errors"
"fmt"
)
var errExtract = regexp.MustCompile(`Err (\d+)`)
func main(){
customErr := errors.New("Err 1024 ; sql must use 3 rows but define 4 in scan")
match := errExtract.FindStringSubmatch(customErr.Error())
fmt.Print(match)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment