hiling_go/api/user.go

28 lines
550 B
Go
Raw Normal View History

2023-09-08 22:25:38 +07:00
package api
import (
"net/http"
"github.com/gin-gonic/gin"
)
type CreateUserRequest struct {
ClientIpV4 string `json:"client_ip" binding:"required"`
}
func (server *Server) createUser(ctx *gin.Context) {
var req CreateUserRequest
if err := ctx.ShouldBindJSON(&req); err != nil {
ctx.JSON(http.StatusBadRequest, errorResponse(err, ""))
return
}
err := server.store.CreateUser(ctx, req.ClientIpV4)
if err != nil {
ctx.JSON(http.StatusInternalServerError, errorResponse(err, ""))
return
}
ctx.Writer.WriteHeader(http.StatusOK)
}