Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultRobotsTxt = `user-agent: *
Allow: /$
Allow: /.static/*$
Disallow: /`
DefaultRobotsTxt is the default value for /robots.txt file.
Functions ¶
func DefaultIndexPageHandler ¶
DefaultIndexPageHandler serves given indexFilePath over HTTP via http.ServeFile(w, r, name).
func Handler ¶
Handler is an HTTP middleware that redirects browsers to Go module server (pkg.go.dev or similar) or Go tool to VCS repository. VCS repository is git by default. VCS can be set with VCS(). Configurable Logger defaults to os.Stdout. 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/).
Example ¶
package main import ( "log" "net/http" "os" "kkn.fi/vanity" ) func main() { errorLog := log.New(os.Stderr, "vanity: ", log.Ldate|log.Ltime|log.LUTC) srv := vanity.Handler( vanity.ModuleServerURL("https://pkg.go.dev"), vanity.Log(errorLog), vanity.VCSURL("https://github.com/kare"), vanity.VCS("git"), vanity.StaticDir("testdata", "/.static/"), vanity.IndexPageHandler(vanity.DefaultIndexPageHandler("testdata"+"/index.html")), ) http.Handle("/", srv) }
Output:
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 ¶
Option represents a functional option for configuring the vanity middleware.
func IndexPageHandler ¶
IndexPageHandler sets a handler for index.html page.
func ModuleServerURL ¶
ModuleServerURL sets Go module server address for browser redirect.
func RobotsTxt ¶
RobotsTxt takes in option robotsTxt value. If value is empty, the value of DefaultRobotsTxt is used