diff --git a/context.go b/context.go index 0e3b29a..23fa92f 100644 --- a/context.go +++ b/context.go @@ -267,17 +267,6 @@ func (c *Context) String(code int, format string, values ...interface{}) { func (c *Context) JSON(code int, obj interface{}) { c.Writer.Header().Set("Content-Type", "application/json; charset=utf-8") c.Writer.WriteHeader(code) - /* - // JSON 编码 - jsonBytes, err := json.Marshal(obj) - if err != nil { - c.AddError(fmt.Errorf("failed to marshal JSON: %w", err)) - //c.String(http.StatusInternalServerError, "Internal Server Error: Failed to marshal JSON") - c.ErrorUseHandle(http.StatusInternalServerError, fmt.Errorf("failed to marshal JSON: %w", err)) - return - } - c.Writer.Write(jsonBytes) - */ if err := json.MarshalWrite(c.Writer, obj); err != nil { c.AddError(fmt.Errorf("failed to marshal JSON: %w", err)) c.ErrorUseHandle(http.StatusInternalServerError, fmt.Errorf("failed to marshal JSON: %w", err)) @@ -294,7 +283,6 @@ func (c *Context) GOB(code int, obj interface{}) { encoder := gob.NewEncoder(c.Writer) if err := encoder.Encode(obj); err != nil { c.AddError(fmt.Errorf("failed to encode GOB: %w", err)) - //c.String(http.StatusInternalServerError, "Internal Server Error: Failed to encode GOB") c.ErrorUseHandle(http.StatusInternalServerError, fmt.Errorf("failed to encode GOB: %w", err)) return } @@ -314,7 +302,6 @@ func (c *Context) HTML(code int, name string, obj interface{}) { err := tpl.ExecuteTemplate(c.Writer, name, obj) if err != nil { c.AddError(fmt.Errorf("failed to render HTML template '%s': %w", name, err)) - //c.String(http.StatusInternalServerError, "Internal Server Error: Failed to render HTML template") c.ErrorUseHandle(http.StatusInternalServerError, fmt.Errorf("failed to render HTML template '%s': %w", name, err)) } return @@ -340,12 +327,6 @@ func (c *Context) ShouldBindJSON(obj interface{}) error { if c.Request.Body == nil { return errors.New("request body is empty") } - /* - decoder := json.NewDecoder(c.Request.Body) - if err := decoder.Decode(obj); err != nil { - return fmt.Errorf("json binding error: %w", err) - } - */ err := json.UnmarshalRead(c.Request.Body, obj) if err != nil { return fmt.Errorf("json binding error: %w", err) diff --git a/engine.go b/engine.go index babe365..3d39cf0 100644 --- a/engine.go +++ b/engine.go @@ -554,7 +554,6 @@ func NotFound() HandlerFunc { return func(c *Context) { engine := c.engine engine.errorHandle.handler(c, http.StatusNotFound, errors.New("not found")) - return } }