Created
December 14, 2019 11:02
-
-
Save patricksuo/15871d4800dee5dc9f729197474e3085 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"github.com/gin-gonic/gin" | |
) | |
func main() { | |
engine := gin.Default() | |
_ = engine | |
projects := engine.Group("/projects") | |
projects.GET("/:project_id", GetProjectDetail) | |
projects.GET("/", QueryProjects) | |
projects.GET("/:project_id/issues", QueryIssues) | |
projects.GET("/:project_id/issues/:issue_id", GetIssuesDetail) | |
projects.GET("/:project_id/members", QueryMembers) | |
projects.GET("/:project_id/members/:member_is", GetMemberDetail) | |
err := engine.Run("localhost:7777") | |
if err != nil { | |
log.Fatalf("engine.Run err: %v", err) | |
} | |
} | |
func QueryIssues(c *gin.Context) { | |
var ( | |
param struct { | |
ProjectID int64 `uri:"project_id" binding:"required"` | |
} | |
) | |
if err := c.BindUri(¶m); err != nil { | |
return | |
} | |
c.JSON(200, param) | |
} | |
func GetIssuesDetail(c *gin.Context) { | |
var ( | |
param struct { | |
ProjectID int64 `uri:"project_id" binding:"required"` | |
IssueID int64 `uri:"issue_id" binding:"required"` | |
} | |
) | |
if err := c.BindUri(¶m); err != nil { | |
return | |
} | |
c.JSON(200, param) | |
} | |
func QueryMembers(c *gin.Context) { | |
var ( | |
param struct { | |
ProjectID int64 `uri:"project_id" binding:"required"` | |
} | |
) | |
if err := c.BindUri(¶m); err != nil { | |
return | |
} | |
c.JSON(200, param) | |
} | |
func GetMemberDetail(c *gin.Context) { | |
var ( | |
param struct { | |
ProjectID int64 `uri:"project_id" binding:"required"` | |
MemberID int64 `uri:"member_id" binding:"required"` | |
} | |
) | |
if err := c.BindUri(¶m); err != nil { | |
return | |
} | |
c.JSON(200, param) | |
} | |
func GetProjectDetail(c *gin.Context) { | |
var ( | |
param struct { | |
ProjectID int64 `uri:"project_id" binding:"required"` | |
} | |
) | |
if err := c.BindUri(¶m); err != nil { | |
return | |
} | |
c.JSON(200, param) | |
} | |
func QueryProjects(c *gin.Context) { | |
c.JSON(200, "query project") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment