forked from gothinkster/golang-gin-realworld-example-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_handler_struct.go
81 lines (60 loc) · 1.62 KB
/
user_handler_struct.go
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"net/http"
"strconv" //for Atoi conv
"gopkg.in/gin-gonic/gin.v1"
)
func HandleLogin(context *gin.Context) {
var LoginInfo LoginForm
context.BindJSON(&LoginInfo)
var newUser User
newUser.Name = LoginInfo.Username
context.JSON(http.StatusOK, newUser)
}
type LoginForm struct {
Username string `json:"username"`
Password string `json:"password"`
}
type RegistrationForm struct {
LoginForm
Email string `json:"email"`
}
func HandleAddProject(context *gin.Context) {
userId := context.Param("id")
userIdint, _ := strconv.Atoi(userId)
//var ProjectInfo ProjectTest
ProjectInfo := struct {
Name string
Entries []ID
Participants struct {
Participants []ID
}
}{}
context.BindJSON(&ProjectInfo)
newProject := ProjectInfo
//newProject.Participants.Participants = append([]ID(newProject.Participants.Participants), ID(userIdint))
newProject.Participants.Participants = append([]ID(newProject.Participants.Participants), ID(userIdint))
context.Header("Content-Type", "application/json")
context.JSON(http.StatusOK, newProject)
}
func HandleGetProjects(context *gin.Context) {
userId := context.Param("id")
userIdint, _ := strconv.Atoi(userId)
var Projects []ProjectTest
Projects = []ProjectTest{
{
Name: "Server sideproject",
Participants: Participation{[]ID{ID(userIdint)}},
},
}
context.Header("Content-Type", "application/json")
context.JSON(http.StatusOK, Projects)
}
/*
func handleUser( c *gin.Context ){
}
funct ( self *UserHandler ) bindToAddress( address string ){
self.GET("", self.HandleUser)
}
funct ( self *UserHandler ) getHandlers() func
*/