Documentation ¶
Overview ¶
Package shrt implements a simple (perhaps simplistic) URL shortener. It also handles go-get requests.
Shortlinks are recorded in the database, and any request path not matching a shortlink is assumed to be a go-get request. This is by design, but can result in specious redirects. Additionally, subdirectory paths are not allowed.
Shortlinks generate an HTTP 301 response. Go-get requests generate an HTTP 200 response. If configured, requests to the base path (i.e., "/") generate an HTTP 302 response.
The database file is human-readable. See [Shrtfile] for the full specification.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶ added in v0.3.0
type Config struct { // Server name of the Shrt host SrvName string // SCM (or VCS) type ScmType string // SCM repository suffix, if required by repository host Suffix string // The server name of the repository host RdrName string // Where requests with an empty path should redirect BareRdr string // The path to the [ShrtFile]-formatted database file. DbPath string // The string to append to the URL for go-get redirects to // form the directory entry in the go-source meta tag. This // key is experimental and may be removed in a future release. GoSourceDir string // The string to append to the URL for go-get redirects to // form the file entry in the go-source meta tag. This // key is experimental and may be removed in a future release. GoSourceFile string }
Config contains all of the global configuration for Shrt. All values except BareRdr and DbPath are used in the go-import meta tag values for go-get requests.
type ShrtFile ¶
type ShrtFile struct {
// contains filtered or unexported fields
}
The ShrtFile struct contains the data read from a specially-formatted file. The syntax of the file is human readable. Each line represents a key-value pair. The key is everything to the left of the first equals sign, and the value is everything to the right. The value is then split around the first occurence of the colon character, with the left side representing the type, and the right side representing the URL. Whitespace is trimmed from the beginning and end of all fields.
ShrtFile is safe for concurrent use across multiple goroutines.
type ShrtHandler ¶ added in v0.3.0
ShrtHandler is the core http.Handler for go-shrt.
func (*ShrtHandler) ServeHTTP ¶ added in v0.3.0
func (s *ShrtHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
Handle implements the http.Handler interface.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
shrt
usage: shrt <command> [arguments]
|
usage: shrt <command> [arguments] |
shrt/internal/base
Package base defines the foundational structures required to build out the Shrt command suite.
|
Package base defines the foundational structures required to build out the Shrt command suite. |
shrt/internal/env
Package env implements the "shrt env" command
|
Package env implements the "shrt env" command |
shrt/internal/help
Package help implements the "shrt help" command
|
Package help implements the "shrt help" command |
shrt/internal/serve
Package serve implements the "shrt serve" command
|
Package serve implements the "shrt serve" command |
shrt/internal/version
Package version implements the "shrt version" command
|
Package version implements the "shrt version" command |
devtools
|
|