mirror of
https://github.com/kataras/iris.git
synced 2026-03-14 04:09:37 +00:00
formatting
Former-commit-id: 037081db5d6d4434e873ca8b75334ee43e046b6a
This commit is contained in:
@@ -2110,9 +2110,7 @@ func GetForm(r *http.Request, postMaxMemory int64, resetBody bool) (form map[str
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
bodyCopy []byte
|
||||
)
|
||||
var bodyCopy []byte
|
||||
|
||||
if resetBody {
|
||||
// on POST, PUT and PATCH it will read the form values from request body otherwise from URL queries.
|
||||
@@ -2360,7 +2358,6 @@ func uploadTo(fh *multipart.FileHeader, destDirectory string) (int64, error) {
|
||||
|
||||
out, err := os.OpenFile(filepath.Join(destDirectory, fh.Filename),
|
||||
os.O_WRONLY|os.O_CREATE, os.FileMode(0666))
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -2534,7 +2531,7 @@ func (ctx *context) shouldOptimize() bool {
|
||||
//
|
||||
// Example: https://github.com/kataras/iris/blob/master/_examples/http_request/read-json/main.go
|
||||
func (ctx *context) ReadJSON(outPtr interface{}) error {
|
||||
var unmarshaler = json.Unmarshal
|
||||
unmarshaler := json.Unmarshal
|
||||
if ctx.shouldOptimize() {
|
||||
unmarshaler = jsoniter.Unmarshal
|
||||
}
|
||||
@@ -2814,9 +2811,7 @@ func (ctx *context) ClientSupportsGzip() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
var (
|
||||
errClientDoesNotSupportGzip = errors.New("client doesn't support gzip compression")
|
||||
)
|
||||
var errClientDoesNotSupportGzip = errors.New("client doesn't support gzip compression")
|
||||
|
||||
// WriteGzip accepts bytes, which are compressed to gzip format and sent to the client.
|
||||
// returns the number of bytes written and an error ( if the client doesn't support gzip compression)
|
||||
@@ -3163,7 +3158,7 @@ func (ctx *context) JSON(v interface{}, opts ...JSON) (n int, err error) {
|
||||
|
||||
if options.StreamingJSON {
|
||||
if ctx.shouldOptimize() {
|
||||
var jsoniterConfig = jsoniter.Config{
|
||||
jsoniterConfig := jsoniter.Config{
|
||||
EscapeHTML: !options.UnescapeHTML,
|
||||
IndentionStep: 4,
|
||||
}.Froze()
|
||||
@@ -3194,9 +3189,7 @@ func (ctx *context) JSON(v interface{}, opts ...JSON) (n int, err error) {
|
||||
return n, err
|
||||
}
|
||||
|
||||
var (
|
||||
finishCallbackB = []byte(");")
|
||||
)
|
||||
var finishCallbackB = []byte(");")
|
||||
|
||||
// WriteJSONP marshals the given interface object and writes the JSON response to the writer.
|
||||
func WriteJSONP(writer io.Writer, v interface{}, options JSONP, enableOptimization ...bool) (int, error) {
|
||||
@@ -4081,9 +4074,7 @@ func (n *NegotiationAcceptBuilder) EncodingGzip() *NegotiationAcceptBuilder {
|
||||
// | Serve files |
|
||||
// +------------------------------------------------------------+
|
||||
|
||||
var (
|
||||
errServeContent = errors.New("while trying to serve content to the client. Trace %s")
|
||||
)
|
||||
var errServeContent = errors.New("while trying to serve content to the client. Trace %s")
|
||||
|
||||
// ServeContent serves content, headers are autoset
|
||||
// receives three parameters, it's low-level function, instead you can use .ServeFile(string,bool)/SendFile(string,string)
|
||||
@@ -4387,7 +4378,7 @@ func (ctx *context) Recorder() *ResponseRecorder {
|
||||
// when the response writer is recording the status code, body, headers and so on,
|
||||
// else returns nil and false.
|
||||
func (ctx *context) IsRecording() (*ResponseRecorder, bool) {
|
||||
//NOTE:
|
||||
// NOTE:
|
||||
// two return values in order to minimize the if statement:
|
||||
// if (Recording) then writer = Recorder()
|
||||
// instead we do: recorder,ok = Recording()
|
||||
@@ -4435,7 +4426,6 @@ func (ctx *context) BeginTransaction(pipe func(t *Transaction)) {
|
||||
// give back to the transaction the original writer (SetBeforeFlush works this way and only this way)
|
||||
// this is tricky but nessecery if we want ctx.FireStatusCode to work inside transactions
|
||||
t.Context().ResetResponseWriter(ctx.writer)
|
||||
|
||||
}()
|
||||
|
||||
// run the worker with its context clone inside.
|
||||
|
||||
@@ -133,7 +133,6 @@ func (w *GzipResponseWriter) WriteString(s string) (n int, err error) {
|
||||
if w.ResponseWriter.Header()[ContentTypeHeaderKey] == nil {
|
||||
w.ResponseWriter.Header().Set(ContentTypeHeaderKey, ContentTextHeaderValue)
|
||||
}
|
||||
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -89,124 +89,122 @@ func (r RequestParams) GetIntUnslashed(key string) (int, bool) {
|
||||
return -1, false
|
||||
}
|
||||
|
||||
var (
|
||||
// ParamResolvers is the global param resolution for a parameter type for a specific go std or custom type.
|
||||
//
|
||||
// Key is the specific type, which should be unique.
|
||||
// The value is a function which accepts the parameter index
|
||||
// and it should return the value as the parameter type evaluator expects it.
|
||||
// i.e [reflect.TypeOf("string")] = func(paramIndex int) interface{} {
|
||||
// return func(ctx Context) <T> {
|
||||
// return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(<T>)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Read https://github.com/kataras/iris/tree/master/_examples/routing/macros for more details.
|
||||
// Checks for total available request parameters length
|
||||
// and parameter index based on the hero/mvc function added
|
||||
// in order to support the MVC.HandleMany("GET", "/path/{ps}/{pssecond} /path/{ps}")
|
||||
// when on the second requested path, the 'pssecond' should be empty.
|
||||
ParamResolvers = map[reflect.Type]func(paramIndex int) interface{}{
|
||||
reflect.TypeOf(""): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) string {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return ""
|
||||
}
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(string)
|
||||
// ParamResolvers is the global param resolution for a parameter type for a specific go std or custom type.
|
||||
//
|
||||
// Key is the specific type, which should be unique.
|
||||
// The value is a function which accepts the parameter index
|
||||
// and it should return the value as the parameter type evaluator expects it.
|
||||
// i.e [reflect.TypeOf("string")] = func(paramIndex int) interface{} {
|
||||
// return func(ctx Context) <T> {
|
||||
// return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(<T>)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Read https://github.com/kataras/iris/tree/master/_examples/routing/macros for more details.
|
||||
// Checks for total available request parameters length
|
||||
// and parameter index based on the hero/mvc function added
|
||||
// in order to support the MVC.HandleMany("GET", "/path/{ps}/{pssecond} /path/{ps}")
|
||||
// when on the second requested path, the 'pssecond' should be empty.
|
||||
var ParamResolvers = map[reflect.Type]func(paramIndex int) interface{}{
|
||||
reflect.TypeOf(""): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) string {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return ""
|
||||
}
|
||||
},
|
||||
reflect.TypeOf(int(1)): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) int {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return 0
|
||||
}
|
||||
// v, _ := ctx.Params().GetEntryAt(paramIndex).IntDefault(0)
|
||||
// return v
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(int)
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(string)
|
||||
}
|
||||
},
|
||||
reflect.TypeOf(int(1)): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) int {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return 0
|
||||
}
|
||||
},
|
||||
reflect.TypeOf(int8(1)): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) int8 {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return 0
|
||||
}
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(int8)
|
||||
// v, _ := ctx.Params().GetEntryAt(paramIndex).IntDefault(0)
|
||||
// return v
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(int)
|
||||
}
|
||||
},
|
||||
reflect.TypeOf(int8(1)): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) int8 {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return 0
|
||||
}
|
||||
},
|
||||
reflect.TypeOf(int16(1)): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) int16 {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return 0
|
||||
}
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(int16)
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(int8)
|
||||
}
|
||||
},
|
||||
reflect.TypeOf(int16(1)): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) int16 {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return 0
|
||||
}
|
||||
},
|
||||
reflect.TypeOf(int32(1)): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) int32 {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return 0
|
||||
}
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(int32)
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(int16)
|
||||
}
|
||||
},
|
||||
reflect.TypeOf(int32(1)): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) int32 {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return 0
|
||||
}
|
||||
},
|
||||
reflect.TypeOf(int64(1)): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) int64 {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return 0
|
||||
}
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(int64)
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(int32)
|
||||
}
|
||||
},
|
||||
reflect.TypeOf(int64(1)): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) int64 {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return 0
|
||||
}
|
||||
},
|
||||
reflect.TypeOf(uint(1)): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) uint {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return 0
|
||||
}
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(uint)
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(int64)
|
||||
}
|
||||
},
|
||||
reflect.TypeOf(uint(1)): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) uint {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return 0
|
||||
}
|
||||
},
|
||||
reflect.TypeOf(uint8(1)): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) uint8 {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return 0
|
||||
}
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(uint8)
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(uint)
|
||||
}
|
||||
},
|
||||
reflect.TypeOf(uint8(1)): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) uint8 {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return 0
|
||||
}
|
||||
},
|
||||
reflect.TypeOf(uint16(1)): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) uint16 {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return 0
|
||||
}
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(uint16)
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(uint8)
|
||||
}
|
||||
},
|
||||
reflect.TypeOf(uint16(1)): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) uint16 {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return 0
|
||||
}
|
||||
},
|
||||
reflect.TypeOf(uint32(1)): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) uint32 {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return 0
|
||||
}
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(uint32)
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(uint16)
|
||||
}
|
||||
},
|
||||
reflect.TypeOf(uint32(1)): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) uint32 {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return 0
|
||||
}
|
||||
},
|
||||
reflect.TypeOf(uint64(1)): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) uint64 {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return 0
|
||||
}
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(uint64)
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(uint32)
|
||||
}
|
||||
},
|
||||
reflect.TypeOf(uint64(1)): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) uint64 {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return 0
|
||||
}
|
||||
},
|
||||
reflect.TypeOf(true): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) bool {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return false
|
||||
}
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(bool)
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(uint64)
|
||||
}
|
||||
},
|
||||
reflect.TypeOf(true): func(paramIndex int) interface{} {
|
||||
return func(ctx Context) bool {
|
||||
if ctx.Params().Len() <= paramIndex {
|
||||
return false
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(bool)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
// ParamResolverByTypeAndIndex will return a function that can be used to bind path parameter's exact value by its Go std type
|
||||
// and the parameter's index based on the registered path.
|
||||
|
||||
@@ -188,7 +188,6 @@ func (w *ResponseRecorder) Clone() ResponseWriter {
|
||||
|
||||
// WriteTo writes a response writer (temp: status code, headers and body) to another response writer
|
||||
func (w *ResponseRecorder) WriteTo(res ResponseWriter) {
|
||||
|
||||
if to, ok := res.(*ResponseRecorder); ok {
|
||||
|
||||
// set the status code, to is first ( probably an error? (context.StatusCodeNotSuccessful, defaults to < 200 || >= 400).
|
||||
|
||||
@@ -298,7 +298,6 @@ func (w *responseWriter) WriteTo(to ResponseWriter) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// the body is not copied, this writer doesn't support recording
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user