Giter Site home page Giter Site logo

tylermmorton / torque Goto Github PK

View Code? Open in Web Editor NEW
35.0 35.0 3.0 368 KB

`torque` is a web framework for building hypermedia driven applications in Go

Home Page: https://lbft.dev/

Go 63.92% HTML 32.48% JavaScript 1.75% CSS 1.01% Dockerfile 0.84%
framework golang htmx webapp

torque's People

Contributors

akarshitjoshi avatar tylermmorton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

torque's Issues

Documentation: `EventSource`, htmx and `hx-ext="sse"`

With the addition of the EventSource route module type, there is also basic support for the htmx sse extension in the torque/pkg/htmx sub-package as of 94a167a.

TODO:

  • Add documentation to https://lbft.dev/server-sent-events
  • Add dogfooding examples of how to use the new EventSource route module type in conjunction with htmx
    • Idea: Create a real-time viewer count component somewhere on lbft.dev
    • Idea: Poll GitHub API and create a real-time toast notification when changes are pushed to the docsite source.

Feature: Generic typed Loader/Renderer interface

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:

  • Implement new generic interface type from above in module.go.
  • Update handleLoader and handleRenderer in server.go to support the new interface type. This may or may not be possible with the generic type.
  • Add documentation to the docsite and provide guidance on API usage.

Refactor: Use the htmx-go package

The torque framework has its own htmx package, mostly containing logic to wire up WebSockets and SSE into torque.

Recently a new package was released called htmx-go that is a much more comprehensive implementation of htmx related features.

We should determine which logic in the torque htmx package can be deprecated and replaced.

Tasks:

Feature: Rate Limiting for Route Modules

Problem:

I often find myself configuring a rate-limiter guard for every route I register with a torque app. I think this is a good use case for the Guard API but if users end up registering the same guard on all of their endpoints, perhaps that is a sign that the guard logic should be implemented internally to torque.

torque.WithRouteModule("/login",
	&login.RouteModule{
		AuthService: authService,
	},
	torque.WithGuard(guards.ThrottleGuard(
		throttled.PerHour(25),
	)),
),

Rough outline of solution

  • Implement rate limiting with sensible defaults using standard library (https://pkg.go.dev/golang.org/x/time/rate) as a part of the router in router.go.
  • Provide an API to consumers for configuring rate limiting. For a route module this could be an additional interface in module.go?
  • Document the new feature and push it to the docsite.

Feature: Uncaught Panic View

Problem

Whenever a panic is left uncaught in server.go a log is printed to the console and nothing is written to the response body. This results in a blank screen in the browser.

In development environments it might be useful to render some HTML to the browser containing details about the error such as message & stack trace.

Rough outline of solution

  • Create a Go html template for the error page. Keep it simple for now and include styles in <style> tags.
    • Include error string
    • Include stack trace
  • In handlePanic of server.go, write the new error page to the response body

Demo: chat app

Saw that SSE is getting turned on.

Is there a chat app example or in fact any examples yet ?

Feature: Honeypot Form Fields

The torque framework has some APIs for decoding form data. It might be useful to include support for honeypot fields, as described by Kent Dodds on his blog:

https://forms.epicweb.dev/06

Another useful thing you can do along with the honeypot field is to add a field that will allow you to determine when the form was generated. So if the form is submitted too quickly, you can be pretty confident that it's a bot.

The time stamp based field sounds particularly useful and very possible for SSR based applications.

The form API is located here:

https://github.com/tylermmorton/torque/blob/master/form.go

Rough outline of solution:

  • Add ErrFormHoneypot
  • Add API for declaring honeypot form fields on structs.
  • Add check for honeypot fields in form decoder methods. Return ErrFormHoneypot
  • Add documentation and provide guidance on API usage

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.