mozillazg / go-httpheader Goto Github PK
View Code? Open in Web Editor NEWA Go library for encoding structs into Header fields.
Home Page: https://godoc.org/github.com/mozillazg/go-httpheader
License: MIT License
A Go library for encoding structs into Header fields.
Home Page: https://godoc.org/github.com/mozillazg/go-httpheader
License: MIT License
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.