Skip to content

Create abstraction layer for requests #134

@abemedia

Description

@abemedia

Create a don.Context interface with an implementation that calls out to fasthttp.

don.Context Methods:

  • context.Context
  • io.Reader (reads from request body)
  • io.Writer (writes to response body)
  • Body() []byte (request body)
  • Method() string
  • URL() don.URL (request URL)
  • RequestHeader() don.Header
  • ResponseHeader() don.Header
  • Query() don.Params (request URL query)
  • Path() don.Params (request path params)
  • Status(int) don.Params (sets status code)
  • Redirect(string, int)
  • Decode(any) error (decode request body, path, header & query to struct)
  • Encode(any) error (encode and write to response body)

don.Header Methods:

  • Get(string) string
  • Values(string) []string
  • Add(k,v string)
  • Set(k,v string)
  • Range(f func(k,v string))

don.Params Methods:

  • Get(string) string
  • Values(string) []string
  • Range(f func(k,v string))

Use this interface in middleware and handlers that don't use don.H. Old style handlers using the fasthttp request directly should also still be supported via an adapter.

This will allow don to also run on standard lib net/http down the line by creating a second implementation of don.Context that wraps the standard lib request & response writer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions