vanity

package module
v1.0.0-beta.6 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: BSD-3-Clause Imports: 6 Imported by: 2

README

kkn.fi/vanity

CI Go Reference GoReportCard

Concepts

  • VCS is Version Control System (such as 'git')
  • Repo root is the root path the source code repository (such as 'https://github.com/kare')
  • Domain is the internet address where the Go Vanity server is hosted (such as 9fans.net or kkn.fi). Domain is deduced from HTTP request.
  • Path is the path component of the Go package (such as /cmd/tcpproxy in kkn.fi/cmd/tcpproxy)

Specification

Features

  • Redirects Go tool to VCS
  • Redirects browsers to pkg.go.dev module server by default. Module Server URL is configurable.
  • Module server URL options are:
  • Hostname defaults to request host, but it can also be configured.
  • Automatic configuration of cmd packages:
    • All packages are redirected without sub-packages to vcsroot.
    • Packages whose path is prefixed with "/cmd/" redirect automatically to vcsroot by stripping the "/cmd" prefix from the package path. Example: Redirect request "kkn.fi/cmd/tcpproxy" to "github.com/kare/tcpproxy" Example: Redirect request "kkn.fi/project/sub/package" to "github.com/kare/project"
  • Configurable logger which is compatible with standard log package. Default output goes to stderr.
  • Supports index HTML file in the domain root and configurable static content directory (for images, CSS, and etc).
  • Supports robots.txt file

Installation

go get kkn.fi/vanity

Development

Run all tests

make test

Run short (unit) tests

make test-unit

Run long (integration) tests

make test-integration

Run goimports

make goimports

Run staticcheck

make staticcheck

Run gofmt with simplify

make fmt

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRobotsTxt = `user-agent: *
Allow: /$
Allow: /.static/*$
Disallow: /`

DefaultRobotsTxt is the default value for /robots.txt file.

View Source
var ErrNotReadable = errors.New("vanity: static dir path directory is not readable")

Functions

func DefaultIndexPageHandler

func DefaultIndexPageHandler(indexFilePath string) http.Handler

DefaultIndexPageHandler serves given indexFilePath over HTTP via http.ServeFile(w, r, name).

func NewHandlerWithOptions

func NewHandlerWithOptions(opts ...Option) (http.Handler, error)

Handler is an HTTP middleware that redirects browsers to Go module server (pkg.go.dev or similar) or Go cmd line tool to VCS repository. Handler can be configured by providing options. VCS repository is git by default. VCS can be set with VCS(). Configurable Logger defaults to os.Stderr. Logger can be configured with SetLogger(). Module server URL is https://pkg.go.dev/ and it can be configured via ModuleServerURL() func. VCSURL() func must be used to set VCS repository URL (such as https://github.com/kare/).

Types

type Logger added in v0.2.0

type Logger interface {
	Printf(format string, v ...interface{})
}

Logger describes functions available for logging purposes.

type Option

type Option func(http.Handler) error

Option represents a functional option for configuring the vanity middleware.

func Host

func Host(host string) Option

Host sets the hostname of the vanity server. Host defaults to HTTP request hostname.

func IndexPageHandler

func IndexPageHandler(index http.Handler) Option

IndexPageHandler sets a handler for index.html page.

func Log

func Log(l Logger) Option

Log sets the logger used by vanity package's error logger.

func ModuleServerURL

func ModuleServerURL(moduleServerURL string) Option

ModuleServerURL sets Go module server address for browser redirect.

func RobotsTxt

func RobotsTxt(robotsTxt string) Option

RobotsTxt takes in a value for robots.txt. If value is empty, the value of `DefaultRobotsTxt` is used

func StaticDir

func StaticDir(path, URLPath string) Option

StaticDir serves a file system directory over HTTP. Given path is the local file system path to directory. Given urlPath is the path portion of the URL for the server.

func VCS

func VCS(vcs string) Option

VCS sets the version control type.

func VCSURL

func VCSURL(vcsURL string) Option

VCSURL sets the VCS repository url address.

Directories

Path Synopsis
cmd module
vanity Module

Jump to

Keyboard shortcuts

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