hactor

package module
v0.0.0-...-565b643 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2025 License: MIT Imports: 7 Imported by: 0

README

go-hactor

Package hactor provides an http.Handler middleware to render hactor (structured-HTML) to HTML, for the Go programming language.

hactor is an HTML based format for creating ActivityPub / ActivityStreams actors — Application, Feed, Group, Organization, Person, Service, etc.

An example hactor of type Person is:

<x-person>
	<x-name>Joe Blow</x-name>
	<x-handle>spaceace</x-handle>	
	<x-message>
		<p>
			Hello, how do you do?
		</p>
	</x-message>
</x-person>

An example hactor of type Application is:

<x-application>
	<x-name>Joe Blow</x-name>
	<x-handle>spaceace</x-handle>	
	<x-message>
		<p>
			Hello, how do you do?
		</p>
	</x-message>
</x-application>

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/codeberg.org/reiver/go-hactor

GoDoc

Example

Here is an example of using hactor.WrapHTTPHandler() to wrap another handler, to provide hactor (structured-HTML) to HTML rendering.

The http.Handler that hactor.WrapHTTPHandler() returns looks at what the sub-http.Handler to see if the Content-Type it wrote has text/excerpt+html.

import "codeberg.org/reiver/go-hactor"

// ...

var handler http.Handler = ...

handler = hactor.WrapHTTPHandler(handler) // <---------

err := http.ListenAndServe(":8080", handler)
if nil != err {
	return err
}

Import

To import package hactor use import code like the following:

import "codeberg.org/reiver/go-hactor"

Installation

To install package hactor do the following:

GOPROXY=direct go get codeberg.org/reiver/go-hactor

Author

Package hactor was written by Charles Iliya Krempeaux

Documentation

Index

Constants

View Source
const FileExtension string = ".hact"

FileExtension is constant for the file-extension used for hactor files.

Here is an example of a hactor file-name that has the ".hact" file-extension:

readme.hact
View Source
const MediaType string = "text/actor+html"

MediaType is a constant for the media-type used for hactor content.

Note that the value of the HTTP Content-Type response header and the HTTP Accept request header both use media-types.

Variables

This section is empty.

Functions

func Transform

func Transform(hact []byte) (html []byte, err error)

Transform accepts hactor data and return HTML.

Note that the HTML is NOT a full HTML page.

func WrapHTTPHandler

func WrapHTTPHandler(subHandler http.Handler) http.Handler

WrapHTTPHandler provides http.Handler middleware.

If the http.Handler WrapHTTPHandler returns sees the "text/actor+html" media-type in the "Content-Type" response header generated by the sub-http.Handler AND "text/actor+html" isn't in the "Accept" request header, then it will transform the body to (regular) HTML (and change the "Content-Type" header to "text/html").

func WrapHTTPHandlerWithLogger

func WrapHTTPHandlerWithLogger(logger Logger, subHandler http.Handler) http.Handler

Types

type Logger

type Logger = log.Logger

Jump to

Keyboard shortcuts

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