api handlers to register and unregister host from turn,added dockerfile

This commit is contained in:
Abhishek Kondur
2023-04-05 13:02:14 +04:00
parent 7f0c147e80
commit d96360565b
15 changed files with 367 additions and 23 deletions

View File

@@ -0,0 +1,48 @@
package errors
import (
"net/http"
"github.com/gravitl/netmaker/turnserver/internal/models"
)
type ApiRespErr string
const (
Internal ApiRespErr = "internal"
BadRequest ApiRespErr = "badrequest"
NotFound ApiRespErr = "notfound"
UnAuthorized ApiRespErr = "unauthorized"
Forbidden ApiRespErr = "forbidden"
Unavailable ApiRespErr = "unavailable"
)
// FormatError - formats into api error resp
func FormatError(err error, errType ApiRespErr) models.ErrorResponse {
var status = http.StatusInternalServerError
switch errType {
case Internal:
status = http.StatusInternalServerError
case BadRequest:
status = http.StatusBadRequest
case NotFound:
status = http.StatusNotFound
case UnAuthorized:
status = http.StatusUnauthorized
case Forbidden:
status = http.StatusForbidden
case Unavailable:
status = http.StatusServiceUnavailable
default:
status = http.StatusInternalServerError
}
var response = models.ErrorResponse{
Code: status,
}
if err != nil {
response.Message = err.Error()
}
return response
}