tylermmorton / torque

`torque` is a web framework for building hypermedia driven applications in Go
https://lbft.dev/
36 stars 3 forks source link

Feature: Generic typed Loader/Renderer interface #7

Closed tylermmorton closed 3 months ago

tylermmorton commented 10 months ago

In the current version of the torque API, Loader and Renderer simply use the any type to describe the loader data.

type Loader interface {
    Load(req *http.Request) (any, error)
}

type Renderer interface {
    Render(wr http.ResponseWriter, req *http.Request, loaderData any) error
}

It would be great for API ergonomics to be able to declare them using a generic combination interface:

Illustration:

type GenericRenderer[T any] interface {
    Load(req *http.Request) (T, error)
    Render(wr http.ResponseWriter, req *http.Request, loaderData T) error
}

Rough outline of solution: