util

package module
v0.0.0-...-a234793 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2024 License: GPL-3.0 Imports: 50 Imported by: 1

README

util

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StringType = &Type{
	IsScalar: true,
	Kind:     "string",
}

Functions

func Accept

func Accept(r *http.Request, format string) bool

func AddToKnownHosts

func AddToKnownHosts(user, server string) error

func AppendUsingReflect

func AppendUsingReflect(slice any, value any) any

func AuthenticateTailscale

func AuthenticateTailscale(authkey string) error

func BackupDir

func BackupDir(path string, encKey string, outfile string) error

func Bit

func Bit(b byte, i int) bool

Bit returns the bit value of the bit at index i of b. It panics if i is out of range (1-8).

func DecryptAndDecompressDir

func DecryptAndDecompressDir(src io.Reader, dst string, key string) error

func DeleteCookie

func DeleteCookie(w http.ResponseWriter, name string)

func Download

func Download(url, target string) error

func EncryptAndCompressDir

func EncryptAndCompressDir(src string, buf io.Writer, key string) error

func EncryptedReader

func EncryptedReader(key string, r io.Reader) (*cipher.StreamReader, error)

EncryptedReader wraps r with an OFB cipher stream.

func EncryptedWriter

func EncryptedWriter(key string, w io.Writer) (*cipher.StreamWriter, error)

EncryptedWriter wraps w with an OFB cipher stream.

func EnvVar

func EnvVar(name string, def string) string

func Exists

func Exists(path string) bool

func FReadJSONFile

func FReadJSONFile(fsys fs.FS, path string, v any) error

func FieldValue

func FieldValue(v any, f string) any

func FilterTestFiles

func FilterTestFiles(fi fs.FileInfo) bool

func Flatten

func Flatten(v any) map[string]string

Flatten any Go object into a map[string]string. Paths are '/'-separated.

func FprintJSON

func FprintJSON(w io.Writer, v any) (int, error)

func GetAddr

func GetAddr() string

func GetName

func GetName(v any) string

func GetOSID

func GetOSID() (string, error)

func HandleCORS

func HandleCORS(w http.ResponseWriter, r *http.Request)

func HandlePUT

func HandlePUT(w http.ResponseWriter, r *http.Request, v any)

func HasMethod

func HasMethod(v any, m string) bool

func HomeDir

func HomeDir() string

func InstallGo

func InstallGo() error

func InstallNode

func InstallNode() error

func InstallTailscale

func InstallTailscale() error

func IntToID

func IntToID(v int64) string

func IsAlphaNumeric

func IsAlphaNumeric(ch rune) bool

func IsArray

func IsArray(v any) bool

func IsBool

func IsBool(v any) bool

func IsDir

func IsDir(path string) bool

func IsInt

func IsInt(v any) bool

func IsMap

func IsMap(v any) bool

func IsMutation

func IsMutation(r *http.Request) bool

func IsRootRequest

func IsRootRequest(r *http.Request) bool

func IsString

func IsString(v any) bool

func IsStruct

func IsStruct(v any) bool

func IsTenDigits

func IsTenDigits(phone string) bool

func JSONString

func JSONString(v any) string

func JoinPath

func JoinPath(path []string) string

func KebabCase

func KebabCase(s string) string

func Main

func Main(s http.Handler)

func NewRecursiveWatcher

func NewRecursiveWatcher(dir string) (*fsnotify.Watcher, error)

func NormalizeGoName

func NormalizeGoName(s string) string

func OS

func OS() string

func OnlyLowerCase

func OnlyLowerCase(s string) string

func OnlyOne

func OnlyOne[T any](m map[string]T) (id string, value T, ok bool)

func PackageManager

func PackageManager() string

func ParsePath

func ParsePath(s string) []string

func PascalCase

func PascalCase(s string) string

func Pop

func Pop[T any](items []T) (T, []T)

func PopPath

func PopPath(path string) (first string, rest string, isRoot bool)

func PrintJSON

func PrintJSON(v any) (int, error)

func RandomBits

func RandomBits(n int) []bool

func RandomBytes

func RandomBytes(n int) []byte

func RandomCode

func RandomCode(digits int) string

func RandomDigit

func RandomDigit() int

func RandomID

func RandomID() string

RandomID returns a 32-byte hex encoded string. The first 8 bytes are a nano-second precision UNIX time-stamp. The next 24 bytes are generated by /dev/urandom.

func RandomToken

func RandomToken(bytes int) string

func ReadGoPackageFromDisk

func ReadGoPackageFromDisk(dir string) (*ast.Package, error)

func ReadJSON

func ReadJSON[T any](r io.Reader) *T

func ReadJSONFile

func ReadJSONFile[T any](path string) T

func ReloadSystemd

func ReloadSystemd() error

func RequireEnvVar

func RequireEnvVar(name string) string

func RestoreDir

func RestoreDir(backupFile string, encKey string, outDir string) error

func Run

func Run(cmd *exec.Cmd) error

func RunSSHCommandWithKnownHostsCheck

func RunSSHCommandWithKnownHostsCheck(host, user, cmd string, auth []ssh.AuthMethod) error

func SHA256

func SHA256(b []byte) []byte

func SSHClientConfig

func SSHClientConfig(user string) (*ssh.ClientConfig, error)

func Serialize

func Serialize(v any) []byte

func Serve

func Serve(s http.Handler) error

func ServeAll

func ServeAll(handlers map[string]http.Handler) error

func ServeBool

func ServeBool(path []string, v any, w http.ResponseWriter, r *http.Request)

func ServeError

func ServeError(w http.ResponseWriter, code int)

func ServeHTTPS

func ServeHTTPS(s http.Handler, email, certDir string) error

Use Let's Encrypt to fetch and renew certificates on any domain. serveHTTPS binds to ports 80 and 443 and serves the given handler. It uses a special handler for port 80 that can handle ACME challenges.

func ServeMethod

func ServeMethod(m string, v any, w http.ResponseWriter, r *http.Request)

func ServeObject

func ServeObject(path []string, v Object, w http.ResponseWriter, r *http.Request)

func SetField

func SetField(v any, fieldName string, fieldValue any)

func SnakeCase

func SnakeCase(s string) string

func StripNonAlphaNumeric

func StripNonAlphaNumeric(s string) string

func StructToMap

func StructToMap(val any) map[string]any

func Sync

func Sync(src, dst string) error

func TitleCase

func TitleCase(s string) string

func UnixNanoTimestamp

func UnixNanoTimestamp() string

func UnixTimestamp

func UnixTimestamp() string

func Watch

func Watch(path string, fn func()) error

func WriteFile

func WriteFile(path string, b []byte) error

func WriteJSON

func WriteJSON(w http.ResponseWriter, v any)

func WriteJSONFile

func WriteJSONFile(path string, v any) error

func WriteMethodNotAllowed

func WriteMethodNotAllowed(w http.ResponseWriter)

func WriteNotFound

func WriteNotFound(w http.ResponseWriter)

Types

type Account

type Account struct {
	Phone string
}

type Action

type Action struct {
	Name string
	URL  string
}

func (*Action) HTML

func (a *Action) HTML() *html.Node

type App

type App struct {
	Dir string
}

func (*App) Config

func (a *App) Config() *AppConfig

func (*App) Handler

func (a *App) Handler(r *http.Request) http.Handler

func (*App) Kind

func (a *App) Kind() string

func (*App) ServeHTTP

func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request)

type AppConfig

type AppConfig struct {
	Kind string
}

type AppServer

type AppServer struct {
	RootDir string
}

type Array

type Array struct {
	Path  []string
	Value any
}

func (*Array) Dig

func (a *Array) Dig(s string) (Object, bool)

func (*Array) ID

func (a *Array) ID() string

func (*Array) JSON

func (a *Array) JSON() string

func (*Array) Ptr

func (a *Array) Ptr() any

func (*Array) Type

func (a *Array) Type() string

type AuthMethod

type AuthMethod interface {
	SendLoginCode(phone string) error
	Login(code string) (string, error)
	Logout(token string) error
	WhoAmI(token string) (string, error)
}

type AuthSystem

type AuthSystem struct {
	// Config
	TwilioClient    *TwilioClient
	LoginCodeMsgFmt string

	// Data
	Users         *Table[*User]
	LoginCodes    map[string]string // user ID => 6 digit code
	SessionTokens map[string]string // token => user ID
}

func NewAuthSystem

func NewAuthSystem() *AuthSystem

func (*AuthSystem) CheckLoginCode

func (a *AuthSystem) CheckLoginCode(userID, code string) bool

CheckLoginCode returns true if the login code is valid.

func (*AuthSystem) CreateLoginCode

func (a *AuthSystem) CreateLoginCode(userID string) string

Creates a new login code. Only one login code per user can be active at a time.

func (*AuthSystem) Login

func (a *AuthSystem) Login(userID, code string) (token string, err error)

Login creates a user session. It returns a token or error.

func (*AuthSystem) Logout

func (a *AuthSystem) Logout(token string)

func (*AuthSystem) Register

func (a *AuthSystem) Register(user *User) (string, error)

func (*AuthSystem) SendLoginCode

func (a *AuthSystem) SendLoginCode(phone string) (userID string, err error)

SendLoginCode sends a login code the users phone number on file via Twilio SMS.

func (*AuthSystem) WhoAmI

func (a *AuthSystem) WhoAmI(token string) string

type BlogPost

type BlogPost struct {
	Metadata *WebpageMetadata
	BodyHTML string
}

type Bool

type Bool struct {
	Path  []string
	Value bool
}

func (*Bool) Dig

func (b *Bool) Dig(s string) (Object, bool)

func (*Bool) ID

func (b *Bool) ID() string

func (*Bool) JSON

func (b *Bool) JSON() string

func (*Bool) Ptr

func (b *Bool) Ptr() any

func (*Bool) Type

func (b *Bool) Type() string

type BuildConfig

type BuildConfig struct {
	Type      string
	Path      string
	Out       string
	OnSuccess string
}

func (*BuildConfig) Build

func (config *BuildConfig) Build() error

type BuildServer

type BuildServer struct {
	Workdir string
	Config  map[string]*BuildConfig
}

func (*BuildServer) ServeHTTP

func (s *BuildServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

type CI

type CI struct {
	PeriodMinutes int
	SourceDir     string
	OutFile       string
	ServiceName   string
	TwilioClient  *TwilioClient
	AdminPhone    string
}

func (*CI) Codebase

func (ci *CI) Codebase() *GoCodebase

func (*CI) GitRepo

func (ci *CI) GitRepo() *GitRepo

func (*CI) Run

func (ci *CI) Run() (bool, error)

func (*CI) Serivce

func (ci *CI) Serivce() *SystemdService

func (*CI) Start

func (ci *CI) Start()

type Cafe

type Cafe[T http.Handler] struct {
	ID   string
	Data map[string]T
}

type Collection

type Collection struct {
	Schema *Schema
	Items  []string
}

func (*Collection) List

func (c *Collection) List(limit, after int)

List returns a list of the first `limit` items after

type Condition

type Condition struct {
	LHS *Expression
	Op  string
	RHS *Expression
}

type DB

type DB struct {
	FS     FileSystem
	Schema struct {
		Tables map[string]struct {
			Columns map[string]string
		}
	}
}

func (*DB) AddColumn

func (db *DB) AddColumn(table, column, typ string) error

func (*DB) CreateTable

func (db *DB) CreateTable(name string) error

func (*DB) Delete

func (db *DB) Delete(name string) error

func (*DB) Insert

func (db *DB) Insert(name string) error

func (*DB) SelectMany

func (db *DB) SelectMany(name string) error

func (*DB) SelectOne

func (db *DB) SelectOne(name string) error

func (*DB) Update

func (db *DB) Update(name string) error

type DevServer

type DevServer struct {
	PkgPath string
	// contains filtered or unexported fields
}

func (*DevServer) Start

func (s *DevServer) Start()

type Email

type Email string

func (Email) Validate

func (email Email) Validate() error

type Error

type Error struct {
	Message string
	Actions []Action
}

func (*Error) HTML

func (e *Error) HTML() *html.Node

type Expression

type Expression struct {
	IsLiteral bool
	Value     string

	IsCall bool
	Fn     *Ref
	Args   []*Expression

	IsRef bool
	Ref   *Ref
}

type FancyRoute

type FancyRoute struct {
	Root   http.Handler
	Static map[string]http.Handler

	Catchall *FancyRoute
	VarName  string
}

func (*FancyRoute) ServeHTTP

func (route *FancyRoute) ServeHTTP(w http.ResponseWriter, r *http.Request)

type FancyRouter

type FancyRouter struct {
	// Routes. Each key should start with '/'.
	// To handle the root request, use the key "/".
	// To define a path variable, use square brackets like "/items/[itemID]".
	Routes   map[string]http.Handler
	NotFound http.Handler
}

FancyRouter handles HTTP requests by matching each request to a handler according to Next.js routing conventions.

func (*FancyRouter) SortedRoutes

func (r *FancyRouter) SortedRoutes() []string

type Field

type Field struct {
	Name string
	Type *Type
}

type File

type File struct {
	Type   string
	Size   int
	SHA256 string
}

type FileObject

type FileObject[T Object] struct {
	Path string
}

func (*FileObject[T]) ServeHTTP

func (fo *FileObject[T]) ServeHTTP(w http.ResponseWriter, r *http.Request)

type FileStore

type FileStore struct {
	Workdir string
}

FileStore stores and serves files. To use, set up a directory with an `auth.json` file and a `content` directory.

func (*FileStore) HasAccess

func (fs *FileStore) HasAccess(userID, path string) bool

func (*FileStore) ReadFile

func (fs *FileStore) ReadFile(path string) ([]byte, error)

type FileSystem

type FileSystem interface {
	ReadFile(path string) ([]byte, error)
	ReadDir(path string) ([]string, error)
	IsDir(path string) bool
	IsFile(path string) bool
	WriteFile(path string, b []byte) error
	MakeDir(path string) error
	Remove(path string) error
	Dig(path string) FileSystem
}

type Form

type Form struct {
	Name      string
	Fields    []Field
	ServePOST func(w http.ResponseWriter, r *http.Request)
}

func (*Form) HTML

func (f *Form) HTML(prefilled map[string]string) *html.Node

func (*Form) ServeHTTP

func (f *Form) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Function

type Function struct {
	Inputs  []Field
	Outputs []Field
	Body    []Statement
}

type GitRepo

type GitRepo struct {
	Dir string
}

func (*GitRepo) AddAll

func (r *GitRepo) AddAll() error

func (*GitRepo) Commit

func (r *GitRepo) Commit(msg string) error

func (*GitRepo) Pull

func (r *GitRepo) Pull() (bool, error)

Pull from the default upstream. Returns true if there were updates, if git prints "Already up to date.", false is returned. Other errors are returned.

func (*GitRepo) Push

func (r *GitRepo) Push() error

type GithubMirror

type GithubMirror struct {
	Workdir string
}

func (*GithubMirror) Pull

func (g *GithubMirror) Pull(repo string) error

func (*GithubMirror) ServeHTTP

func (g *GithubMirror) ServeHTTP(w http.ResponseWriter, r *http.Request)

Handle webhooks from github

type GithubRepository

type GithubRepository struct {
	ID       int    `json:"id"`
	NodeID   string `json:"node_id"`
	FullName string `json:"full_name"`
}

func (*GithubRepository) SyncLocal

func (repo *GithubRepository) SyncLocal(path string) error

type GithubWebhook

type GithubWebhook struct {
	Type string
	ID   int
}

type GithubWebhookRequest

type GithubWebhookRequest struct {
	Zen        string            `json:"zen"`
	HookID     int               `json:"hook_id"`
	Hook       *GithubWebhook    `json:"hook"`
	Repository *GithubRepository `json:"repository"`
}

type GoCodebase

type GoCodebase struct {
	Dir string
}

func (GoCodebase) Build

func (c GoCodebase) Build(outFile string) error

func (*GoCodebase) GitRepo

func (c *GoCodebase) GitRepo() *GitRepo

func (*GoCodebase) UpdateDeps

func (c *GoCodebase) UpdateDeps() (bool, error)

type GoPackage

type GoPackage struct {
	Types map[string]Type
}

func (*GoPackage) Write

func (p *GoPackage) Write(dir string) error

type GoWorkspace

type GoWorkspace struct {
	Dir string
}

func (*GoWorkspace) Build

func (w *GoWorkspace) Build(pkg string, o string) error

func (*GoWorkspace) Clone

func (w *GoWorkspace) Clone(pkg string) error

func (*GoWorkspace) Install

func (w *GoWorkspace) Install(pkg string) error

func (*GoWorkspace) Pull

func (w *GoWorkspace) Pull(pkg string) error

func (*GoWorkspace) ServeGithubWebhook

func (ws *GoWorkspace) ServeGithubWebhook(w http.ResponseWriter, r *http.Request)

type HCloudStorageFileSystem

type HCloudStorageFileSystem struct {
	HetznerStorageBoxAddr     string
	HetznerStorageBoxUsername string
	HetznerStorageBoxPassword string
}

func (*HCloudStorageFileSystem) NewSFTPClient

func (fs *HCloudStorageFileSystem) NewSFTPClient() (*sftp.Client, error)

func (*HCloudStorageFileSystem) NewSSHClient

func (fs *HCloudStorageFileSystem) NewSSHClient() (*ssh.Client, error)

type HTMLDocument

type HTMLDocument struct {
	Head *HTMLHead
	Body *html.Node
}

func (*HTMLDocument) Write

func (d *HTMLDocument) Write(w io.Writer) error

type HTMLHead

type HTMLHead struct {
	Title  string
	Desc   string
	Author string
	CSS    string
}

func (*HTMLHead) ServeHTTP

func (h *HTMLHead) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*HTMLHead) Write

func (h *HTMLHead) Write(w io.Writer) (int64, error)

func (*HTMLHead) XML

func (h *HTMLHead) XML() *XML

type HTMLTemplateData

type HTMLTemplateData struct {
	Title    string
	Desc     string
	Author   string
	Keywords string
}

type Index

type Index map[string]Set[string]

func (Index) Add

func (i Index) Add(k, v string)

func (Index) Get

func (i Index) Get(key string) Set[string]

func (Index) Remove

func (i Index) Remove(k, v string)

type Int

type Int struct {
	Path  []string
	Value int64
}

func (*Int) Dig

func (i *Int) Dig(s string) (Object, bool)

func (*Int) ID

func (i *Int) ID() string

func (*Int) JSON

func (i *Int) JSON() string

func (*Int) Ptr

func (i *Int) Ptr() any

func (*Int) Type

func (i *Int) Type() string

type JSONFile

type JSONFile[T http.Handler] struct {
	Path string
}

func (*JSONFile[T]) ServeHTTP

func (f *JSONFile[T]) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Link struct {
	Name string
	Href string
}

func (*Link) ServeHTTP

func (l *Link) ServeHTTP(w http.ResponseWriter, r *http.Request)

type LinkTree

type LinkTree struct {
	Head  *HTMLHead
	Links []Link
}

func (*LinkTree) ServeHTTP

func (tree *LinkTree) ServeHTTP(w http.ResponseWriter, r *http.Request)

type List

type List struct {
	Size  int
	Items []ListItem
}

func (*List) ServeHTTP

func (l *List) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ListItem

type ListItem struct {
	URL  string
	Name string
}

type LocalFileSystem

type LocalFileSystem struct {
	Root string
}

func (*LocalFileSystem) Dig

func (fs *LocalFileSystem) Dig(path string) FileSystem

func (*LocalFileSystem) IsDir

func (fs *LocalFileSystem) IsDir(path string) bool

func (*LocalFileSystem) IsFile

func (fs *LocalFileSystem) IsFile(path string) bool

func (*LocalFileSystem) MakeDir

func (fs *LocalFileSystem) MakeDir(path string) error

func (*LocalFileSystem) ReadDir

func (fs *LocalFileSystem) ReadDir(path string) ([]string, error)

func (*LocalFileSystem) ReadFile

func (fs *LocalFileSystem) ReadFile(path string) ([]byte, error)

func (*LocalFileSystem) Remove

func (fs *LocalFileSystem) Remove(path string) error

func (*LocalFileSystem) WriteFile

func (fs *LocalFileSystem) WriteFile(path string, b []byte) error

type Map

type Map struct {
	Path  []string
	Value map[string]any
}

func (*Map) Dig

func (m *Map) Dig(s string) (Object, bool)

func (*Map) ID

func (m *Map) ID() string

func (*Map) JSON

func (m *Map) JSON() string

func (*Map) Ptr

func (m *Map) Ptr() any

func (*Map) Type

func (m *Map) Type() string

type MapList

type MapList[T http.Handler] struct {
	ID   string
	Data map[string]T
}

func (*MapList[T]) ServeHTTP

func (m *MapList[T]) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Metadata

type Metadata struct {
	Type  string
	Types map[string]Type
}

type Movie

type Movie struct {
	Year    int
	Title   string
	PTPID   string
	FileSHA string
}

type MultiHostServer

type MultiHostServer struct {
	Hosts        map[string]http.Handler
	TwilioClient *TwilioClient
	AdminPhone   string
}

func (*MultiHostServer) HostPolicy

func (s *MultiHostServer) HostPolicy(ctx context.Context, host string) error

func (*MultiHostServer) ServeHTTP

func (s *MultiHostServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*MultiHostServer) Start

func (s *MultiHostServer) Start(email, certDir string) error

type MultiUserApp

type MultiUserApp struct {
	Twilio    *TwilioClient
	AuthFiles FileSystem
	App       http.Handler
}

func (*MultiUserApp) AuthHandler

func (a *MultiUserApp) AuthHandler() *MultiUserAuthHandler

func (*MultiUserApp) Authorized

func (a *MultiUserApp) Authorized(r *http.Request) (bool, string, error)

func (*MultiUserApp) GetOrg

func (a *MultiUserApp) GetOrg(id string) (*Org, error)

func (*MultiUserApp) GetSession

func (a *MultiUserApp) GetSession(token string) (*Session, error)

func (*MultiUserApp) ServeHTTP

func (a *MultiUserApp) ServeHTTP(w http.ResponseWriter, r *http.Request)

type MultiUserAuthHandler

type MultiUserAuthHandler struct {
	AuthFiles FileSystem
	Twilio    *TwilioClient
}

func (*MultiUserAuthHandler) Login

func (a *MultiUserAuthHandler) Login(phone, code string) (*Session, error)

func (*MultiUserAuthHandler) SendLoginCode

func (a *MultiUserAuthHandler) SendLoginCode(phone string) error

func (*MultiUserAuthHandler) ServeHTTP

func (a *MultiUserAuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Nil

type Nil struct {
	Path []string
}

func (*Nil) Dig

func (n *Nil) Dig(p string) (Object, bool)

func (*Nil) ID

func (n *Nil) ID() string

func (*Nil) JSON

func (n *Nil) JSON() string

func (*Nil) Ptr

func (n *Nil) Ptr() any

func (*Nil) Type

func (n *Nil) Type() string

type Object

type Object interface {
	ID() string
	JSON() string
	Type() string
	Ptr() any
	Dig(s string) (Object, bool)
}

func NewObject

func NewObject(path []string, v any) Object

type Org

type Org struct {
	Members []string
}

func (*Org) HasMember

func (o *Org) HasMember(id string) bool

type Pair

type Pair[K, V any] struct {
	K K
	V V
}

type Person

type Person struct {
	FirstName string
	LastName  string
}

func (*Person) FullName

func (p *Person) FullName() string

type Personal

type Personal struct {
	Blog []BlogPost
}

type PhoneNumber

type PhoneNumber string

func (PhoneNumber) Validate

func (phone PhoneNumber) Validate() error

type PingServer

type PingServer struct {
	Msg string
}

func (*PingServer) ServeHTTP

func (s *PingServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ProgrammingLanguage

type ProgrammingLanguage struct {
	ImportSyntax   string
	TypeSyntax     string
	FunctionSyntax string
	ExportSyntax   string
}

type ReactComponent

type ReactComponent struct {
	Name  string
	Props []*Field
	State []*Field
	Body  []*Statement
}

type ReactElement

type ReactElement struct {
	Type  string
	Props []struct {
		Key   string
		Value any
	}
	Children []ReactElement
}

func (*ReactElement) WriteNextJSPage

func (el *ReactElement) WriteNextJSPage(w io.Writer) error

type Ref

type Ref struct {
	From string
	Name string
}

type RemoteFileSystem

type RemoteFileSystem struct {
	Root string
}

func (*RemoteFileSystem) IsDir

func (fs *RemoteFileSystem) IsDir(path string) bool

func (*RemoteFileSystem) IsFile

func (fs *RemoteFileSystem) IsFile(path string) bool

func (*RemoteFileSystem) MakeDir

func (fs *RemoteFileSystem) MakeDir(path string) error

func (*RemoteFileSystem) ReadDir

func (fs *RemoteFileSystem) ReadDir(path string) ([]string, error)

func (*RemoteFileSystem) ReadFile

func (fs *RemoteFileSystem) ReadFile(path string) ([]byte, error)

func (*RemoteFileSystem) Remove

func (fs *RemoteFileSystem) Remove(path string) error

func (*RemoteFileSystem) WriteFile

func (fs *RemoteFileSystem) WriteFile(path string, b []byte) error

type Request

type Request struct {
	Method string
	URL    string
	Header http.Header
	Body   string
}

func NewRequest

func NewRequest(r *http.Request) *Request

func (*Request) Log

func (r *Request) Log()

type Router

type Router struct {
	Root func(w http.ResponseWriter, r *http.Request)
	Next func(first string, w http.ResponseWriter, r *http.Request)
}

func (*Router) ServeHTTP

func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)

type SHA256Server

type SHA256Server struct {
	FileDir string
	User    string
	Pass    string
}

func (*SHA256Server) ServeHTTP

func (s *SHA256Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Schema

type Schema struct {
	Fields []Field
}

func (*Schema) Type

func (s *Schema) Type() *Type

func (*Schema) WriteGoTypeFile

func (s *Schema) WriteGoTypeFile(w io.Writer, pkg, name string) (int, error)

type SchemaCafe

type SchemaCafe struct {
	Schemas map[string]*Schema
}

func (*SchemaCafe) ServeHTTP

func (sc *SchemaCafe) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Sender

type Sender interface {
	Send(to string, msg string) error
}

type Server

type Server struct {
	DataFile          string
	ErrorsDir         string
	TwilioClient      *TwilioClient
	AdminPhone        string
	AdminEmail        string
	CertDir           string
	Users             *Table[*User]
	LoginCodes        map[string]string // user ID => 6 digit code
	SessionTokens     map[string]string // token => user ID
	LoginCodeMsgFmt   string
	GithubSourceDir   string
	AllowRegistration bool
}

Server hosts multiple apps. App data is read from "{datadir}/{host}/data.json". Config is "{datadir}/{host}/config.json" defined by AppConfig.

func (*Server) CheckLoginCode

func (a *Server) CheckLoginCode(userID, code string) bool

CheckLoginCode returns true if the login code is valid.

func (*Server) CreateLoginCode

func (a *Server) CreateLoginCode(userID string) string

Creates a new login code. Only one login code per user can be active at a time.

func (*Server) GithubMirror

func (s *Server) GithubMirror() *GithubMirror

func (*Server) HostPolicy

func (s *Server) HostPolicy(ctx context.Context, host string) error

func (*Server) Load

func (s *Server) Load()

func (*Server) LogError

func (s *Server) LogError(e any)

func (*Server) LoginForm

func (a *Server) LoginForm() *Form

func (*Server) Logout

func (a *Server) Logout(token string)

func (*Server) LogoutForm

func (a *Server) LogoutForm() *Form

func (*Server) NotifyAdmin

func (s *Server) NotifyAdmin(msg string)

func (*Server) RegisterForm

func (s *Server) RegisterForm() *Form

func (*Server) SendLoginCodeForm

func (a *Server) SendLoginCodeForm() *Form

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) Start

func (s *Server) Start() error

func (*Server) SystemdService

func (s *Server) SystemdService() *SystemdService

func (*Server) User

func (s *Server) User(r *http.Request) *User

func (*Server) WhoAmI

func (a *Server) WhoAmI(token string) string

type Session

type Session struct {
	UserID string
	Token  string
}

func (*Session) String

func (s *Session) String() string

type Set

type Set[T comparable] map[T]bool

func (Set[T]) Add

func (s Set[T]) Add(v T)

func (Set[T]) Intersection

func (s Set[T]) Intersection(other Set[T]) Set[T]

func (Set[T]) List

func (s Set[T]) List() []T

func (Set[T]) Remove

func (s Set[T]) Remove(v T)

func (Set[T]) Union

func (s Set[T]) Union(other Set[T]) Set[T]

type SheetsDB

type SheetsDB struct {
}

type SingleFileServer

type SingleFileServer[T http.Handler] struct {
	Path string
	V    T
	// contains filtered or unexported fields
}

func NewSingleFileServer

func NewSingleFileServer[T http.Handler](path string) *SingleFileServer[T]

func (*SingleFileServer[T]) ServeHTTP

func (s *SingleFileServer[T]) ServeHTTP(w http.ResponseWriter, r *http.Request)

type SinglePageApp

type SinglePageApp struct {
	// contains filtered or unexported fields
}

func (*SinglePageApp) ServeHTTP

func (spa *SinglePageApp) ServeHTTP(w http.ResponseWriter, r *http.Request)

type SingleUserApp

type SingleUserApp struct {
	Twilio    *TwilioClient
	UserPhone string
	Files     FileSystem
	Handler   http.Handler
}

func (*SingleUserApp) AuthFiles

func (a *SingleUserApp) AuthFiles() FileSystem

func (*SingleUserApp) AuthHandler

func (a *SingleUserApp) AuthHandler() *SingleUserAuthHandler

func (*SingleUserApp) Authorized

func (a *SingleUserApp) Authorized(r *http.Request) (bool, error)

func (*SingleUserApp) GetSession

func (a *SingleUserApp) GetSession(token string) (*Session, error)

func (*SingleUserApp) ServeHTTP

func (app *SingleUserApp) ServeHTTP(w http.ResponseWriter, r *http.Request)

type SingleUserAuthHandler

type SingleUserAuthHandler struct {
	UserPhone string
	AuthFiles FileSystem
	Twilio    *TwilioClient
}

func (*SingleUserAuthHandler) Login

func (a *SingleUserAuthHandler) Login(phone, code string) (*Session, error)

func (*SingleUserAuthHandler) SendLoginCode

func (a *SingleUserAuthHandler) SendLoginCode(phone string) error

func (*SingleUserAuthHandler) ServeHTTP

type Statement

type Statement struct {
	IsReturn bool
	Return   *Expression

	IsAssign bool
	Name     string
	Value    *Expression

	IsIf      bool
	Condition *Condition
	Body      []*Statement
}

Statement represents a line of code in a function or method body. There are 4 types of statements: returns, assignments, ifs and loops. Ifs and loops have substatements.

type String

type String struct {
	Path  []string
	Value string
}

func (*String) Dig

func (s *String) Dig(p string) (Object, bool)

func (*String) ID

func (s *String) ID() string

func (*String) JSON

func (s *String) JSON() string

func (*String) Ptr

func (s *String) Ptr() any

func (*String) Type

func (s *String) Type() string

type Struct

type Struct struct {
	Path  []string
	Value map[string]any
}

func (*Struct) Dig

func (s *Struct) Dig(p string) (Object, bool)

func (*Struct) ID

func (s *Struct) ID() string

func (*Struct) JSON

func (s *Struct) JSON() string

func (*Struct) Ptr

func (s *Struct) Ptr() any

func (*Struct) Type

func (s *Struct) Type() string

type SystemdService

type SystemdService struct {
	Name        string
	Desc        string
	After       string
	Type        string
	Env         []Pair[string, string]
	ExecStart   string
	AutoRestart string
	WantedBy    string
}

func (*SystemdService) Restart

func (s *SystemdService) Restart() error

func (*SystemdService) WriteConfig

func (s *SystemdService) WriteConfig(w io.Writer) error

func (*SystemdService) WriteConfigToFile

func (s *SystemdService) WriteConfigToFile() error

type TVEpisode

type TVEpisode struct {
	SeasonID  string
	EpisodeID string
}

type TVSeason

type TVSeason struct {
	ID string
}

type TVShow

type TVShow struct {
	Year  int
	Title string
	BTNID string
}

type Table

type Table[T any] struct {
	Path        string
	Rows        map[string]T
	Indexes     map[string]Index
	Constraints []TableConstraint
	RowLimit    int
}

func NewTable

func NewTable[T any]() *Table[T]

func (*Table[T]) AddIndex

func (t *Table[T]) AddIndex(fieldID string) error

func (*Table[T]) AddUniqConstraint

func (t *Table[T]) AddUniqConstraint(col string) error

func (*Table[T]) Delete

func (t *Table[T]) Delete(id string)

func (*Table[T]) Find

func (t *Table[T]) Find(id string) (T, bool)

func (*Table[T]) FindBy

func (t *Table[T]) FindBy(col string, value any) map[string]T

func (*Table[T]) IDs

func (t *Table[T]) IDs() Set[string]

func (*Table[T]) Insert

func (t *Table[T]) Insert(v T) (string, error)

func (*Table[T]) List

func (t *Table[T]) List(page int) *List

func (*Table[T]) ServeHTTP

func (t *Table[T]) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Table[T]) Update

func (t *Table[T]) Update(id string, v T) error

type TableConstraint

type TableConstraint struct {
	Col  string
	Uniq bool
}

type TwilioClient

type TwilioClient struct {
	AccountSID  string
	AuthToken   string
	PhoneNumber string
}

func (*TwilioClient) SendSMS

func (c *TwilioClient) SendSMS(to, message string) error

type Type

type Type struct {
	IsScalar    bool
	Kind        string
	IsPointer   bool
	IsArray     bool
	IsMap       bool
	ElemType    string
	IsStruct    bool
	Fields      []Field
	Methods     map[string]*Function
	DefaultJSON string
}

func (*Type) GoFile

func (t *Type) GoFile(pkg, typ string) string

func (*Type) GoString

func (t *Type) GoString(indent int) string

func (*Type) WriteGoFile

func (t *Type) WriteGoFile(w io.Writer, pkg, name string) (int, error)

type User

type User struct {
	// Public ID
	ID string

	// Contact
	Phone string
	Email string

	// Personal
	FirstName string
	LastName  string

	// Data
	Schemas *Table[*Schema]
}

func (*User) SchemaCafe

func (u *User) SchemaCafe(w http.ResponseWriter, r *http.Request)

func (*User) ServeHTTP

func (u *User) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Video

type Video struct {
	Height     int
	Width      int
	FPS        int
	Source     string
	VideoCodec string
	AudioCodec string
	Encoder    string
	Container  string
	File       *File
}

type WebAPI

type WebAPI struct {
	Types    map[string]Type
	RootType string
	Data     FileSystem
}

The WebAPI type represents an WebAPI backed by any JSON-serializable Go object.

func (*WebAPI) ServeHTTP

func (api *WebAPI) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves a generic REST API.

func (*WebAPI) ServeNotFound

func (api *WebAPI) ServeNotFound(w http.ResponseWriter, r *http.Request)

func (*WebAPI) ServePOST

func (api *WebAPI) ServePOST(w http.ResponseWriter, r *http.Request)

type WebApp

type WebApp[T any] struct {
	Name             string
	Description      string
	Author           string
	Keywords         []string
	Favicon          []byte
	Icon             []byte
	Types            map[string]Type
	CoreResourceType string
	TwilioClient     *TwilioClient
	Files            FileSystem
}

func (*WebApp[T]) AuthHandler

func (app *WebApp[T]) AuthHandler() *MultiUserAuthHandler

func (*WebApp[T]) DeletePath

func (app *WebApp[T]) DeletePath(w http.ResponseWriter, r *http.Request)

func (*WebApp[T]) GetAuthLogin

func (app *WebApp[T]) GetAuthLogin(w http.ResponseWriter, r *http.Request)

func (*WebApp[T]) GetAuthSendLoginCode

func (app *WebApp[T]) GetAuthSendLoginCode(w http.ResponseWriter, r *http.Request)

func (*WebApp[T]) GetFavicon

func (app *WebApp[T]) GetFavicon(w http.ResponseWriter, r *http.Request)

func (*WebApp[T]) GetMeta

func (app *WebApp[T]) GetMeta(w http.ResponseWriter, r *http.Request)

func (*WebApp[T]) GetOrg

func (app *WebApp[T]) GetOrg(w http.ResponseWriter, r *http.Request)

func (*WebApp[T]) GetPath

func (app *WebApp[T]) GetPath(w http.ResponseWriter, r *http.Request)

func (*WebApp[T]) GetRoot

func (app *WebApp[T]) GetRoot(w http.ResponseWriter, r *http.Request)

func (*WebApp[T]) KeywordString

func (app *WebApp[T]) KeywordString() string

func (*WebApp[T]) Metadata

func (app *WebApp[T]) Metadata() *Metadata

func (*WebApp[T]) OrgTmpl

func (app *WebApp[T]) OrgTmpl() *template.Template

func (*WebApp[T]) PatchPath

func (app *WebApp[T]) PatchPath(w http.ResponseWriter, r *http.Request)

func (*WebApp[T]) PostAuthLogin

func (app *WebApp[T]) PostAuthLogin(w http.ResponseWriter, r *http.Request)

func (*WebApp[T]) PostAuthSendLoginCode

func (app *WebApp[T]) PostAuthSendLoginCode(w http.ResponseWriter, r *http.Request)

func (*WebApp[T]) PostOrg

func (app *WebApp[T]) PostOrg(w http.ResponseWriter, r *http.Request)

func (*WebApp[T]) PostPath

func (app *WebApp[T]) PostPath(w http.ResponseWriter, r *http.Request)

func (*WebApp[T]) PostRoot

func (app *WebApp[T]) PostRoot(w http.ResponseWriter, r *http.Request)

func (*WebApp[T]) PutOrg

func (app *WebApp[T]) PutOrg(w http.ResponseWriter, r *http.Request)

func (*WebApp[T]) PutPath

func (app *WebApp[T]) PutPath(w http.ResponseWriter, r *http.Request)

func (*WebApp[T]) ServeHTTP

func (app *WebApp[T]) ServeHTTP(w http.ResponseWriter, r *http.Request)

type WebFrontend

type WebFrontend struct {
	Favicon      []byte
	RootTitle    string
	MetaDesc     string
	MetaAuthor   string
	MetaKeywords []string
}

func (*WebFrontend) HTMLData

func (fe *WebFrontend) HTMLData() *HTMLTemplateData

func (*WebFrontend) ServeHTTP

func (fe *WebFrontend) ServeHTTP(w http.ResponseWriter, r *http.Request)

type WebpageMetadata

type WebpageMetadata struct {
	Title    string
	Desc     string
	Author   *Person
	Keywords []string
	Favicon  []byte
}

type XML

type XML struct {
	El       string
	Attrs    []Pair[string, string]
	Children []*XML
}

func NewXML

func NewXML(n *html.Node) *XML

func XMLString

func XMLString(s string) *XML

func (*XML) Attr

func (xml *XML) Attr(key string) string

func (*XML) String

func (xml *XML) String() string

func (*XML) Write

func (xml *XML) Write(w io.Writer) (n int64, err error)

Source Files

Directories

Path Synopsis
cmd
dev

Jump to

Keyboard shortcuts

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