Documentation ¶
Overview ¶
Package dyd provides runtime support for web servers created by the dyd command.
Index ¶
- type App
- type Context
- type KV
- func (s *KV) BatchSet(ctx context.Context, pairs []KVPair) (err error)
- func (s *KV) Delete(ctx context.Context, key string) (err error)
- func (s *KV) DeleteLike(ctx context.Context, pattern string) (err error)
- func (s *KV) Get(ctx context.Context, key string, dest any) (err error)
- func (s *KV) GetLike(ctx context.Context, pattern string) (pairs []KVPair, err error)
- func (s *KV) GetTime(ctx context.Context, key string, dest any) (err error)
- func (s *KV) Set(ctx context.Context, key string, value any) (err error)
- type KVPair
- type URLInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App interface { Bind(url string, handler func(ctx *Context, write func(s string, args ...any) error)) AddMeta(url string, attr []html.Attribute) error ListenAndServe(addr string) error }
App represents a dyd web app.
type Context ¶
type Context struct { ReqSequence int64 Request *http.Request ResponseWriter http.ResponseWriter URLInfo *URLInfo // contains filtered or unexported fields }
Context provides access to the state of the server/session/request/database etc. Every web request creates a new Context instance which is automatically destroyed when the outermost serving function returns.
Context is not safe for concurrent use by multiple goroutines.
func (*Context) DBConn ¶ added in v0.0.11
DBConn returns a new *sql.Conn or an error, if any. All connections are automatically closed when the serving function returns.
func (*Context) Include ¶ added in v0.0.13
Include will call the serving function bound to url, if any. For example
ctx.Include("/path/to/file.html")
func (*Context) KV ¶ added in v0.1.4
KV returns the key value store associated with the server instance or an error, if any.
func (*Context) W3CSS ¶ added in v0.0.14
W3CSS returns the content of
https://www.w3schools.com/w3css/4/w3.css
without using an internet connection. The latest version at the above URL is, as of 2023-05-23
/* W3.CSS 4.15 December 2020 by Jan Egil and Borge Refsnes */
It can be used like
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style><? write("%s", ctx.W3CSS()) ?></style> </head> <body> </body> </html>
type KV ¶ added in v0.1.4
type KV struct {
// contains filtered or unexported fields
}
KV models a simple key/value store backed by a SQLite table with this schema
create table <table name> (key text primary key on conflict replace, value);
Note the 'value' column has no type a thus no affinity. Quoting https://www.sqlite.org/datatype3.html#datetime:
SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values: ...
This means KV.Get(key, &dest) where dest is *time.Time or *sql.NullTime will _not_ work. The proper destinations of Get reflect the SQLite only data types listed at https://www.sqlite.org/datatype3.html#affinity:
- TEXT
- NUMERIC
- INTEGER
- REAL
- BLOB
To read time-representing values, use the GetTime method.
func (*KV) BatchSet ¶ added in v0.1.4
BatchSet sets the values associated with keys. The method is safe for concurrent use by multiple goroutines, all operations are serialized. Meaning all other operations on 's' are blocked until BatchSet completes.
BatchSet atomically sets all pairs or none of them.
func (*KV) Delete ¶ added in v0.1.4
Delete removes the value associated with key. The method is safe for concurrent use by multiple goroutines, all operations are serialized. Meaning all other operations on 's' are blocked until Delete completes.
func (*KV) DeleteLike ¶ added in v0.1.4
DeleteLike removes all value associated with keys matching 'pattern' using the SQLite operator LIKE (https://www.sqlite.org/lang_expr.html#like). The method is safe for concurrent use by multiple goroutines, all operations are serialized. Meaning all other operations on 's' are blocked until Delete completes.
func (*KV) Get ¶ added in v0.1.4
Get retrieves the value associated with key, if any. The method is safe for concurrent use by multiple goroutines, all operations are fully isolated/serialized. Meaning all other operations on 's' are blocked until Get completes.
To detect null values, pass an instance of one of the sql.Null* types or any other type implementing the sql.Scan interface{}. More info about acceptable 'dest' types available at https://pkg.go.dev/database/sql#Rows.Scan.
func (*KV) GetLike ¶ added in v0.1.4
GetLike retrieves all values associated with keys matching 'pattern' using the SQLite operator LIKE (https://www.sqlite.org/lang_expr.html#like). The method is safe for concurrent use by multiple goroutines, all operations are fully isolated/serialized. Meaning all other operation on 's' are blocked until GetLike completes.
When GetLike returns an error, it still returns also any pairs already produced.
Returning no pairs is not an error.
func (*KV) GetTime ¶ added in v0.1.4
GetTime is the is the same as Get, but expects the produced value to be NULL or to be a string representation of a datetime value. The 'dest' should have type *any, *time.Time or *sql.NullTime.