util

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_MODULE        = "ace"
	DOC_MODULE            = "doc"
	TABLE_MODULE          = "table"
	APP                   = "app"
	PAGE                  = "page"
	FRAGMENT              = "fragment"
	STYLE                 = "style"
	REDIRECT              = "redirect"
	PERMISSION            = "permission"
	RESPONSE              = "response"
	LIBRARY               = "library"
	DEFAULT_REDIRECT_CODE = 303
)
View Source
const (
	// Constants included in the ace builtin module
	GET    = "GET"
	POST   = "POST"
	PUT    = "PUT"
	DELETE = "DELETE"
	HTML   = "HTML"
	JSON   = "JSON"
	TEXT   = "TEXT"
)
View Source
const (
	APP_FILE_NAME         = "app.star"
	APP_CONFIG_KEY        = "app"
	DEFAULT_HANDLER       = "handler"
	ERROR_HANDLER         = "error_handler"
	METHODS_DELIMITER     = ","
	CONFIG_LOCK_FILE_NAME = "config_gen.lock"
	SCHEMA_FILE_NAME      = "schema.star"
	BUILTIN_PLUGIN_SUFFIX = "in"
	STARLARK_FILE_SUFFIX  = ".star"
	INDEX_FILE            = "index.go.html"
	INDEX_GEN_FILE        = "index_gen.go.html"
	CLACE_GEN_FILE        = "clace_gen.go.html"
	ACCOUNT_SEPERATOR     = "#"
)
View Source
const (
	TYPE  = "type"
	FIELD = "field"
	INDEX = "index"
)
View Source
const COMPRESSION_TYPE = "br" // brotli uses br as the encoding type

Variables

This section is empty.

Functions

func CreateBuiltin

func CreateBuiltin() starlark.StringDict

func FileServer

func FileServer(fsys *SourceFs) http.Handler

FileServer returns an http.Handler for serving FS files. It provides a simplified implementation of http.FileServer which is used to aggressively cache files on the client since the file hash is in the filename.

Because FileServer is focused on small known path files, several features of http.FileServer have been removed including canonicalizing directories, defaulting index.html pages, precondition checks, & content range headers.

func FormatName

func FormatName(filename, hash string) string

FormatName returns a hash name that inserts hash before the filename's extension. If no extension exists on filename then the hash is appended. Returns blank string the original filename if hash is blank. Returns a blank string if the filename is blank.

func GetBoolAttr

func GetBoolAttr(s starlark.HasAttrs, key string) (bool, error)

func GetIntAttr

func GetIntAttr(s starlark.HasAttrs, key string) (int64, error)

func GetListStringAttr

func GetListStringAttr(s starlark.HasAttrs, key string, optional bool) ([]string, error)

func GetStringAttr

func GetStringAttr(s starlark.HasAttrs, key string) (string, error)

func GetStringList added in v0.4.0

func GetStringList(list *starlark.List) ([]string, error)

func LoadStoreInfo added in v0.4.0

func LoadStoreInfo(fileName string, data []byte) (*utils.StoreInfo, error)

func ParseName

func ParseName(filename string) (base, hash string)

ParseName splits formatted hash filename into its base & hash components.

func ReadStoreInfo added in v0.4.0

func ReadStoreInfo(fileName string, inp []byte) (*utils.StoreInfo, error)

Types

type AppConfig

type AppConfig struct {
	Routing RouteConfig `json:"routing"`
	Htmx    HtmxConfig  `json:"htmx"`
}

func NewAppConfig

func NewAppConfig() *AppConfig

NewAppConfig creates an AppConfig with default values. This config is used when lock file is not present. The config file load order is

DefaultAppConfig -> StarlarkAppConfig

func NewCompatibleAppConfig

func NewCompatibleAppConfig() *AppConfig

NewCompatibleAppConfig creates an AppConfig focused on maintaining backward compatibility. This is used when the app is created from a source url where the source has the config lock file present. The configs are read in the order

CompatibleAppConfig -> LockFile -> StarlarkAppConfig

The goal is that if the application has a lock file, then all settings will attempt to be locked such that there should not be any change in behavior when the Clace version is updated. Removing the lock file will result in new config defaults getting applied, which can be done when the app developer wants to do an application refresh. Refresh will require additional testing to ensure that UI functionality is not changed..

type DiskReadFS added in v0.2.0

type DiskReadFS struct {
	*utils.Logger
	// contains filtered or unexported fields
}

func NewDiskReadFS added in v0.2.0

func NewDiskReadFS(logger *utils.Logger, root string) *DiskReadFS

func (*DiskReadFS) Glob added in v0.2.0

func (d *DiskReadFS) Glob(pattern string) (matches []string, err error)

func (*DiskReadFS) Open added in v0.2.0

func (d *DiskReadFS) Open(name string) (fs.File, error)

func (*DiskReadFS) ReadFile added in v0.2.0

func (d *DiskReadFS) ReadFile(name string) ([]byte, error)

func (*DiskReadFS) Reset added in v0.3.0

func (d *DiskReadFS) Reset()

func (*DiskReadFS) Stat added in v0.2.0

func (d *DiskReadFS) Stat(name string) (fs.FileInfo, error)

func (*DiskReadFS) StaticFiles added in v0.3.0

func (d *DiskReadFS) StaticFiles() []string

type DiskWriteFS added in v0.2.0

type DiskWriteFS struct {
	*DiskReadFS
}

func (*DiskWriteFS) Remove added in v0.2.0

func (d *DiskWriteFS) Remove(name string) error

func (*DiskWriteFS) Write added in v0.2.0

func (d *DiskWriteFS) Write(name string, bytes []byte) error

type HtmxConfig

type HtmxConfig struct {
	Version string `json:"version"`
}

type RouteConfig

type RouteConfig struct {
	TemplateLocations []string `json:"template_locations"`
	BaseTemplates     string   `json:"base_templates"`
	StaticDir         string   `json:"static_dir"`
	StaticRootDir     string   `json:"static_root_dir"`
	PushEvents        bool     `json:"push_events"`
	EarlyHints        bool     `json:"early_hints"`
}

type SourceFs added in v0.2.0

type SourceFs struct {
	utils.ReadableFS
	Root string
	// contains filtered or unexported fields
}

SourceFs is the implementation of source file system

func NewSourceFs added in v0.2.0

func NewSourceFs(dir string, fs utils.ReadableFS, isDev bool) (*SourceFs, error)

func (*SourceFs) ClearCache added in v0.2.0

func (f *SourceFs) ClearCache()

func (*SourceFs) Glob added in v0.2.0

func (f *SourceFs) Glob(pattern string) ([]string, error)

func (*SourceFs) HashName added in v0.2.0

func (f *SourceFs) HashName(name string) string

HashName returns the hash name for a path, if exists. Otherwise returns the original path.

func (*SourceFs) Open added in v0.2.0

func (f *SourceFs) Open(name string) (fs.File, error)

Open returns a reference to the named file. If name is a hash name then the underlying file is used.

func (*SourceFs) ParseFS added in v0.2.0

func (f *SourceFs) ParseFS(funcMap template.FuncMap, patterns ...string) (*template.Template, error)

func (*SourceFs) ParseName added in v0.2.0

func (f *SourceFs) ParseName(filename string) (base, hash string)

ParseName splits formatted hash filename into its base & hash components.

func (*SourceFs) Stat added in v0.2.0

func (f *SourceFs) Stat(name string) (fs.FileInfo, error)

func (*SourceFs) StaticFiles added in v0.3.0

func (f *SourceFs) StaticFiles() []string

type WorkFs added in v0.2.0

type WorkFs struct {
	utils.WritableFS
	Root string
}

WorkFs is the implementation of work file system

func NewWorkFs added in v0.2.0

func NewWorkFs(dir string, fs utils.WritableFS) *WorkFs

NewWorkFs creates a new work file system

type WritableSourceFs added in v0.2.0

type WritableSourceFs struct {
	*SourceFs
}

func (*WritableSourceFs) Remove added in v0.2.0

func (w *WritableSourceFs) Remove(name string) error

func (*WritableSourceFs) Write added in v0.2.0

func (w *WritableSourceFs) Write(name string, bytes []byte) error

Jump to

Keyboard shortcuts

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