Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于RESTFUL API的数据传递 #10

Closed
scottjeremy opened this issue Nov 22, 2018 · 3 comments
Closed

关于RESTFUL API的数据传递 #10

scottjeremy opened this issue Nov 22, 2018 · 3 comments

Comments

@scottjeremy
Copy link

scottjeremy commented Nov 22, 2018

增加和修改的数据都是通过params来传 这很不利于安全,而且URL长度每个游览器都有所限制。
标签里的标题、状态、创建者都应该放在POST或PUT的body下(其余API同理)
在models下你已经定义了tag的结构体,所以可以直接引用结构体里面的数据类型
下面是我修改过后的AddTags方法:

func AddTags(c *gin.Context) {
	tag := new(models.Tag)
	err := c.Bind(tag)
	if err != nil {
		c.JSON(500,gin.H{
			"state": "初始化失败",
		})
		return
	}
	name := tag.Name
	state := tag.State
	createdBy := tag.CreatedBy

	valid := validation.Validation{}
	valid.Required(name, "name").Message("名称不能为空")
	...........
        ...........
}
@eddycjy
Copy link
Owner

eddycjy commented Nov 25, 2018

@scottjeremy 现在 go-gin-example 这个项目源码中,之前我已经把敏感信息的入参方式都改为走 Body 入参了。先前在文章中大量用 Query 仅仅是为了便于展示。仅此而已

@eddycjy
Copy link
Owner

eddycjy commented Nov 25, 2018

@scottjeremy 另外你不经意提到的更优雅的处理方式。我本次将进行修改,以此达到更好的代码结构

eddycjy added a commit to eddycjy/go-gin-example that referenced this issue Nov 25, 2018
@eddycjy eddycjy closed this as completed Nov 25, 2018
@eddycjy
Copy link
Owner

eddycjy commented Nov 25, 2018

已另行优化,感谢

Wonderex95 added a commit to Wonderex95/go-gin-mongodb that referenced this issue Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants