router

package
v0.0.0-...-ce6b2e3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2024 License: MIT Imports: 32 Imported by: 3

Documentation

Index

Constants

View Source
const (
	KB = 1000
	MB = KB * 1000
	GB = MB * 1000
)
View Source
const DATE_LAYOUT = "Monday, January 2, 2006 15:04"
View Source
const HUMAN = "Monday, January 2, 2006 3:04 PM"
View Source
const HUMAN_SMALL = "01/02/2006"

Variables

View Source
var BuildTag string
View Source
var CustomFuncMap *template.FuncMap
View Source
var DB_FLAVOR = "pg"
View Source
var EmbeddedAssets embed.FS
View Source
var EmbeddedTemplates embed.FS
View Source
var UseJsonToMakeTablesAndIndexes = true
View Source
var UseLiveTemplates = os.Getenv("USE_LIVE_TEMPLATES") == "true"
View Source
var WasmTag string

Functions

func AddSearchResults

func AddSearchResults(c *Context, field, token string, allRows map[int64]any)

func CastFields

func CastFields(model *models.Model, m map[string]any)

func CastFieldsPg

func CastFieldsPg(model *models.Model, m map[string]any)

func CastFieldsSqlite

func CastFieldsSqlite(model *models.Model, m map[string]any)

func CreateSession

func CreateSession(c *Context)

func Default404

func Default404(r *Router, c *Context)

func DestroySession

func DestroySession(c *Context)

func DollarSigns

func DollarSigns(size int) string

func FetchOneRow

func FetchOneRow(db *sqlx.DB, model *models.Model, guid string) map[string]any

func Filelog

func Filelog(fields ...any)

func GetCookie

func GetCookie(c *Context, name string) string

func GetEditableCols

func GetEditableCols(c *Context, modelString string) ([]string, map[string]string)

func HandleCreateSessionAutoForm

func HandleCreateSessionAutoForm(c *Context)

func HandleCreateUserAutoForm

func HandleCreateUserAutoForm(c *Context, username string) string

func HandleSessions

func HandleSessions(c *Context, second, third string)

func HashPassword

func HashPassword(password string) string

func InitNewApp

func InitNewApp(path string)

func IsAdmin

func IsAdmin(user map[string]any) bool

func IsEditable

func IsEditable(item string, editable map[string]string) bool

func LoadLiveTemplates

func LoadLiveTemplates(tf template.FuncMap) *template.Template

func LoadTemplates

func LoadTemplates(tf template.FuncMap) *template.Template

func MakeGuidsInTable

func MakeGuidsInTable(db *sqlx.DB, model *models.Model)

func MakeGuidsInTables

func MakeGuidsInTables(db *sqlx.DB, models []*models.Model)

func MakeTable

func MakeTable(db *sqlx.DB, model *models.Model)

func MakeTables

func MakeTables(db *sqlx.DB, models []*models.Model)

func MakeWasmScript

func MakeWasmScript(tag, s string) template.HTML

func MakeWasmScript2

func MakeWasmScript2(tag, s string) template.HTML

func Markup

func Markup(c *Context, second, third string)

func ModelsCreateWithId

func ModelsCreateWithId(c *Context, id string)

func ModelsShow

func ModelsShow(c *Context, rawId string)

func ModelsToBytes

func ModelsToBytes(list []*models.Model) []byte

func NotLoggedIn

func NotLoggedIn(c *Context) bool

func ParseNumbers

func ParseNumbers(c *Context, cols []string, editable map[string]string)

func Redirect

func Redirect(c *Context, path string)

func RenderMarkup

func RenderMarkup()

func SaveMultiFilesAws

func SaveMultiFilesAws(c *Context, guid string)

func SetCookie

func SetCookie(c *Context, name, value string)

func SetCors

func SetCors(c *Context)

func SetCorsOptions

func SetCorsOptions(c *Context)

func SetFlash

func SetFlash(c *Context, flash string)

func SetUser

func SetUser(c *Context, guid, domain string)

func StringIds

func StringIds(ids []any) []string

func TemplateFunctions

func TemplateFunctions() template.FuncMap

func TimezoneList

func TimezoneList(tz string) template.HTML

Types

type Batch

type Batch struct {
	TheFunc func(*Context, string, string)
	Context *Context
	Second  string
	Third   string
	Params  string
}

type BatchWriter

type BatchWriter struct {
	http.ResponseWriter
	TheHeader http.Header
	Route     string
	Code      int
}

func NewBatchWriter

func NewBatchWriter(route string) *BatchWriter

func (*BatchWriter) Header

func (w *BatchWriter) Header() http.Header

func (*BatchWriter) Write

func (w *BatchWriter) Write(data []byte) (int, error)

func (*BatchWriter) WriteHeader

func (w *BatchWriter) WriteHeader(statusCode int)

type Context

type Context struct {
	Writer  http.ResponseWriter
	Request *http.Request

	Router       *Router
	User         map[string]any
	UserRequired bool

	Db       *sqlx.DB
	Dbs      []*sqlx.DB
	NotFound bool
	Method   string

	Layout     string
	Params     map[string]any
	Title      string
	LayoutMap  map[string]any
	ParamMutex sync.Mutex
	Client     *http.Client
	Batch      bool
	BatchThing any
	// contains filtered or unexported fields
}

func PrepareContext

func PrepareContext(r *Router, user map[string]any, path, flash string, writer http.ResponseWriter, request *http.Request) *Context

func (*Context) All

func (c *Context) All(modelName string, where, offset string, params ...any) []map[string]any

func (*Context) AllIn

func (c *Context) AllIn(field, modelName string, offset, other string, tokens []any) []map[string]any

func (*Context) BodyAsString

func (c *Context) BodyAsString() string

func (*Context) CopyContext

func (c *Context) CopyContext() *Context

func (*Context) Count

func (c *Context) Count(modelName string, whereString string, params []any) int64

func (*Context) Decorate

func (c *Context) Decorate(list []map[string]any) []string

func (*Context) DecorateList

func (c *Context) DecorateList(list []map[string]any)

func (*Context) DecorateListWithFields

func (c *Context) DecorateListWithFields(list []map[string]any,
	fields map[string]bool)

func (*Context) DecorateSingle

func (c *Context) DecorateSingle(item map[string]any)

func (*Context) Delete

func (c *Context) Delete(modelName, fieldName string, id any)

func (*Context) ExecuteTemplate

func (c *Context) ExecuteTemplate(filename string, vars any)

func (*Context) FindModel

func (c *Context) FindModel(name string) *models.Model

func (*Context) FreeFormSelect

func (c *Context) FreeFormSelect(sql string, params ...any) []map[string]any

func (*Context) FreeFormUpdate

func (c *Context) FreeFormUpdate(sql string, params ...any) error

func (*Context) FunctionToRun

func (c *Context) FunctionToRun(route string, user map[string]any) *Batch

func (*Context) Insert

func (c *Context) Insert(modelString string) string

func (*Context) LookupUser

func (c *Context) LookupUser(guid string) map[string]any

func (*Context) LookupUserByToken

func (c *Context) LookupUserByToken(token string) map[string]any

func (*Context) LookupUsername

func (c *Context) LookupUsername(username string) map[string]any

func (*Context) MakeCells

func (c *Context) MakeCells(list []any, headers []string, thing any, prefix string) [][]any

func (*Context) Model

func (c *Context) Model(modelName string) *models.Model

func (*Context) Models

func (c *Context) Models() []*models.Model

func (*Context) One

func (c *Context) One(modelName string, where string, params ...any) map[string]any

func (*Context) OneWithIndex

func (c *Context) OneWithIndex(index int64, modelName string, where string, params ...any) map[string]any

func (*Context) ReadFormPost

func (c *Context) ReadFormPost()

func (*Context) ReadFormValuesIntoParams

func (c *Context) ReadFormValuesIntoParams(list ...string)

func (*Context) ReadJsonBodyAsArray

func (c *Context) ReadJsonBodyAsArray() []any

func (*Context) ReadJsonBodyIntoParams

func (c *Context) ReadJsonBodyIntoParams()

func (*Context) ReadJsonBodyIntoParamsWithLog

func (c *Context) ReadJsonBodyIntoParamsWithLog(file string)

func (*Context) ReadMultipleFormValues

func (c *Context) ReadMultipleFormValues(list ...string)

func (*Context) RegexMap

func (c *Context) RegexMap(s string) map[string]string

func (*Context) SelectAll

func (c *Context) SelectAll(modelName string, where string, params []any, offset string) []map[string]any

func (*Context) SelectOne

func (c *Context) SelectOne(modelName string, where string, params []any) map[string]any

func (*Context) SendContentAsJson

func (c *Context) SendContentAsJson(thing any, status int)

func (*Context) SendContentAsJsonMessage

func (c *Context) SendContentAsJsonMessage(message string, status int)

func (*Context) SendContentForAjax

func (c *Context) SendContentForAjax(doZip bool, user map[string]any, writer http.ResponseWriter,
	filename string, contentVars any, status int)

func (*Context) SendContentInLayout

func (c *Context) SendContentInLayout(filename string, vars any, status int)

func (*Context) SendIntAsJson

func (c *Context) SendIntAsJson(wrapper string, val int64)

func (*Context) SendRowAsJson

func (c *Context) SendRowAsJson(wrapper string, row map[string]any)

func (*Context) TableJson

func (c *Context) TableJson(tableName string)

func (*Context) TableJsonParams

func (c *Context) TableJsonParams(tableName, where string, params ...any)

func (*Context) Template

func (c *Context) Template(name string, vars any) template.HTML

func (*Context) TimezoneList

func (c *Context) TimezoneList(list []map[string]any,
	field1, field2 string, tz *time.Location)

func (*Context) Update

func (c *Context) Update(modelString, where string, lastParam any) string

func (*Context) UpdateOne

func (c *Context) UpdateOne(modelName, setString, whereString string, params []any) error

func (*Context) UpdateWithIndex

func (c *Context) UpdateWithIndex(index int64, sql string, params ...any) error

func (*Context) Upsert

func (c *Context) Upsert(modelString, where string, lastParam any) string

func (*Context) Validate

func (c *Context) Validate(create bool, fields []*models.Field) string

func (*Context) ValidateAndInsert

func (c *Context) ValidateAndInsert(modelString string) string

func (*Context) ValidateAndUpsert

func (c *Context) ValidateAndUpsert(modelString, field string, val any) string

func (*Context) ValidateCreate

func (c *Context) ValidateCreate(modelString string) string

func (*Context) ValidateOneField

func (c *Context) ValidateOneField(modelString, fieldString, value string) bool

func (*Context) ValidateUpdate

func (c *Context) ValidateUpdate(modelString string) string

func (*Context) WhereIn

func (c *Context) WhereIn(modelString string, ids []any) MI64MSA

func (*Context) WhereInList

func (c *Context) WhereInList(modelString string, ids []any) []map[string]any

func (*Context) WhereInWithId

func (c *Context) WhereInWithId(modelString, id string, ids []any) map[int64]map[string]any

func (*Context) WithIndex

func (c *Context) WithIndex(index int64, sql string, params ...any) []map[string]any

func (*Context) Wrangle

func (c *Context) Wrangle(s *FeedbackSite) *Context

type FeedbackSite

type FeedbackSite struct {
	Footer  string          `json:"footer"`
	Title   string          `json:"title"`
	Models  []*models.Model `json:"models"`
	Routes  []*models.Route `json:"routes"`
	Dynamic []*models.Model `json:"dynamic"`
}

func (*FeedbackSite) FindDynamic

func (s *FeedbackSite) FindDynamic(id string) *models.Model

func (*FeedbackSite) FindField

func (s *FeedbackSite) FindField(model *models.Model, id string) *models.Field

func (*FeedbackSite) FindModel

func (s *FeedbackSite) FindModel(id string) *models.Model

func (*FeedbackSite) FindModelOrDynamic

func (s *FeedbackSite) FindModelOrDynamic(id string) *models.Model

type FieldVars

type FieldVars struct {
	Model *models.Model
	Rows  []*models.Field
	Row   map[string]any
}

type MI64MSA

type MI64MSA map[int64]map[string]any

type MSA

type MSA map[string]any

type MSAS

type MSAS map[string][]string

type MSMAB

type MSMAB map[string]map[any]bool

type ModelVars

type ModelVars struct {
	Model *models.Model
	Rows  []map[string]any
}

type ModelsVars

type ModelsVars struct {
	Models     []*models.Model
	SchemaJson string
}

type Router

type Router struct {
	Template        *template.Template
	Site            *FeedbackSite
	Db              *sqlx.DB
	Dbs             []*sqlx.DB
	WrangleDb       *sqlx.DB
	Prefix          string
	BucketPath      string
	Paths           map[string]func(*Context, string, string)
	BeforeCreate    map[string]func(*Context)
	AfterCreate     map[string]func(*Context, string)
	PathLock        sync.Mutex
	AfterLock       sync.Mutex
	BeforeLock      sync.Mutex
	DefaultLayout   string
	BearerAuthFunc  func(*Context) map[string]any
	CookieAuthFunc  func(*Context) map[string]any
	NotFoundFunc    func(*Router, *Context)
	BeforeAll       func(*Context)
	NotLoggedInPath string
}

func NewRouter

func NewRouter(dbEnvVarName string, jsonBytes []byte) *Router

func (*Router) All

func (r *Router) All(modelName string, where, offset string, params ...any) []map[string]any

func (*Router) FindModel

func (r *Router) FindModel(name string) *models.Model

func (*Router) FreeFormSelect

func (r *Router) FreeFormSelect(sql string, params ...any) []map[string]any

func (*Router) FreeFormUpdate

func (r *Router) FreeFormUpdate(sql string, params ...any) error

func (*Router) GetLiveOrCachedTemplate

func (r *Router) GetLiveOrCachedTemplate(name string) *template.Template

func (*Router) HandleAsset

func (r *Router) HandleAsset(path string, writer http.ResponseWriter, request *http.Request)

func (*Router) HandleBucketAsset

func (r *Router) HandleBucketAsset(path string, writer http.ResponseWriter, request *http.Request)

func (*Router) ListenAndServe

func (r *Router) ListenAndServe(port string)

func (*Router) ListenAndServeTLS

func (r *Router) ListenAndServeTLS()

func (*Router) LookupUser

func (r *Router) LookupUser(guid string) map[string]any

func (*Router) LookupUserByToken

func (r *Router) LookupUserByToken(token string) map[string]any

func (*Router) LookupUsername

func (r *Router) LookupUsername(username string) map[string]any

func (*Router) One

func (r *Router) One(modelName string, where string, params ...any) map[string]any

func (*Router) PlaceContentInLayoutMap

func (r *Router) PlaceContentInLayoutMap(layoutMap map[string]any, flash string, user map[string]any, filename string, vars any)

func (*Router) ResetDatabase

func (r *Router) ResetDatabase()

func (*Router) RouteFromRequest

func (r *Router) RouteFromRequest(writer http.ResponseWriter, request *http.Request)

func (*Router) SelectAll

func (r *Router) SelectAll(modelName string, where string, params []any, offset string) []map[string]any

func (*Router) SelectOne

func (r *Router) SelectOne(modelName string, where string, params []any) map[string]any

func (*Router) SendContentInLayout

func (r *Router) SendContentInLayout(doZip bool, layout string, layoutMap map[string]any, flash string, user map[string]any, writer http.ResponseWriter,
	filename string, contentVars any, status int)

func (*Router) ToContext

func (r *Router) ToContext() *Context

func (*Router) WhereInFull

func (r *Router) WhereInFull(modelString string, ids []any) []map[string]any

type UploadedFile

type UploadedFile struct {
	OrigName     string
	GuidFilename string
	Size         int64
}

func SaveMultiFiles

func SaveMultiFiles(c *Context, path, newName string) []UploadedFile

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL