如何检查文件名太长错误

While trying to create files, I am running into os.PathError because of "file name too long". I would like to handle this scenario to do something specific. How do I go about it, apart from inspecting error.Error which returns the string "file name too long"?

That error is system dependent, but on unix systems the error value is syscall.ENAMETOOLONG

if pe, ok := err.(*os.PathError); ok {
    if pe.Err == syscall.ENAMETOOLONG {
        log.Fatal("name really was too long")
    }
}