示例#1
0
func isUniqueViolation(err error) bool {
	if err != nil {
		var ok bool
		var pge pq.PGError
		pge, ok = err.(pq.PGError)
		if ok {
			if pge.Get('C') == pgErrorUniqueViolation {
				return true
			}
		}
	}
	return false
}
示例#2
0
func getDatabaseErrorMessage(err error) string {
	result := "unknown"

	if err != nil {
		var ok bool
		var pge pq.PGError
		pge, ok = err.(pq.PGError)
		if ok {
			var r, l, m, c, s, f string
			r = pge.Get('R')
			l = pge.Get('L')
			m = pge.Get('M')
			c = pge.Get('C')
			s = pge.Get('S')
			f = pge.Get('F')

			result = fmt.Sprintf("postgres error r: %s l: %s m: %s c: %s s: %s f: %s", r, l, m, c, s, f)
		}
	}

	return result
}