-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogin_controller.go
More file actions
38 lines (31 loc) · 935 Bytes
/
login_controller.go
File metadata and controls
38 lines (31 loc) · 935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package controllers
import (
"github.com/gin-gonic/gin"
"net/http"
)
// LoginController is a struct to define the login controller
type LoginController struct {
}
// NewLoginController is a function to create a new login controller
func NewLoginController() *LoginController {
return &LoginController{}
}
// LoginRequest is a struct to define the login request
type LoginRequest struct {
Message string `json:"message" binding:"required"`
}
// LoginResponse is a struct to define the login response
type LoginResponse struct {
Message string `json:"message"`
}
// Login is a function to handle the login request
func (controller *LoginController) Login(c *gin.Context) {
var request LoginRequest
if err := c.ShouldBindJSON(&request); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
var response LoginResponse
response.Message = "Login successful"
c.JSON(http.StatusOK, response)
}