Commit Graph

1470 Commits

Author SHA1 Message Date
田欧
6c6d97ba2e remove hardcode instead of http status value (#1411) 2018-06-26 17:21:32 +08:00
田欧
1f59bad84b add an edge case from httprouter (#1407) 2018-06-23 11:06:27 +08:00
田欧
760d0574db vendor: remove vendor package from example folder (#1402)
updated `vendor.json` is ok.
but set `ignore test` in `vendor.json`, `x/net/context` package only use in `context_test.go`, I don't know why vendor still need it.
please @appleboy review the pull request, thanks a lot.
2018-06-23 00:45:43 +08:00
田欧
8035359102 use strings.Split instead of strings.IndexByte (#1406) 2018-06-23 00:08:58 +08:00
田欧
605aa1c30f example: fix typo for grpc (#1405)
sorry...fixed #1403
2018-06-22 23:44:45 +08:00
田欧
737d2fb7ab add grpc example (#1401)
use grpc helloworld example.
2018-06-22 09:51:06 +08:00
htobenothing
bf85b32c1d Add Pusher() function for support http2 server push (#1273)
gin already support http2, while previously not support server push.
Add Pusher() function to extend the ResponseWriter interface.

```golang
// get http.Pusher
 if pusher := c.Writer.Pusher(); pusher != nil {
     // use pusher.Push() to do server push
}
```
<img width="881" alt="screen shot 2018-03-07 at 11 20 49 pm" src="https://user-images.githubusercontent.com/16014993/37100619-680c00c6-225e-11e8-9352-76ec3bd62894.png">
2018-06-21 09:53:52 +08:00
田欧
87d536c001 utils: use strings.Split instead of strings.IndexByte (#1400)
And I test them benchmark:

code:

```go
# stringsbench.go
package stringsbench

import "strings"

func index(part string) string {
	if index := strings.IndexByte(part, ';'); index >= 0 {
		if part := strings.TrimSpace(strings.Split(part, ";")[0]); part != "" {
			return part[0:index]
		}
	}
	return ""
}

func split(part string) string {
	return strings.Split(part, ";")[0]
}
```

```go
# stringsbench_test.go
package stringsbench

import (
	"testing"
)

func BenchmarkIndex(b *testing.B) {
	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			index("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
		}
	})
}

func BenchmarkSplit(b *testing.B) {
	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			split("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
		}
	})
}
```

And the result:

```shell
➜  strings go test --bench=.
goos: darwin
goarch: amd64
BenchmarkIndex-8   	30000000	        46.1 ns/op
BenchmarkSplit-8   	50000000	        35.9 ns/op
PASS
ok  	_/Users/tianou/strings	3.271s
➜  strings go test --bench=.
goos: darwin
goarch: amd64
BenchmarkIndex-8   	30000000	        44.2 ns/op
BenchmarkSplit-8   	50000000	        34.7 ns/op
PASS
ok  	_/Users/tianou/strings	3.156s
➜  strings go test --bench=.
goos: darwin
goarch: amd64
BenchmarkIndex-8   	30000000	        45.6 ns/op
BenchmarkSplit-8   	50000000	        35.3 ns/op
PASS
ok  	_/Users/tianou/strings	3.230s
```
2018-06-21 09:31:43 +08:00
田欧
caf3e350a5 doc: update readme for adding binding about skip validate (#1359)
* update readme for adding binding about skip validate

* update readme for adding binding about skip validate
2018-05-31 14:13:40 +08:00
MW Lim
c2f083fc95 minor typo in routergroup.go (#1360) 2018-05-31 11:41:45 +08:00
chainhelen
07cbe116a0 Add and fix the explanation of HandleContext (#1371)
Reference this issue #1323 

1. There isn't any eg about `HandleContext`  
2. The `c.Request.Path`  of `HandleContext` Comment  is not right   

Based on the above two points, I pull this request.  
If you think it's unnecessary, I will close this.  
Thx.
2018-05-30 09:19:04 +08:00
Jean-Christophe Lebreton
bf7803815b Serve easily dynamic files with DataFromReader context method (#1304)
* Add DataFromReader context method

* Replace fmt by strconv.FormatInt

* Add pull request link to README
2018-05-12 11:00:42 +08:00
chainhelen
5636afe02d fix bug, return err when failed binding bool (#1350)
* fix bug, return err when failed binding bool

* add test, return err when failed binding bool
2018-05-11 22:40:33 +08:00
JINNOUCHI Yasushi
995fa8e9ce Fix #216: Enable to call binding multiple times in some formats (#1341)
* Add interface to read body bytes in binding

* Add BindingBody implementation for some binding

* Fix to use `BindBodyBytesKey` for key

* Revert "Fix to use `BindBodyBytesKey` for key"

This reverts commit 2c82901ceab6ae53730a3cfcd9839bee11a08f13.

* Use private-like key for body bytes

* Add tests for BindingBody & ShouldBindBodyWith

* Add note for README

* Remove redundant space between sentences
2018-05-11 10:33:33 +08:00
Aurelien Regat-Barrel
6e09ef03b0 Fix typo in panic() message (extra single quote) (#1352)
Also fix the same typo in a comment
2018-05-11 09:57:21 +08:00
田欧
bd4f73af67 support struct pointer (#1342)
* support struct pointer

* add readme
2018-05-01 14:24:18 +08:00
Alexander Lokhman
2282be059b Add support of pointers in form binding (#1336)
* Add support of pointers in form binding

* Add tests for pointer form binding
2018-04-26 22:09:34 +08:00
senhtry
8c24018290 Add Jsonp Support to Context (#1333) 2018-04-26 11:52:19 +08:00
田欧
41f951e0cd support default value for form (#1138)
* support default value for form

* fix bug for nil interface

* use SplitN and optimization code

* add test case

* add test cases for form(own default value)

* fix invalid code

* fix code indent

* assert order
2018-04-25 16:24:03 +08:00
JINNOUCHI Yasushi
814ac9490a Add example to build single binary with templates (#1328) 2018-04-22 15:04:38 +08:00
田欧
dfe37ea6f1 unify assert.Equal usage (#1327)
* unify assert.Equal usage

* fix typo
2018-04-20 10:27:44 +08:00
田欧
248c522e4a Add Contents for README because it too long (#1325) 2018-04-20 09:54:00 +08:00
esplo
3455d7f388 change README for app-engine example because of goapp deprecation (#1324)
the App Engine SDK is superseded by the Cloud SDK
2018-04-19 12:00:22 +08:00
Yoshiyuki Kinjo
6ad7b9c9d3 Fix documentation typo (#1321) 2018-04-17 10:54:40 +08:00
Suhas Karanth
6d913fc343 fix(binding): Expose validator engine used by the default Validator (#1277)
* fix(binding): Expose validator engine used by the default Validator

- Add func ValidatorEngine for returning the underlying validator engine used
  in the default StructValidator implementation.
- Remove the function RegisterValidation from the StructValidator interface
  which made it immpossible to use a StructValidator implementation without the
  validator.v8 library.
- Update and rename test for registering validation
  Test{RegisterValidation => ValidatorEngine}.
- Update readme and example for registering custom validation.
- Add example for registering struct level validation.
- Add documentation for the following binding funcs/types:
  - Binding interface
  - StructValidator interface
  - Validator instance
  - Binding implementations
  - Default func

* fix(binding): Move validator engine getter inside interface

* docs: rm date cmd from custom validation demo
2018-03-29 14:33:07 +08:00
hellojukay
65a65c2edd add gin panic time log (#1270)
* add gin pinic time log

* Update recovery.go
2018-03-20 14:42:51 +08:00
Romain Beuque
3e3f9bca81 doc(graceful-shutdown): failure to ListenAndServe should be a reason to exit (#1287)
Signed-off-by: Romain Beuque <romain.beuque@gmail.com>
2018-03-20 14:05:24 +08:00
Mario Kostelac
5d3f30cfc8 Make "" mode being the same as debug mode (#1250)
Not setting mode explicitly sets gin into debug mode, but it does not
make it possible to retrieve gin mode as Debug since it's set to "".
2018-02-23 09:09:33 +08:00
README Bot
cbb1ee80b1 Add CodeTriage badge to gin-gonic/gin (#1249)
Adds a badge showing the number of people helping this repo on CodeTriage.

[![Open Source Helpers](https://www.codetriage.com/gin-gonic/gin/badges/users.svg)](https://www.codetriage.com/gin-gonic/gin)

## What is CodeTriage?

CodeTriage is an Open Source app that is designed to make contributing to Open Source projects easier. It works by sending subscribers a few open issues in their inbox. If subscribers get busy, there is an algorithm that backs off issue load so they do not get overwhelmed

[Read more about the CodeTriage project](https://www.codetriage.com/what).

## Why am I getting this PR?

Your project was picked by the human, @schneems. They selected it from the projects submitted to https://www.codetriage.com and hand edited the PR. How did your project get added to [CodeTriage](https://www.codetriage.com/what)? Roughly 6 months ago, [dinsaw](https://github.com/dinsaw) added this project to CodeTriage in order to start contributing. Since then, 5 people have subscribed to help this repo.

## What does adding a badge accomplish?

Adding a badge invites people to help contribute to your project. It also lets developers know that others are invested in the longterm success and maintainability of the project.

You can see an example of a CodeTriage badge on these popular OSS READMEs:

- [![](https://www.codetriage.com/rails/rails/badges/users.svg)](https://www.codetriage.com/rails/rails) https://github.com/rails/rails
- [![](https://www.codetriage.com/crystal-lang/crystal/badges/users.svg)](https://www.codetriage.com/crystal-lang/crystal) https://github.com/crystal-lang/crystal

## Have a question or comment?

While I am a bot, this PR was manually reviewed and monitored by a human - @schneems. My job is writing commit messages and handling PR logistics.

If you have any questions, you can reply back to this PR and they will be answered by @schneems. If you do not want a badge right now, no worries, close the PR, you will not hear from me again.

Thanks for making your project Open Source! Any feedback is greatly appreciated.
2018-02-22 21:28:50 +08:00
Eason Lin
ae22f0c870 chore(travis): add 1.10 version (#1256) 2018-02-22 21:00:20 +08:00
田欧
783c7ee9c1 Add some test cases and run test cases on binding/render dir (#1168)
* Travis run test cases on binding and render dir and add some test cases for binding and render
2018-01-26 11:46:11 +08:00
Bo-Yi Wu
2fbb97117c
fix(build): remove unused target. (#1183) 2018-01-24 11:06:42 +08:00
MW Lim
7a9a290b36 minor typo in README.md (#1219) 2018-01-23 10:36:36 +08:00
Kevin Zhu
8a6792d516 Fix README.md example code (#1231)
r -> router
2018-01-23 10:07:33 +08:00
Weilin Shi
a712f77d7a Fix some golint warnings in gin.go (#1215) 2017-12-29 17:10:28 +08:00
Weilin Shi
6626358d4f Fix golint warnings in utils.go (#1209) 2017-12-25 13:58:02 +08:00
Weilin Shi
a816f9e9db Remove redundant if err != nil check (#1202)
* Remove redundant if err != nil check

* Return e.EncodeToken instead of create a new variable
2017-12-21 11:00:17 +08:00
Levi Olson
05547037e4 Minor grammatical correction in README (#1206) 2017-12-21 10:48:11 +08:00
Himanshu Mishra
46662e700b Doc: Fix typo in documentation of Bind (#1204) 2017-12-20 09:32:39 +08:00
田欧
b70b8ab20c use lower if the struct is private (#1185) 2017-12-17 13:02:33 +08:00
TaeJun Park
25e7cd75ed Update README.md (#1188)
change path from '~/go/...' to '$GOPATH/...'
2017-12-17 08:05:30 +08:00
Max Hilbrunner
13a40fcd2c README: Small update to clarify on Goroutines (#1199) 2017-12-17 00:52:07 +08:00
田欧
9e895470dd add deprecated test case (#1176)
* add deprecated test case

* swap assert param

* remove
2017-11-29 16:42:51 +08:00
Boris Borshevsky
6f94fd05c9 Linting and optimizing struct memory signature. (#1184)
* fix cleanPath spell (#969)

* linter and optimize structs
2017-11-29 10:50:14 +08:00
田欧
eeb57848ca update assert param(expect, actual) position (#1177) 2017-11-21 21:18:45 +08:00
田欧
7e5aff8ea7 simple code and increase coverage (#1174) 2017-11-21 10:03:57 +08:00
田欧
1f377cb847 Add test cases for RunTLS and each mode (#1173)
* add RunTLS test cases and add debug/test mode cases

* add release mode cases
2017-11-21 09:27:57 +08:00
Richard Lee
ae9f03e6e8 Fix up syntax error in README (#1155) 2017-11-11 23:56:59 -06:00
Andrii Bubis
80f691159f Added simple testing documentation and examples (#1156) 2017-11-11 23:37:32 -06:00
田欧
9a4ecc87d6 format some codes style (#1165) 2017-11-11 23:24:51 -06:00