htmlpage

package module
v0.0.0-...-89328f9 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2025 License: MIT Imports: 9 Imported by: 0

README

go-htmlpage

Package htmlpage provides tools for working with complete HTML pages, for the Go programming language.

Documention

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

GoDoc

Example

Here is an example of using htmlpage.WrappingHTTPHandler:

var handler http.Handler = http.HandlerFunc(serveHTTP)

handler = htmlpage.WrappingHTTPHandler{handler} // <---------

Import

To import package htmlpage use import code like the following:

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

Installation

To install package htmlpage do the following:

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

Author

Package htmlpage was written by Charles Iliya Krempeaux

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WrappingHTTPHandler

type WrappingHTTPHandler struct {
	SubHandler http.Handler
}

If the sub-http.Handler returns HTML that is not a complete document (with opening and closing "<html>...</html>" HTML elements) then WrappingHTTPHandler wraps it.

It also infers what the "<title>...</title>" should be.

So, for example, if the sub-http.Handler returns a "Content-Type" with a media-type of "text/html" and the body is:

<div>What is this?</div>

Then WrappingHTTPHandler with transform that into:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
</head>
<body>
<main>
<div>What is this?</div></main>
</body>
</html>

Or, for example, if the sub-http.Handler returns a "Content-Type" with a media-type of "text/html" and the body is:

<div>
	<h1>Hey!</h1>
	<p>
		What is this?
	</p>
</div>

Then WrappingHTTPHandler with transform that into:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Hey!</title>
</head>
<body>
<main>
<div>
	<h1>Hey!</h1>
	<p>
		What is this?
	</p>
</div>
</body>
</html>

func (WrappingHTTPHandler) ServeHTTP

func (receiver WrappingHTTPHandler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request)

Jump to

Keyboard shortcuts

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