Documentation
¶
Overview ¶
Package http_util provides useful routines for writing web apps.
Index ¶
- func AddStatic(mux Mux, path, content string)
- func AddStaticBinary(mux Mux, path string, content []byte)
- func AddStaticFromFile(mux Mux, path, localPath string) error
- func AppendParams(u *url.URL, nameValues ...string) *url.URL
- func Error(w http.ResponseWriter, status int)
- func HasParam(values url.Values, param string) bool
- func NewUrl(path string, nameValues ...string) *url.URL
- func Redirect(w http.ResponseWriter, r *http.Request, redirectUrl string)
- func ReportError(w http.ResponseWriter, message string, err error)
- func WithParams(u *url.URL, nameValues ...string) *url.URL
- func WriteTemplate(w io.Writer, t *template.Template, v interface{})
- type Choice
- type ComboBox
- type Mux
- type PageBreadCrumb
- type SelectModel
- type Selection
- type Selections
- type Values
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddStatic ¶
AddStatic adds static content to mux. path is the path to the file; content is the file content.
func AddStaticBinary ¶
AddStaticBinary adds static content to mux. path is the path to the file; content is the file content.
func AddStaticFromFile ¶
AddStaticFromFile adds static content to mux. path is the path to the file; localPath is the actual path of the file on the local filesystem.
func AppendParams ¶
AppendParams returns a URL with new parameters appended. No existing parameter is replaced. u is the original URL; nameValues is parameter name, parameter value, parameter name, parameter value, etc. nameValues must have even length.
func Error ¶
func Error(w http.ResponseWriter, status int)
Error sends the status code along with its corresponding message
func NewUrl ¶
NewUrl returns a new URL with a given path and parameters. nameValues is parameter name, parameter value, parameter name, parameter value, etc. nameValues must have even length.
func Redirect ¶
func Redirect(w http.ResponseWriter, r *http.Request, redirectUrl string)
Redirect sends a 302 redirect
func ReportError ¶
func ReportError(w http.ResponseWriter, message string, err error)
Repoort error reports an error. message is what user sees.
func WithParams ¶
WithParams returns a URL with new parameters. If the parameters already exist in the original URL, they are replaced. u is the original URL; nameValues is parameter name, parameter value, parameter name, parameter value, etc. nameValues must have even length.
Types ¶
type Choice ¶
type Choice struct { // What the user sees in the choice dialog Name string // The parameter value attached to this choice Value interface{} }
Choice represents a choice in a combo box.
type ComboBox ¶
type ComboBox []Choice
ComboBox represents an immutable combo box of items. ComboBox implements SelectModel.
func (ComboBox) ToSelection ¶
type PageBreadCrumb ¶
type PageBreadCrumb struct { // the currennt URL URL *url.URL // The page number URL parameter name PageNoParam string // The zero based page number PageNo int // Whether or not we are at last page. End bool }
PageBreadCrumb is used for displaying the page breadcrumb
func (*PageBreadCrumb) DisplayPageNo ¶
func (p *PageBreadCrumb) DisplayPageNo() int
DisplayPageNo returns the 1-based page number.
func (*PageBreadCrumb) NextPageLink ¶
func (p *PageBreadCrumb) NextPageLink() *url.URL
NextPageLink returns the URL for the next page.
func (*PageBreadCrumb) PrevPageLink ¶
func (p *PageBreadCrumb) PrevPageLink() *url.URL
PrevPageLink returns the URL for the previous page.
type SelectModel ¶
type SelectModel interface { // ToSelection converts a parameter value to a selection. ToSelection may // return nil if value does not map to a valid selection. ToSelection(s string) *Selection }
SelectModel converts a parameter value to a selection.
type Selection ¶
type Selection struct { // Value is the value of the selection Value string // Name is what is displayed for the selection Name string }
Selection represents a single selection from a drop down
type Selections ¶
type Selections []Selection
Selections implements SelectModel
func (Selections) ToSelection ¶
func (s Selections) ToSelection(str string) *Selection
type Values ¶
Values is a wrapper around url.Values providing additional methods.
func (Values) GetSelection ¶
func (v Values) GetSelection( model SelectModel, name string) *Selection
GetSelection gets the current selection. name is the request parameter name. GetSelection may return nil if there is no valid selection.