Documentation
¶
Index ¶
- Constants
- Variables
- func HandleRenderPageEndPoint(api_endpoint string, val AnEndpointType) (fx func(www http.ResponseWriter, req *http.Request))
- func HandleRenderPartial(www http.ResponseWriter, req *http.Request)
- func HasTemplate(TemplateCtl *TmplObj, name string) (hasIt bool)
- func OpToMethod(op string) (method string)
- func PathFind(path, fn string) (full_path, file_type string, err error)
- func ProcessSQL(ds *JsonTemplateRunnerType, ...) (mdata map[string]interface{}, err error)
- func RenderTemplate(mdata map[string]interface{}, tmplList string, fns ...string) (tmpl_rendered string, err error)
- func RenderTemplateByName(name string, mdata map[string]interface{}, tmplList string, fns ...string) (tmpl_rendered string, err error)
- func ReturnHandleRenderPage(endPoint string) func(www http.ResponseWriter, req *http.Request)
- func RowsToInterface(rows *sql.Rows) ([]map[string]interface{}, string, int)
- func Run1(db *sql.DB, q string, arg ...interface{}) error
- func SelData2(db *sql.DB, q string, data ...interface{}) ([]map[string]interface{}, error)
- func SelQ(db *sql.DB, q string, data ...interface{}) (Rows *sql.Rows, err error)
- func SetDbOn(x *map[string]bool, y *sync.Mutex)
- func SetGPath(s string)
- func SetupExTmplModels(fnGroup, fnModel string) (err error)
- func SetupMux(mux *ymux.ServeMux, lf *os.File, cfg *ExTmplConfig, xDB *sql.DB, ...)
- func SetupNoDoc(b bool)
- func SetupTemplate(tmplList string, fns ...string) (tmpl *template.Template, err error)
- func TmplProcess(item string, tmpl_name string, dataFunc func(name string, tmplIt bool) string) (tmpl_rendered string, status int, err error)
- func TmplProcessInternal(item string, tmpl_name string, path string, ...) (body, data, tmpl_rendered string, status int, err error)
- func TmplTest(item string, tmpl string, test_name string)
- type AnEndpointType
- type BindType
- type BodyConfigType
- type ColumnType
- type ExTmplConfig
- type ExTmplateAPIConfigData
- type GroupItemType
- type GroupType
- type HeaderConfigType
- type JsonTemplateRunnerType
- type LayoutItemType
- type ModelTable
- type ModelType
- type MyDb
- type RelationsToType
- type SelectDataType
- type SelectValueType
- type TemplateSetType
- type TmplObj
Constants ¶
const ISO8601 = "2006-01-02T15:04:05.99999Z07:00"
ISO format for date
const ISO8601output = "2006-01-02T15:04:05.99999-0700"
ISO format for date
Variables ¶
var DB *sql.DB
var DbBeginQuote = `"`
var DbEndQuote = `"`
var DbOn *map[string]bool
var DbOnLock *sync.Mutex
var ValidRelationType = []string{
"1:N",
"N:1",
"1:0..1",
"1:1..N",
"1:1",
}
Functions ¶
func HandleRenderPageEndPoint ¶
func HandleRenderPageEndPoint(api_endpoint string, val AnEndpointType) (fx func(www http.ResponseWriter, req *http.Request))
HandleRenderPageEndPoint is a closure returing a http.Handler function - the funtion renders Page and Parital end points (default "page"). This is the main handler for ./tmpl1/setup.json end points. ./tmpl1/setup.json maps an endpoint to a pair of files. A JSON file that contains select(s) and the set of pages that can be rendered.
{ "api": {
...
...
...
, "/create-dev-un-pw-acct.html": {
"page_name": "create-dev-un-pw-acct.json"
, "path": "./tmpl1"
, "auth_required": true
}
...
...
...
} }
In this case the end point is `/create-dev-un-pw-acct.html`. This maps to the JSON setup file that is found in using the ./tmpl1 path. This end point requires login.
The JSON setup file specifies the set of pages that can be rendered.
{
"TemplateSet": {
"page": {
"Template": [ "page.html", "create-dev-un-pw-acct.html" ]
}
, "partial": {
"Template": [ "partial-page.html", "create-dev-un-pw-acct.html" ]
}
},
"SelectData": [ ]
}
In this case for a page_type of "partial" the set of templates is ./tmpl1/partial-page.html and ./tmpl1/create-dev-un-pw-acct.html. There is no slect data used.
DebugFlags:
DumpTemplate - tracing informaiton. DumpTemplateStderr Print complteted template out to Stderr DumpTemplateLogFile Print complteted template out to LogFile
func HandleRenderPartial ¶
func HandleRenderPartial(www http.ResponseWriter, req *http.Request)
func HasTemplate ¶
HasTemplate returns true if the tempalte named `name` is in the set of defined templates.
func OpToMethod ¶
func PathFind ¶
full_path, file_type, err := PathFind(path, tmpl_name) PathFind searches each location in the path for the specified file. It returns the first full file name that is found or an error of "Not Found" path - top level directory to search in. fn - file name or pattern to search for.
func ProcessSQL ¶
func ProcessSQL(ds *JsonTemplateRunnerType, getDataForSQL func(name string, tmplIt bool) string, TemplateCtl *TmplObj) (mdata map[string]interface{}, err error)
ProcessSQL will run sql statments and collect the data for use in temlates.
func RenderTemplate ¶
func RenderTemplate(mdata map[string]interface{}, tmplList string, fns ...string) (tmpl_rendered string, err error)
RenderTemplate will take the data in mdata and combine the templates and render the resulting template. The template that is rendered is "render". Each of the files, fns, is a full path to a file to render. Example Call: tmpl_rendered, err = RenderTemplate(mdata, full_path)
func RenderTemplateByName ¶
func ReturnHandleRenderPage ¶
func ReturnHandleRenderPage(endPoint string) func(www http.ResponseWriter, req *http.Request)
func RowsToInterface ¶
------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------
func Run1 ¶
------------------------------------------------------------------------------------------------- test: t-run1q.go, .sql, .out -------------------------------------------------------------------------------------------------
func SelData2 ¶
------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------
func SelQ ¶
------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------
func SetupExTmplModels ¶
func SetupTemplate ¶
func TmplProcess ¶
func TmplProcessInternal ¶
Types ¶
type AnEndpointType ¶
type AnEndpointType struct {
PageName string `json:"page_name" default:"app.json"`
Path string `json:"path" default:"./tmpl1"`
DebugFlags []string `json:"debug_flags"`
AuthRequired bool `json:"auth_required"`
NoDoc bool `json:"NoDoc"`
DocTag string `json:"DocTag"`
InputList []*ymux.MuxInput `json:"InputList"`
// contains filtered or unexported fields
}
type BodyConfigType ¶
type ColumnType ¶
type ColumnType struct {
ColName string `json:"ColName"`
Type string //
TmplType string `json:"TmplType"` // convert from 's' -> Stringt, but allow setting for other special types like "File"
MinLen int `json:"MinLen"`
MaxLen int `json:"MaxLen"`
ValidationRE string `json:"ValidationRE"`
ValidationType string `json:"ValidationType"`
Name string //
Label string //
SelectValues []SelectValueType `json:"SelectValues"`
}
type ExTmplConfig ¶
type ExTmplConfig struct {
TemplatePath string `json:"template_path" default:"./tmpl1"` // xyzzy2
BasePage string `json:"base_page" default:"index.html"`
TemplateAPIConfig string `json:"tmpl_api_config" default:"./tmpl1/setup.json"`
ExTmplGroup string `json:"tmpl_group" default:"./tmpl1/group.json"`
ExTmplModel string `json:"tmpl_model" default:"./tmpl1/model.json"`
}
type ExTmplateAPIConfigData ¶
type ExTmplateAPIConfigData struct {
API map[string]AnEndpointType `json:"api"`
}
type GroupItemType ¶
type GroupItemType struct {
AnEndpointType
PrimaryTable string `json:"primary_table"`
RelatedTableList []string `json:"related_table_list"`
LayoutFormat string `json:"layout_format"`
MetaRelationship string `json:"MetaRelationship"`
Stmt string `json:"Stmt"`
Bind BindType `json:"Bind"`
StmtDetail string `json:"StmtDetail"`
BindDetail BindType `json:"BindDetail"`
}
type GroupType ¶
type GroupType map[string]GroupItemType
type HeaderConfigType ¶
type HeaderConfigType struct {
ColumnTitle string
ColumnName string
ColumnPos int
IsAdd bool
AddTemplate string // new
AddTemplateByCol []string // new
HdrTemplate string // new
HdrTemplateByCol []string // new
}
Run multiple selects
select: [ { "to": "name" "stmt": "select..." "errror_on": 0 rows etc. } , { "to": "name...x" "stmt": "select..." "errror_on": 0 rows etc. "bind": [ "$1": "{{.name}}" ] } ]
Bind values by name from GET/POST and previous queries
Run Template at the end
"template": [ "base.html", "tmpl1.html" ... ]
Set of request for template
"TemplateSet": { "page_name": { "template": [ "full_page.html", "extend1.tmpl" ] } , "partial": { "template": [ "section.html", "extend1.tmpl" ] , "target": "body" } }
Layout Info "jsonLayout": { -- data for layout / style of layout }
Testing "test": [ { "data": { "user_id": "123" } , "expect": ... } ]
Notes:
.MuxName -- Name of page we are displaying .HeaderInfo[] -- slice of column header info .HeaderInfo[].ColumnTitle -- title for column .HeaderInfo[]. ?? sort info ?? -- todo - future - sort/filter info for a column $row.id -- Per row (t_ymux_documents) - Unique PK/Id for the column $row.data -- The set of data in a column (may have more than displayed) .data["MuxName"][$row.pos] -- The data for a particular table/row .data["MuxName"][$row.pos][$col.name] -- A single data item $row.BodyInfo[] -- Data for the displayed columns $row.BodyInfo[].coldata -- a single data item to be displayed .t_ymux_documents [[ primary table name ]]
type JsonTemplateRunnerType ¶
type JsonTemplateRunnerType struct {
TemplateList []string `json:"Template"`
TemplateSet map[string]TemplateSetType `json:"TemplateSet"`
SelectData []SelectDataType `json:"SelectData"`
}
func ReadJsonTemplateConfigFile ¶
func ReadJsonTemplateConfigFile(fn string) (ds JsonTemplateRunnerType, err error)
ds, err := ReadJsonTemplateConfigFile(full_paty)
type LayoutItemType ¶
type ModelTable ¶
type ModelTable struct {
Table string
Api string
SelectApi string
Relations []RelationsToType
Columns []ColumnType
}
Example Data // ---------------------------------------------------------------------------------------------- xyzzy4
type ModelType ¶
type ModelType struct {
Primary map[string]ModelTable
}
type RelationsToType ¶
type SelectDataType ¶
type SelectDataType struct {
To string // Name of data item to place data in. (MuxData?)
Stmt string // SQL ro run
Bind map[string]string //
ErrOn string // Xyzzy - needs work
UpdateAPI string // what to call for Update/Delete/Insert
UpdateColumns []string //
InsertColumns []string //
MuxName string `json:"MuxName"` // Primary Table Name
DetailName string `json:"DetailName"` //
HeaderInfo []HeaderConfigType `json:"HeaderInfo"` //
BodyInfo []BodyConfigType `json:"BodyInfo"` //
}
type SelectValueType ¶
type TemplateSetType ¶
type TemplateSetType struct {
TemplateList []string `json:"Template"`
}