Skip to content

Commit

Permalink
Edit: example
Browse files Browse the repository at this point in the history
  • Loading branch information
MrXu committed Apr 16, 2016
1 parent 4bf27e1 commit 7d211d3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
)

func TestController(c *gin.Context) {
c.String(200, "from test controller/n")
c.JSON(http.StatusOK, gin.H{
"greeting":"hello go",
})
}

func TestJsonController(c *gin.Context) {
Expand All @@ -17,8 +19,7 @@ func TestJsonController(c *gin.Context) {
}
user := userAccount.(*auth.UserAccount)
c.JSON(200, gin.H{
"name": "jason",
"action": "work",
"greeting": "hello world",
"email":user.Id,
})
}
12 changes: 10 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,17 @@ func main() {
/*
api requiring authentication
*/
private := r.Group("/api/auth")
private := r.Group("/api/private")
private.Use(auth.TokenAuthMiddleware)
private.GET("/action", controller.TestJsonController)
private.GET("/example", controller.TestJsonController)


/*
api not requiring authentication
*/
public := r.Group("/api/public")
public.GET("/example", controller.TestController)



r.Run(":8080") // listen and serve on 0.0.0.0:8080
Expand Down

0 comments on commit 7d211d3

Please sign in to comment.