Documentation
¶
Index ¶
- Variables
- func GetBase(r *http.Request) string
- func GetShorthandPath(path string) string
- func HasContentType(header http.Header, mimetype string) bool
- func Hash(s string) string
- func IsPrivateIP(ip net.IP) bool
- func IsPrivateURL(rawURL string) (bool, error)
- func NewID() string
- func WriteFavicon(w http.ResponseWriter, _ *http.Request)
- func WritePixel(w http.ResponseWriter, _ *http.Request)
- type API
- type DB
- func (db *DB) Close() error
- func (db *DB) DeleteEntry(id string) error
- func (db *DB) DeleteLogs(entryID string) error
- func (db *DB) GetEntries(pattern string) (map[string]*Entry, error)
- func (db *DB) GetEntry(id string) (*Entry, error)
- func (db *DB) GetLogs(entryID string, first, last int) ([]Log, error)
- func (db *DB) GetLogsCount(entryID string) (int, error)
- func (db *DB) InsertEntry(id *string, e *Entry) (string, error)
- func (db *DB) InsertLog(entryID string, r *http.Request) error
- func (db *DB) SetEntry(id string, e *Entry) error
- type Entry
- type Layout
- type LayoutRenderer
- type Log
- type Page
- type PageRequest
- func (r *PageRequest) AsyncCopyView(resp *http.Response, opts ...ViewOption) *View
- func (r *PageRequest) CookieAndRedirectView(cookie *http.Cookie, url string, opts ...ViewOption) *View
- func (r *PageRequest) CopyView(resp *http.Response, opts ...ViewOption) *View
- func (r *PageRequest) EmbedView(url string, opts ...ViewOption) *View
- func (r *PageRequest) ErrorView(errmsg string, errcode int, opts ...ViewOption) *View
- func (r *PageRequest) HandlerView(handler http.HandlerFunc, opts ...ViewOption) *View
- func (r *PageRequest) RedirectView(url string, opts ...ViewOption) *View
- func (r *PageRequest) Respond(data interface{}, opts ...ViewOption) *View
- type ServeMethod
- type Server
- type View
- func AsyncCopyView(resp *http.Response, opts ...ViewOption) *View
- func CookieAndRedirectView(r *http.Request, cookie *http.Cookie, url string, opts ...ViewOption) *View
- func CopyView(resp *http.Response, opts ...ViewOption) *View
- func EmbedView(url string, opts ...ViewOption) *View
- func ErrorView(r *http.Request, errmsg string, errcode int, opts ...ViewOption) *View
- func HandlerView(r *http.Request, handler http.HandlerFunc, opts ...ViewOption) *View
- func RedirectView(r *http.Request, url string, opts ...ViewOption) *View
- type ViewOption
Constants ¶
This section is empty.
Variables ¶
var InstanceID = newInstanceID()
InstanceID is a unique ID for this instance (to be prepended to entry IDs)
Functions ¶
func GetShorthandPath ¶
GetShorthandPath returns a shorthand version of a path in case it's too long
func HasContentType ¶
HasContentType determines whether the request `content-type` includes a server-acceptable mime-type
func IsPrivateIP ¶
IsPrivateIP returns true if the given IP address belongs to private network space
func IsPrivateURL ¶
IsPrivateURL checks whether the host in the given URL resolves to a private IP address
func WriteFavicon ¶
func WriteFavicon(w http.ResponseWriter, _ *http.Request)
WriteFavicon writes Razlink favicon to a http.ResponseWriter
func WritePixel ¶
func WritePixel(w http.ResponseWriter, _ *http.Request)
WritePixel writes a transparent pixel to a http.ResponseWriter
Types ¶
type API ¶
type API struct {
Path string
// contains filtered or unexported fields
}
API is lightweight frontend-less version of a page
func (*API) GetHandler ¶
func (api *API) GetHandler() http.HandlerFunc
GetHandler creates a http.HandlerFunc that uses Razlink layout
type DB ¶
type DB struct {
ExpirationTime time.Duration
MaxLogs int
// contains filtered or unexported fields
}
DB ...
func (*DB) DeleteEntry ¶
DeleteEntry deleted the entry with the given ID
func (*DB) DeleteLogs ¶
DeleteLogs deleted all logs that belong to an entry
func (*DB) GetEntries ¶
GetEntries returns the list of entries with IDs matching the given pattern
func (*DB) GetLogs ¶
GetLogs returns the Nth page of logs that belong to an entry (pages are 0 based)
func (*DB) GetLogsCount ¶
GetLogsCount returns the number of logs that belong to an entry
func (*DB) InsertEntry ¶
InsertEntry inserts a new entry to the database If 'id' is null, the function will generate and return a unique one
type Entry ¶
type Entry struct {
URL string
Method ServeMethod
Salt string
PasswordHash string
Permanent bool
}
Entry ...
func (*Entry) MatchPassword ¶
MatchPassword ...
type Layout ¶
type Layout interface {
BindTemplate(pageTemplate string, stylesheets, scripts []string, meta map[string]string) (LayoutRenderer, error)
}
Layout is used to give pages a uniform layout
type LayoutRenderer ¶
type LayoutRenderer func(w http.ResponseWriter, r *http.Request, title string, data interface{}, statusCode int)
LayoutRenderer is a function that renders a html page
type Log ¶
type Log struct {
Time time.Time
IP string
Hostnames []string `json:"Addresses"`
CountryName string
RegionName string
City string
OS string
Browser string
Referer string
}
Log ...
type Page ¶
type Page struct {
Path string
Title string
ContentTemplate string
Stylesheets []string
Scripts []string
Metadata map[string]string
Handler func(*PageRequest) *View
}
Page ...
func (*Page) GetHandler ¶
func (page *Page) GetHandler(layout Layout) (http.HandlerFunc, error)
GetHandler creates a http.HandlerFunc that uses the given layout to render the page
type PageRequest ¶
type PageRequest struct {
Request *http.Request
RelPath string
RelURI string
Title string
// contains filtered or unexported fields
}
PageRequest ...
func (*PageRequest) AsyncCopyView ¶
func (r *PageRequest) AsyncCopyView(resp *http.Response, opts ...ViewOption) *View
AsyncCopyView ...
func (*PageRequest) CookieAndRedirectView ¶
func (r *PageRequest) CookieAndRedirectView(cookie *http.Cookie, url string, opts ...ViewOption) *View
CookieAndRedirectView ...
func (*PageRequest) CopyView ¶
func (r *PageRequest) CopyView(resp *http.Response, opts ...ViewOption) *View
CopyView ...
func (*PageRequest) EmbedView ¶
func (r *PageRequest) EmbedView(url string, opts ...ViewOption) *View
EmbedView ...
func (*PageRequest) ErrorView ¶
func (r *PageRequest) ErrorView(errmsg string, errcode int, opts ...ViewOption) *View
ErrorView ...
func (*PageRequest) HandlerView ¶
func (r *PageRequest) HandlerView(handler http.HandlerFunc, opts ...ViewOption) *View
HandlerView ...
func (*PageRequest) RedirectView ¶
func (r *PageRequest) RedirectView(url string, opts ...ViewOption) *View
RedirectView ...
func (*PageRequest) Respond ¶
func (r *PageRequest) Respond(data interface{}, opts ...ViewOption) *View
Respond returns the default page response View
type ServeMethod ¶
type ServeMethod int
ServeMethod defines how to serve a request
const ( Proxy ServeMethod = iota Embed Redirect Track )
Available serve methods
func GetServeMethodForURL ¶
func GetServeMethodForURL(ctx context.Context, url string, timeout time.Duration) (ServeMethod, error)
GetServeMethodForURL tries to determine the best possible serve method for a URL
func GetServeMethodFromHeader ¶
func GetServeMethodFromHeader(header http.Header) ServeMethod
GetServeMethodFromHeader tries to determine the best possible serve method from a http response header
type Server ¶
type Server struct {
FaviconPNG []byte
Metadata map[string]string
// contains filtered or unexported fields
}
Server ...
func (*Server) AddPageWithLayout ¶
AddPageWithLayout adds a new servable page with custom layout to the server
type View ¶
type View struct {
StatusCode int
Error error
Data interface{}
Redirect string
// contains filtered or unexported fields
}
View is something that a PageHandler returns and is capable of rendering a page
func AsyncCopyView ¶
func AsyncCopyView(resp *http.Response, opts ...ViewOption) *View
AsyncCopyView ...
func CookieAndRedirectView ¶
func CookieAndRedirectView(r *http.Request, cookie *http.Cookie, url string, opts ...ViewOption) *View
CookieAndRedirectView ...
func EmbedView ¶
func EmbedView(url string, opts ...ViewOption) *View
EmbedView returns a View that embeds the given website
func HandlerView ¶
func HandlerView(r *http.Request, handler http.HandlerFunc, opts ...ViewOption) *View
HandlerView ...
func RedirectView ¶
func RedirectView(r *http.Request, url string, opts ...ViewOption) *View
RedirectView ...
type ViewOption ¶
type ViewOption func(view *View)
ViewOption ...
func WithErrorMessage ¶
func WithErrorMessage(errmsg string, errcode int) ViewOption
WithErrorMessage ...