Skip to content

All examples must use func(*Context) error signature and new serialization #1

@FumingPower3925

Description

@FumingPower3925

Breaking change in celeris core

The HandlerFunc type has changed from func(*Context) to func(*Context) error in v1.0.0.

Impact on examples

All example code must use the new signature. The repo is currently empty, but when examples are added they must follow the new patterns.

New handler signature

s.GET("/hello", func(c *celeris.Context) error {
    return c.String(200, "Hello, World!")
})

Middleware pattern

s.Use(func(c *celeris.Context) error {
    start := time.Now()
    err := c.Next()
    log.Println("request", c.Method(), c.Path(), time.Since(start), err)
    return err
})

Error handling pattern

s.GET("/data", func(c *celeris.Context) error {
    data, err := fetchData()
    if err != nil {
        return celeris.NewHTTPError(500, "fetch failed")
    }
    return c.JSON(200, data)
})

New serialization features to demonstrate

  • c.XML(code, v) — XML response
  • c.ProtoBuf(code, msg) — Protocol Buffers response
  • c.Bind(v) — auto-detect format from Content-Type (JSON/XML/Protobuf)
  • c.BindJSON(v), c.BindXML(v), c.BindProtoBuf(msg) — explicit format binding

Suggested examples to include

  • Hello World (basic handler with error return)
  • REST API (CRUD with JSON + error handling)
  • Middleware chain (logging, recovery, auth — all error-aware)
  • XML API (legacy/SOAP endpoint)
  • Protobuf API (inter-service RPC)
  • Content negotiation (Bind auto-detect)
  • Custom error handler (HTTPError + middleware interception)
  • net/http bridge (Adapt/AdaptFunc)
  • Graceful shutdown
  • Route groups with per-group middleware

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions