Code Monkey home page Code Monkey logo

go-httpheader's Issues

fillValues case reflect.Int, reflect.Int64 provides error if header is not set

fillValues function returns error if header with int value is not set.

type ControllerPostParams struct {
IntegerInJsonBody int json:"integerInJsonBody" validate:"min=1,max=100000"
stringInHeader string header:"X-String,omitempty"
}

The error occurs in switch case
case reflect.Int, reflect.Int64:
var v int64
if v, err = strconv.ParseInt(value, 10, 64); err != nil {
return err
}
sv.SetInt(v)
return nil

in case of an empty header value = "" strconv.ParseInt throws an error. I guess the same problem will occur in all number based switch cases from fillValues. I recommended to check if the header is set and otherwise exit the loop.

I know you can also set header:"-" in the struct tags, but this can be easily forgotten.
Additionally we initialise our params with defaults and httpheader.Decode overwrites everything if we do not set header:"-", which adds a lot of overhead in our stuct tags.

My proposal:
add an option that struct fields are left unharmed and are not overwritten with empty strings if no header is present.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.