29 lines
539 B
Go
29 lines
539 B
Go
package routes
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"example.com/rest-api/models"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func signup(context *gin.Context) {
|
|
var user models.User
|
|
|
|
err := context.ShouldBindJSON(&user)
|
|
|
|
if err != nil {
|
|
context.JSON(http.StatusBadRequest, gin.H{"message": "Could not parse request data."})
|
|
return
|
|
}
|
|
|
|
err = user.Save()
|
|
|
|
if err != nil {
|
|
context.JSON(http.StatusInternalServerError, gin.H{"message": "Could not save user."})
|
|
return
|
|
}
|
|
|
|
context.JSON(http.StatusCreated, gin.H{"message": "User created successfully"})
|
|
}
|