Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultTemplateSet = &TemplateSet{}
default templates associated with their respective file extension. This can be modified before calling the (*Router).SqlXXX methods to change the default templates. The init functions of the various template/xxx packages each register their respective default template.
var IsolationLevel = sql.LevelSerializable
IsolationLevel is the level passed to sql.TxOptions when running queries in transactions.
TODO: verify it is supported by all supported database drivers.
var TemplateFuncs = map[string]interface{}{ "add": add, "mod": mod, "join": strings.Join, "split": strings.Split, "tex": TeXEscaper, }
Functions ¶
func TeXEscapeString ¶
func TeXEscaper ¶
func TeXEscaper(v interface{}) interface{}
Types ¶
type Executer ¶
type Executer interface { // Execute the template with data, and write the output to wr. Execute(wr io.Writer, data interface{}) error }
Executer wraps method Execute. Both text/template.Template and html/template.Template implement this interface.
type Router ¶
type Router struct { *httprouter.Router *sql.DB // contains filtered or unexported fields }
func (*Router) ServeHTTP ¶
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP wraps the embedded httprouter.Router ServeHTTP to handle file extensions.
func (*Router) SqlGET ¶
func (r *Router) SqlGET(path string, queries []Query, templates *TemplateSet)
SqlGET registers the path pattern to send the given queries on the database upon GET requests.
The path given is the pattern without file extension. When matched against a request URL, the URL file extensions is used to find the template used (defaulting to ".html").
The list of templates used for the responses is provided with tmpl. It defaults to DefaultTemplateSet if nil.
func (*Router) SqlPOST ¶
func (r *Router) SqlPOST(path string, queries []Query, templates *TemplateSet)
SqlPOST registers the path pattern to execute the given queries on the database upon POST requests.
The path given is the pattern without file extension. When matched against a request URL, the URL file extensions is used to find the template used (defaulting to ".html").
The list of templates used for the responses is provided with tmpl. It defaults to DefaultTemplateSet if nil.
type Row ¶
type Row struct { Header []string Values []interface{} }
Row represents a row of query result. The Headers are present for column name lookup of the row data.
type Template ¶
type Template interface { Executer // string to return with the Content-Type Header value. ContentType() string }
Template is the interface used to format the queried data back to the http Response.
It wraps interface Executer with a ContentType method.
func TemplateFromExecuter ¶
TemplateFromExecuter returns a Template with the given content type string.
type TemplateSet ¶
type TemplateSet struct {
// contains filtered or unexported fields
}
TemplateSet represents a set of templates, stored by file extension.
func (*TemplateSet) Clone ¶
func (ts *TemplateSet) Clone() *TemplateSet
Clone returns a shallow copy of ts. It allocates a new map, however if the Templates associated with ts are pointers, then the returned TemplateSet will use the same pointers.
This is typically used to tune part of the templates of DefaultTemplateSet. For example:
t := DefaultTemplateSet.Clone() t[".json"] = myJSONTemplate router.SqlGet(path, queries, t)
func (*TemplateSet) Get ¶
func (ts *TemplateSet) Get(ext string) Template
func (*TemplateSet) Register ¶
func (ts *TemplateSet) Register(ext string, t Template)
Notes ¶
Bugs ¶
is modifying req.URL.Path prone to problems?