jincheng9

jincheng9

Member Since 9 years ago

THU,

Experience Points
41
follower
Lessons Completed
70
follow
Lessons Completed
117
stars
Best Reply Awards
36
repos

302 contributions in the last year

Pinned
⚡ 讨论如何构建一套可靠的大型分布式系统
⚡ R API for Crawling Stock and Index Data from Sina Finance
⚡ Notes and Codes from Reading the book "R in Action"
⚡ Digit Recognizer for MNIST Data Set
⚡ C++ Implementation for Affinity Propagation
⚡ Go learning materials
Activity
Dec
4
1 day ago
pull request

jincheng9 pull request gin-gonic/gin

jincheng9
jincheng9

fix: typo

as titled.

push

jincheng9 push jincheng9/gin

jincheng9
jincheng9

TrustedProxies: Add default IPv6 support and refactor (#2967)

jincheng9
jincheng9

Merge branch 'gin-gonic:master' into master

commit sha: 66b30ac3da8139a9bf47ee352ca28ca94d8084dc

push time in 1 day ago
Activity icon
issue

jincheng9 issue comment gin-gonic/gin

jincheng9
jincheng9

<Parameters in path> if param.value lenght < 1,gin should response 404.

Description

path:/user/:id/action/ if requestUrl=="/user//action"; response normal. I think should response 404 or others.

my programme

tree.go

//...
type Param struct {
	Key   string
	Value string
}
//...
func (ps Params) IsEmpty() bool {
	for _, param := range ps {
		if len(param.Value) < 1 {
			return true
		}
	}
	return false
}

gin.go

// Find route in tree
		value := root.getValue(rPath, c.params, c.skippedNodes, unescape)
		if value.params != nil {
			c.Params = *value.params
		}

		if c.Params.IsEmpty() {
			serveError(c, http.StatusNotFound, default404Body)
			return
		}

Of course, I don't think this is the best solution.

jincheng9
jincheng9

@appleboy @thinkerou @manucorporat please help check whether the following scenarios abide the gin desgin: All settings are default, and

  1. set the route rule "/user/:id/action"
  2. request via url "/user//action" result: the gin accepts the url, and the param id is empty string, and return 200. I think the response should be 404.

but if we do this:

  1. set the route rule "/user/:id/action"
  2. request via url "/user//action/" result: the response is 404. It seems the trailing slash redirect does not work.

Plz help clariy the desgin. thanks.

Activity icon
issue

jincheng9 issue comment gin-gonic/gin

jincheng9
jincheng9

<Parameters in path> if param.value lenght < 1,gin should response 404.

Description

path:/user/:id/action/ if requestUrl=="/user//action"; response normal. I think should response 404 or others.

my programme

tree.go

//...
type Param struct {
	Key   string
	Value string
}
//...
func (ps Params) IsEmpty() bool {
	for _, param := range ps {
		if len(param.Value) < 1 {
			return true
		}
	}
	return false
}

gin.go

// Find route in tree
		value := root.getValue(rPath, c.params, c.skippedNodes, unescape)
		if value.params != nil {
			c.Params = *value.params
		}

		if c.Params.IsEmpty() {
			serveError(c, http.StatusNotFound, default404Body)
			return
		}

Of course, I don't think this is the best solution.

jincheng9
jincheng9

@codeHauler-1 If you set RemoveExtraSlash to true, then your request url well be cleaned to "user/1/action", and it match your route rule "/user/:id/action".

Activity icon
issue

jincheng9 issue comment gin-gonic/gin

jincheng9
jincheng9

[Not an issue] Something to feel proud

Gin tutorial in has been featured has been featured in the "12 years of go" blog by Russ Cox and the Go team

https://go.dev/blog/12years

Line in the above blog

One highlight is the new tutorial “Developing a RESTful API with Go and Gin”, which is also available in interactive form using Google Cloud Shell.

jincheng9
jincheng9

@kishaningithub would you please close this issue? Let the open issues be the truly problems we need to address. Thanks.

Activity icon
issue

jincheng9 issue comment gin-gonic/gin

jincheng9
jincheng9

<Parameters in path> if param.value lenght < 1,gin should response 404.

Description

path:/user/:id/action/ if requestUrl=="/user//action"; response normal. I think should response 404 or others.

my programme

tree.go

//...
type Param struct {
	Key   string
	Value string
}
//...
func (ps Params) IsEmpty() bool {
	for _, param := range ps {
		if len(param.Value) < 1 {
			return true
		}
	}
	return false
}

gin.go

// Find route in tree
		value := root.getValue(rPath, c.params, c.skippedNodes, unescape)
		if value.params != nil {
			c.Params = *value.params
		}

		if c.Params.IsEmpty() {
			serveError(c, http.StatusNotFound, default404Body)
			return
		}

Of course, I don't think this is the best solution.

jincheng9
jincheng9

Are you sure your route rule is /user/:id/action, and you use /user//action to request, and the response is normal? For your case, the repsonse should be 404.

Description

path:/user/:id/action/ if requestUrl=="/user//action"; response normal. I think should response 404 or others.

my programme

tree.go

//...
type Param struct {
	Key   string
	Value string
}
//...
func (ps Params) IsEmpty() bool {
	for _, param := range ps {
		if len(param.Value) < 1 {
			return true
		}
	}
	return false
}

gin.go

// Find route in tree
		value := root.getValue(rPath, c.params, c.skippedNodes, unescape)
		if value.params != nil {
			c.Params = *value.params
		}

		if c.Params.IsEmpty() {
			serveError(c, http.StatusNotFound, default404Body)
			return
		}

Of course, I don't think this is the best solution.

Dec
2
3 days ago
started
started time in 3 days ago
Activity icon
issue

jincheng9 issue comment gin-gonic/gin

jincheng9
jincheng9

does gin have a IDL method like proto3 or thrift to define a api service?

Description

does gin have an IDL method like proto3 or thrift to define a api service?

for example , i have an echo api i want to define it like before does gin has an IDL tool to generate basic code including field verify, model generate?

message EchoRequest{
  string content = 1;   
}
message EchoData{
 string content = 1;
}
message EchoResponse{
 int status = 1;
 string message = 2;
 EchoData data = 3;   
}
service{
api EchoResponse Echo(EchoRequest )(api.get='/echo')
}
jincheng9
jincheng9

@SpringTY Gin does not have this kind of stuff.

started
started time in 3 days ago
Previous