hiling_go/api/user.go

28 lines
550 B
Go

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)
}