25 lines
500 B
Go
25 lines
500 B
Go
package controllers
|
|
|
|
import (
|
|
"gitea.zjmud.xyz/phyer/rbac/models"
|
|
"gitea.zjmud.xyz/phyer/rbac/services"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func CreateRole(c *gin.Context) {
|
|
var role models.Role
|
|
if err := c.ShouldBindJSON(&role); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
if err := services.CreateRole(&role); err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusCreated, role)
|
|
}
|