Commit Graph

354 Commits

Author SHA1 Message Date
Bo-Yi Wu
05464a8f6b
docs: update benchmark result v1.6.3 (#2355) 2020-05-05 16:37:40 +08:00
thinkerou
747efffd2a
chore: update godoc address (#2357) 2020-05-05 14:06:42 +08:00
Shilin Wang
4f208887e1
update set cookie example (#2312)
fix #2308
2020-04-08 23:31:31 +08:00
Igor H. Vieira
c4fd2489ce
Improved the graceful shutdown and restart section and removed… (#2288) 2020-03-22 10:25:35 +08:00
Nikifor Seryakov
1d055af1bc
FileFromFS (#2112)
* Context.FileFromFS added

* Context File and FileFromFS examples at README

Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-03-07 10:23:33 +08:00
Bo-Yi Wu
863ad2d4de
docs(badge): add todo badge (#2240)
fix https://github.com/gin-gonic/gin/issues/2236

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-02-21 16:33:36 +08:00
Andy Pan
07c0f05f24 Renew README to fit the modification of SetCookie method (#2217)
fix #2214
2020-01-23 07:54:08 +08:00
John Bampton
59ab588bf5 Remove broken link from README. (#2198) 2019-12-30 21:55:08 +08:00
Lin Kao-Yuan
9b3477ef9d Update validator to v10 (#2190)
Passed my manual test, output nothing different.
2019-12-20 14:01:58 +08:00
飞雪无情
cc14a770cd upgrade go-validator to v10 for README (#2189) 2019-12-19 11:21:58 +08:00
Lin Kao-Yuan
1b480ed294 Update to currently output (#2188)
Excuse me, I forgot change output in #2186
2019-12-18 21:08:58 +08:00
Lin Kao-Yuan
aee83e040b Fix "Custom Validators" example (#2186)
* Update fixed error code from merged commit

According to [this](874dcfa6c4) merged commit.

* Fixed incorrect testing date.

Original testing date incompatible demo require, can't get expect result.
check_in date need NOT AFTER check_out date.
2019-12-18 09:44:33 +08:00
Victor Castell
77b8344169 Add project to README (#2165)
Add Dkron as user of Gin in the README
2019-12-02 20:59:56 +08:00
thinkerou
3c8e29b53c
drop support govendor (#2148) 2019-11-25 15:42:23 +08:00
BradyBromley
3737520f17 Changed wording for clarity in README.md (#2122) 2019-11-25 11:03:36 +08:00
thinkerou
2ee0e96394 Drop support go1.10 (#2147) 2019-11-24 23:07:56 +08:00
Ildar1111
089016a092 Update README.md (#2106)
* Update README.md

c:\>curl 0.0.0.0:8080
"Failed to connect to 0.0.0.0 port 8080: Address not available"
Connecting to address 0.0.0.0:8080 is not allowed on windows. From http://msdn.microsoft.com/en-us/library/aa923167.aspx

" ... If the address member of the structure specified by the name parameter is
all zeroes, connect will return the error WSAEADDRNOTAVAIL. ..."

* Update README.md

edit comment
2019-10-25 10:03:53 +08:00
John Bampton
4fd3234840 Fix spelling. (#2080) 2019-10-03 07:46:41 +08:00
bullgare
9b9f4fab34 Updated Readme.md: file.Close() for template read (#2068) 2019-09-24 22:18:41 +08:00
bullgare
f45c83c70c Updated Readme.md for serving multiple services (#2067)
Previous version had issues - if one service did not start for any reason, you would never know about it.
2019-09-23 23:48:10 +08:00
Jim Filippou
b80d675864 Added specific installation instructions for Mac (#2011)
Made it more clear for Mac users using Go version 1.8 and greater.
2019-09-05 21:50:54 +08:00
Johnny Dallas
6ece26c7c5 Add Header bind methods to README (#2025) 2019-08-30 10:58:55 +08:00
guonaihong
502c898d75 binding: support unix time (#1980)
* binding: support unix time

ref:#1979

* binding: support unix time

add test file
modify readme

```golang
package main

import (
        "fmt"
        "github.com/gin-gonic/gin"
        "time"
)

type shareTime struct {
        CreateTime time.Time `form:"createTime" time_format:"unixNano"`
        UnixTime   time.Time `form:"unixTime" time_format:"unix"`
}

func main() {
        r := gin.Default()
        unix := r.Group("/unix")

        testCT := time.Date(2019, 7, 6, 16, 0, 33, 123, time.Local)
        fmt.Printf("%d\n", testCT.UnixNano())

        testUT := time.Date(2019, 7, 6, 16, 0, 33, 0, time.Local)
        fmt.Printf("%d\n", testUT.Unix())

        unix.GET("/nano", func(c *gin.Context) {
                s := shareTime{}

                c.ShouldBindQuery(&s)

                if !testCT.Equal(s.CreateTime) {
                        c.String(500, "want %d got %d", testCT.UnixNano(), s.CreateTime)
                        return
                }

                c.JSON(200, s)
        })

        unix.GET("/sec", func(c *gin.Context) {
                s := shareTime{}

                c.ShouldBindQuery(&s)

                if !testUT.Equal(s.UnixTime) {
                        c.String(500, "want %d got %d", testCT.Unix(), s.UnixTime)
                        return
                }

                c.JSON(200, s)

        })

        r.Run()
}

```

* Contraction variable scope
2019-07-10 13:02:40 +08:00
thinkerou
3f53a58d4a
Add user case: brigade (#1937) 2019-06-29 00:09:53 +08:00
Dan Markham
fc920dc561 Drop Support for go1.8 and go1.9 (#1933) 2019-06-28 23:43:07 +08:00
srt180
46acb91996 modify readme example code (#1961) 2019-06-28 09:34:14 +08:00
guonaihong
31342fc03f fix README.md code bug and Change map to gin.H (#1963)
``` go
func main() {
        r := gin.Default()

        // r.GET("/JSONP?callback=x", func(c *gin.Context) { // old
        r.GET("/JSONP", func(c *gin.Context) {    // new
                data := gin.H{
                        "foo": "bar",
                }

                //callback is x
                // Will output  :   x({\"foo\":\"bar\"})
                c.JSONP(http.StatusOK, data)
        })

        // Listen and serve on 0.0.0.0:8080
        r.Run(":8080")
}

// client
// curl http://127.0.0.1:8080/JSONP?callback=x

// old output
// 404 page not found

// new output
// x({"foo":"bar"})

```

Most of the sample code in the documentation map[string]interface{} is represented by gin.H.
gin.H is a very important place for me to like gin, can write a lot less code
2019-06-28 09:25:19 +08:00
guonaihong
f98b339b77 support bind http header param #1956 (#1957)
* support bind http header param #1956

update #1956
```
package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
)

type testHeader struct {
	Rate   int    `header:"Rate"`
	Domain string `header:"Domain"`
}

func main() {
	r := gin.Default()
	r.GET("/", func(c *gin.Context) {
		h := testHeader{}

		if err := c.ShouldBindHeader(&h); err != nil {
			c.JSON(200, err)
		}

		fmt.Printf("%#v\n", h)
		c.JSON(200, gin.H{"Rate": h.Rate, "Domain": h.Domain})
	})

	r.Run()

// client
// curl -H "rate:300" -H "domain:music" 127.0.0.1:8080/
// output
// {"Domain":"music","Rate":300}
}
```

* add unit test

* Modify the code to get the http header

When the http header is obtained in the standard library,
the key value will be modified by the CanonicalMIMEHeaderKey function,
and finally the value of the http header will be obtained from the map.
As follows.
```go
func (h MIMEHeader) Get(key string) string {
        // ...
         v := h[CanonicalMIMEHeaderKey(key)]
        // ...
}
```

This pr also follows this modification

* Thanks to vkd for suggestions, modifying code

* Increase test coverage

env GOPATH=`pwd` go test github.com/gin-gonic/gin/binding -coverprofile=cover.prof
ok  	github.com/gin-gonic/gin/binding	0.015s	coverage: 100.0% of statements

* Rollback check code

* add use case to README.md
2019-06-27 12:47:45 +08:00
Dmitry Kutakov
09a3650c97 binding: add support of multipart multi files (#1878) (#1949)
* binding: add support of multipart multi files (#1878)

* update readme: add multipart file binding
2019-06-18 19:49:10 +08:00
Roman Zaynetdinov
35e33d3638 Hold matched route full path in the Context (#1826)
* Return nodeValue from getValue method

* Hold route full path in the Context

* Add small example
2019-05-26 08:20:21 +08:00
ZYunH
78a8b5c9d5 Fix typo (#1913) 2019-05-23 11:37:34 +08:00
田欧
965d74cebb
add dev version (#1886)
* add dev version

* Update version.go

* Update version.go
2019-05-12 18:47:27 +08:00
田欧
5a7e3095b2 Update README.md about go version (#1885) 2019-05-08 11:10:34 +08:00
Dan Markham
094f9a9105 v1.4.0 + #1631 (remove go1.6/go1,7 support) (#1851)
* remove go1.6 support

* remove build tag

* remove todo

* remove go1.6 support: https://github.com/gin-gonic/gin/pull/1383/commits

* update readme

* remove go1.7 support

* fix embedmd error

* test

* revert it

* revert it

* remove context_17

* add pusher test

* v1.4.0 rc1
2019-05-07 18:32:32 +08:00
DeathKing
202f8fc58a Fix a typo syscanll.SIGTERM -> syscall.SIGTERM (#1868) 2019-04-24 20:21:41 +08:00
Eason Lin
ffcbe77b1e chore(readme): rollback readme (#1846)
#1844 #1838 
Keep the documentation in readme until full available on the new website.
2019-04-06 21:48:33 +08:00
田欧
0c1f3c4e81 chore: fix invalid link (#1820) 2019-03-20 12:07:34 +08:00
Sai
242a2622c8 Fix Japanese text hiragana -> kanji (#1812) 2019-03-14 16:26:51 +08:00
田欧
cab0749b4f
chore: update readme (#1793)
* update readme

* add multi-language version doc link

* add multi-language version doc link

* update readme

* update

* update readme

* update readme

* update readme
2019-03-14 13:23:35 +08:00
田欧
e5261480fd
chore(readme.md): fix invalid link (#1807) 2019-03-12 14:01:12 +08:00
Kumar McMillan
f8f1459619 Fix URL to starter template in the docs (#1795) 2019-03-04 08:06:46 +08:00
Dmitry Kutakov
0d50ce8597 refactor(form_mapping.go): mapping ptr, struct and map (#1749)
* refactor(form_mapping.go): mapping ptr, struct and map

* fix #1672 correct work with ptr - not create value if field is not set
* avoid allocations on strings.Split() - change to strings.Index()
* fix #610 tag value "-" is mean ignoring field
* struct fields mapped like json.Unmarshal
* map fields mapped like json.Unmarshal

* fix after @thinkerou review
2019-03-03 14:39:43 +08:00
Bo-Yi Wu
3b84a430d0 Drone switch from gin to go-chi in 1.0 version. (#1790) 2019-03-02 20:19:42 +08:00
田欧
8c8002d744 chore: add examples repo link to README (#1788) 2019-03-02 19:21:10 +08:00
Dang Nguyen
688eb1281c update examples link in README (#1789) 2019-03-02 16:04:21 +08:00
田欧
0feaf8cbd8
Split examples to alone repo (#1776)
* split examples to alone repo

* vendor

* fix package error

* add examples/README.md
2019-03-01 23:42:41 +08:00
Olivier Robardet
a58a2f9bf3 Add a function to force color in console output (#1724)
Add a function `ForceConsoleColor`, like `DisableConsoleColor` but to force coloring the output.

It usefull when some IDE's integrated console (like IntelliJ or Goland) are not detected as TTY, but can display colors.

Also helps if one want to output color in log file (#1590) and as a workaround for #1547.
2019-02-20 21:14:16 +08:00
ffhelicopter
90587c7787 Update: examples/graceful-shutdown/server.go (#1530)
* Update server.go

It's necessary that  catching  ctx.Done()

* Update server.go

* Update server.go

* Update README.md

* Update README.md
2019-02-20 13:24:29 +08:00
awkj
5846ceba8b add notify accept signal (#1740)
* add notify accept signal

* add import

* update readme,keep same with example
2019-02-20 00:02:37 +08:00
Ryan
f38a3fe65f fix password error (#1728) 2019-01-20 18:27:04 +08:00
Ganlv
1542eff27f Fix #1693: file.Filename should not be trusted (#1699) 2018-12-17 08:13:07 +08:00
Sai
f76ccb25f1 Add LoggerWithFormatter method (#1677)
* Add LoggerWithFormatter

* Add tests for LoggerWithFormatter & LoggerWithConfig

* Add note for README

* Add tests for DefaultLogFormatter

* Add comment

* Change DefaultLogFormatter to a private method
2018-12-12 09:05:16 +08:00
thinkerou
687d8b9ac6 add picfit to gin user list (#1661)
agreed with the project's author.
cc @thoas
thanks!
2018-11-25 20:52:46 +08:00
thinkerou
331af2219c add krakend to gin user list (#1658) 2018-11-24 13:49:26 +01:00
thinkerou
521d06c81d support bind uri param (#1612)
* support bind uri (1)

* uri binding successful run

* fix vet warning: github.com/gin-gonic/gin/internal.Param composite literal uses unkeyed fields

* fix code style

* update function name

* fix test function signature

* add test for CanSet

* update readme and add test case

* remove internal.Params

* add coverage

* fix warning
2018-11-22 09:29:48 +08:00
Gordon Tyler
8cb390f8fe Yaml binding (#1618)
* Add YAML binding for application/x-yaml.

* Add YAML binding methods to Context.

* Review fixes.

* Revert accidentally removed import.
2018-11-06 09:49:45 +08:00
chenyang929
b524e29442 Update README.md (#1620)
Missing the right colon
2018-11-01 22:44:49 +08:00
Barnabus
6f7fe487b3 Change HTML input tags to use HTML5 syntax. (#1617)
In XHTML, the <input> tag must be properly closed, like this `<input />`.  In HTML5 the `<input>` tag has no ending slash.  https://www.w3schools.com/tags/tag_input.asp
2018-11-01 16:05:40 +08:00
forging2012
8e9619767c FIX r.LoadHTMLGlob("/path/to/templates") (#1616)
FIX r.LoadHTMLGlob("/path/to/templates")) to r.LoadHTMLGlob("/path/to/templates")
2018-10-31 20:19:58 +08:00
田欧
a1a32562de
add gin user - photoprism (#1601) 2018-10-19 11:06:23 +08:00
A. F
333bac5f94 add example to set and get cookies (#1599) 2018-10-17 15:40:57 +08:00
zesani
fbdcbd2275 Update README.md (#1583)
change "hava" to "have"
2018-10-09 07:14:21 +08:00
田欧
5a75dc7127
add release badge for readme (#1533) 2018-09-22 11:37:28 +08:00
Jérôme Laforge
90c680ef5c Let's user define how he wants to log his routes (eg. JSON, key value, or something else) (#1553) (#1555) 2018-09-17 12:09:34 +08:00
田欧
d510595aa5 chore: add some annotations (#1544)
ref: #1075 
because I am not a native English, maybe have a bit problem.
2018-09-15 10:23:32 +08:00
Javier Provecho Fernandez
500ebd9ea8
docs: add fnproject to gin's user list (#1505) 2018-08-31 22:38:16 +02:00
llgoer
708b76adf0 Update README.md (#1509)
change  `ShouldBindXML` to `ShouldBindJSON`
2018-08-30 14:29:26 +08:00
anoty
0da5b0c85a format readme code import (#1503) 2018-08-21 13:29:25 +08:00
Filip Figiel
c6110f970c Add PureJSON renderer (#694)
Closes #693
2018-08-20 15:15:31 +08:00
aljun
efdd3c8b81 Add support for Protobuf format response and unit test (#1479)
`Gin` now have the `protobufBinding` function to check the request format, but didn't have a protobuf response function like `c.YAML()`.
In our company [ByteDance](http://bytedance.com/), the largest internet company using golang in China, we use `gin` to transfer __Protobuf__  instead of __Json__, we have to write some internal library to make some wrappers to achieve that, and the code is not elegant. So we really want such a feature.
2018-08-19 10:45:56 +08:00
chainhelen
f856aa85cd Update readme about the version of gin (#1494) 2018-08-17 14:59:55 +08:00
David Zhang
f5451bd645 Fix typo in README [ci skip] (#1492) 2018-08-17 11:33:23 +08:00
Eason Lin
a643d20605 readme: fix users link (#1493) 2018-08-17 11:21:14 +08:00
syssam
40ab9de4b5 Add BindXML AND ShouldBindXML #1484 (#1485)
Add BindXML AND ShouldBindXML #1484
2018-08-17 09:12:15 +08:00
Abner Chen
64a4548642 Fix typo in readme (#1490) 2018-08-15 13:42:12 +08:00
Alex
8aef947f6e docs: remove double negative in README.md (#1480)
"not match neither" means that it will match.
2018-08-12 22:54:22 +02:00
田欧
6159213462 unify test data (#1417)
mkdir a test data dir.
2018-08-12 23:38:31 +08:00
田欧
9666ba6738 chore: update top bar header (#1461) 2018-08-07 13:49:31 +08:00
田欧
647535cd9b Support map as query string or post form parameters (#1383)
* support query map

* add GetQueryMap and unittest

* support post-form map

* add readme for query map

* attempt to fix bug for post-form map when go version is 1.6

* remove duplicate code

* remove comment
2018-08-06 12:07:11 +08:00
Rex Lee(李俊)
85221af84c add json ASCII string render (#1358)
add a json render that rendering json as ASCII string
2018-07-03 17:17:08 +08:00
田欧
c00f21ff23 add go version prerequisite and debug warning (#1394)
* add go version prerequisite and debug warning

* merge duplicate content

* remove duplicate content
2018-06-26 18:56:43 +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
田欧
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
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
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
田欧
bd4f73af67 support struct pointer (#1342)
* support struct pointer

* add readme
2018-05-01 14:24:18 +08:00
senhtry
8c24018290 Add Jsonp Support to Context (#1333) 2018-04-26 11:52:19 +08:00
JINNOUCHI Yasushi
814ac9490a Add example to build single binary with templates (#1328) 2018-04-22 15:04:38 +08:00
田欧
248c522e4a Add Contents for README because it too long (#1325) 2018-04-20 09:54:00 +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
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
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
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
Levi Olson
05547037e4 Minor grammatical correction in README (#1206) 2017-12-21 10:48:11 +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
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
Richard Lee
ae9f03e6e8 Fix up syntax error in README (#1155) 2017-11-11 23:56:59 -06:00