Commit Graph

286 Commits

Author SHA1 Message Date
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