htmxgo

package module
v1.9.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2023 License: BSD-3-Clause Imports: 11 Imported by: 0

README

htmxgo

pckage htmxgo provides utilities for serving htmx library.

Look https://htmx.org/ for more information about htmx.

It can be imported as a library into golang project and hooked up to any HTTP router or server. It supports compression and caches compressed content in memory, but lazily and doesn't waste memory on unused encodings.

All functions are safe for concurrent use.

Currently supported encodings are:

  • plain text
  • deflate
  • gzip
  • brotli

License

Usage

import "github.com/ninedraft/htmx-go"
go get -v github.com/ninedraft/htmx-go@latest

Example

// your router setup

mux.Get("/assets/htmx.min.js", htmxgo.ServeHTTP)

Versioning

Release versions are the same as htmx versions. API can and will be broken.

Development

Updating htmx version:

wget 'https://unpkg.com/htmx.org@1.9.8/dist/htmx.min.js' -O htmx.min.js

But why?

For pet experiments. I don't want to import htmx via unpkg nor do I want to setup tooling for frontend stuff. Don't use in production, it will backfire, I swear to you. It's mostly a meme module.

Documentation

Overview

package htmxgo provides utilities for serving htmx library.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ServeHTTP

func ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP serves the htmx library. Compression is supported. Sets Content-Type to application/javascript. Tries to use the best compression available by Accept-Encoding header. Concurrent safe.

Example
package main

import (
	"fmt"
	"net/http"
	"net/http/httptest"

	htmxgo "github.com/ninedraft/htmx-go"
)

func main() {
	req := httptest.NewRequest("GET", "/htmx.min.js", nil)
	req.Header.Set("Accept-Encoding", "br")

	mux := http.NewServeMux()
	mux.HandleFunc("/htmx.min.js", htmxgo.ServeHTTP)

	rw := httptest.NewRecorder()

	mux.ServeHTTP(rw, req)

	fmt.Println(rw.Header().Get("Content-Encoding"))
	fmt.Println(rw.Header().Get("Content-Type"))

}
Output:

br
application/javascript

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL