24 lines
364 B
Go
24 lines
364 B
Go
|
package utils
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
func ErrorToHTTPCode(err error, gone bool) int {
|
||
|
switch {
|
||
|
case os.IsPermission(err):
|
||
|
return http.StatusForbidden
|
||
|
case os.IsNotExist(err):
|
||
|
if !gone {
|
||
|
return http.StatusNotFound
|
||
|
}
|
||
|
|
||
|
return http.StatusGone
|
||
|
case os.IsExist(err):
|
||
|
return http.StatusGone
|
||
|
default:
|
||
|
return http.StatusInternalServerError
|
||
|
}
|
||
|
}
|