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,36 @@
package utils
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/gravitl/netmaker/turnserver/internal/models"
)
// ReturnSuccessResponse - success api response
// ReturnSuccessResponse - success api response
func ReturnSuccessResponse(c *gin.Context, message string, responseBody interface{}) {
var httpResponse models.SuccessResponse
httpResponse.Code = http.StatusOK
httpResponse.Message = message
httpResponse.Response = responseBody
if httpResponse.Response == nil {
httpResponse.Response = struct{}{}
}
c.Writer.Header().Set("Content-Type", "application/json")
c.JSON(http.StatusOK, httpResponse)
}
// ReturnErrorResponse - error api response
func ReturnErrorResponse(c *gin.Context, errorMessage models.ErrorResponse) {
httpResponse := &models.ErrorResponse{Code: errorMessage.Code, Message: errorMessage.Message}
c.Writer.Header().Set("Content-Type", "application/json")
c.JSON(errorMessage.Code, httpResponse)
}
// AbortWithError - abort api request with error
func AbortWithError(c *gin.Context, errorMessage models.ErrorResponse) {
httpResponse := &models.ErrorResponse{Code: errorMessage.Code, Message: errorMessage.Message}
c.Writer.Header().Set("Content-Type", "application/json")
c.AbortWithStatusJSON(errorMessage.Code, httpResponse)
}