get users request

This commit is contained in:
cyrus 2024-05-28 22:10:09 +00:00
parent 89397ec70f
commit 1f700048a4
2 changed files with 33 additions and 7 deletions

29
main.go
View File

@ -1,25 +1,40 @@
package main package main
import ( import (
"bytes" "net/http"
"fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func main() { func main() {
router := gin.Default() router := gin.Default()
router.GET("/version", func(c *gin.Context) { router.GET("/version", func(c *gin.Context) {
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"version": "0.0.1", "version": "0.0.1",
}) })
}) })
router.POST("/echo", func(c *gin.Context) { router.GET("/users", func(c *gin.Context) {})
buf := new(bytes.Buffer) router.POST("/users/:userid", func(c *gin.Context) {
buf.ReadFrom(c.Request.Body) var user User
data := buf.String() if err := c.ShouldBind(&user); err != nil {
fmt.Println(data) c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
user.Id = c.Param("userid")
c.JSON(http.StatusOK, user)
}) })
router.GET("/users/:userid", func(c *gin.Context) {})
router.DELETE("/users/:userid", func(c *gin.Context) {})
router.GET("/groups", func(c *gin.Context) {})
router.POST("/groups/:groupid", func(c *gin.Context) {})
router.GET("/groups/:groupid", func(c *gin.Context) {})
router.DELETE("/groups/:groupid", func(c *gin.Context) {})
router.POST("/groups/:groupid/members/:userid", func(c *gin.Context) {})
router.DELETE("/groups/:groupid/members/:userid", func(c *gin.Context) {})
router.Run("0.0.0.0:80") // listen and serve on 0.0.0.0:8080 router.Run("0.0.0.0:80") // listen and serve on 0.0.0.0:8080
} }

11
request_types.go Normal file
View File

@ -0,0 +1,11 @@
package main
type User struct {
Id string
Password string `form:"userpassword" binding:"required"`
CN string `form:"usercn" binding:"required"`
SN string `form:"usersn" binding:"required"`
Resources struct{}
Cluster struct{}
Templates struct{}
}