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

support bind http header param #1956 #1957

Merged

Commits on Jun 18, 2019

  1. support bind http header param gin-gonic#1956

    update gin-gonic#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}
    }
    ```
    guonaihong committed Jun 18, 2019
    Configuration menu
    Copy the full SHA
    027f846 View commit details
    Browse the repository at this point in the history

Commits on Jun 20, 2019

  1. add unit test

    guonaihong committed Jun 20, 2019
    Configuration menu
    Copy the full SHA
    f439a1b View commit details
    Browse the repository at this point in the history

Commits on Jun 23, 2019

  1. 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
    guonaihong committed Jun 23, 2019
    Configuration menu
    Copy the full SHA
    ce723d2 View commit details
    Browse the repository at this point in the history

Commits on Jun 24, 2019

  1. Configuration menu
    Copy the full SHA
    159224b View commit details
    Browse the repository at this point in the history

Commits on Jun 25, 2019

  1. 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
    guonaihong committed Jun 25, 2019
    Configuration menu
    Copy the full SHA
    c438fc1 View commit details
    Browse the repository at this point in the history

Commits on Jun 26, 2019

  1. Rollback check code

    guonaihong committed Jun 26, 2019
    Configuration menu
    Copy the full SHA
    8a7e38a View commit details
    Browse the repository at this point in the history
  2. add use case to README.md

    guonaihong committed Jun 26, 2019
    Configuration menu
    Copy the full SHA
    f9f0f9d View commit details
    Browse the repository at this point in the history

Commits on Jun 27, 2019

  1. Configuration menu
    Copy the full SHA
    adef0a8 View commit details
    Browse the repository at this point in the history