util

package
v0.0.0-...-c276c0a Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2025 License: GPL-3.0 Imports: 55 Imported by: 1

README

util

A collection of useful types/functions for Go developers.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IntType = &Type{
	IsScalar: true,
	ElemType: "int",
}
View Source
var StringType = &Type{
	IsScalar:    true,
	ElemType:    "string",
	DefaultJSON: "\"\"",
}
View Source
var TextType = &Type{
	IsScalar:    true,
	ElemType:    "Text",
	DefaultJSON: "\"\"",
}
View Source
var TypeType = &Type{
	IsStruct: true,
	Fields: []Field{
		{
			Name: NewName("Is scalar"),
			Desc: "",
			Type: "bool",
		},
		{
			Name: NewName("Kind"),
			Desc: "",
			Type: "string",
		},
		{
			Name: NewName("Is pointer"),
			Desc: "",
			Type: "bool",
		},
		{
			Name: NewName("Is array"),
			Desc: "",
			Type: "bool",
		},
		{
			Name: NewName("Is map"),
			Desc: "",
			Type: "bool",
		},
		{
			Name: NewName("Elem type"),
			Desc: "",
			Type: "string",
		},
		{
			Name: NewName("Is struct"),
			Desc: "",
			Type: "bool",
		},
		{
			Name: NewName("Fields"),
			Desc: "",
			Type: "[]util.Field",
		},
	},
}

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 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 CallMethod

func CallMethod(v any, m string, args []string) ([]string, error)

CallMethod takes any value, a method name, and an array of JSON-encoded strings. It parses these strings into method arguments and invokes the method, including support for variadic functions. Returns the result of the method call or an error.

func CompressDir

func CompressDir(dir, outFile string) error

CompressDir compresses the specified directory into a .tar.gz file.

func ContentType

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

func CopyDir

func CopyDir(srcDir, dstDir string) error

CopyDir recursively copies a directory from src to dst.

func CopyFile

func CopyFile(src, dst string) error

CopyFile copies a file from src to dst. If dst does not exist, it will be created.

func CopyFileFromRemote

func CopyFileFromRemote(user, addr, src, dst string) ([]byte, error)

func CopyFileToRemote

func CopyFileToRemote(user, addr, src, dst string) ([]byte, error)

func CreateFile

func CreateFile(path string) (*os.File, error)

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 DownloadDir

func DownloadDir(user, host, path string) ([]byte, error)

func Drill

func Drill(v any, path []string) (any, 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 ExecRemote

func ExecRemote(user, host, cmd string) ([]byte, error)

func Exists

func Exists(path string) bool

func ExprString

func ExprString(expr ast.Expr) string

ExprString converts an ast.Expr to its string representation.

func FReadJSONFile

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

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 FrequencyToRGB

func FrequencyToRGB(frequency float64) string

FrequencyToRGB converts a light frequency in THz to an RGB hex 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 Kind

func Kind(v interface{}) string

Kind determines the kind of a given value. It returns one of "struct", "map", "list", "scalar" or "null".

func MIMEType

func MIMEType(file 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 ParseJSON

func ParseJSON[T any](s string) T

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 Port

func Port() string

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(path string, v any) error

func ReloadSystemd

func ReloadSystemd() error

func RenderTemplateToFile

func RenderTemplateToFile(tmpl string, path string, in any) 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) ([]byte, 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)

func ServeAll

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

func ServeAny

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

ServeAny serves any Go value. Drill into any exported struct field or map/arary value. Arrays start at 1001. GET requests are served the JSON encoded values. POST requests are used to call methods. Ex request body: `{"Method":"Add","Args":["1","2","3"]}`. All args are JSON-encoded strings. The server will unmarshal each arg into it's appropriate type. Ex response body: `["6","null"]`.

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 Touch

func Touch(path string) error

func UnixNanoTimestamp

func UnixNanoTimestamp() string

func UnixTimestamp

func UnixTimestamp() string

func UploadDir

func UploadDir(user, host string, b []byte, path string) error

func WaitUntil

func WaitUntil(h, m, s int)

func Watch

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

func WavelengthToRGB

func WavelengthToRGB(wavelength float64) string

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)

func WriteTempFile

func WriteTempFile(b []byte) (string, error)

Types

type AuthMethod

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

type BlogPost

type BlogPost struct {
	Metadata *WebpageMetadata
	BodyHTML string
}

type CmdServer

type CmdServer struct {
	Dir string
}

func (*CmdServer) ServeHTTP

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

type Comment

type Comment struct {
	Timestamp time.Time `json:"timestamp"`
	Author    string    `json:"author"`
	Message   string    `json:"message"`
	Replies   []Comment `json:"replies"`
}

type Condition

type Condition struct {
	LHS *Expression `json:"lhs"`
	Op  string      `json:"op"`
	RHS *Expression `json:"rhs"`
}

type Email

type Email string

func (Email) Validate

func (email Email) Validate() error

type Expression

type Expression struct {
	IsLiteral bool   `json:"isLiteral"`
	Value     string `json:"value"`

	IsCall bool          `json:"isCall"`
	Fn     string        `json:"fn"`
	Args   []*Expression `json:"args"`

	IsRef bool   `json:"isRef"`
	Ref   string `json:"ref"`
}

func (*Expression) GoString

func (e *Expression) GoString() string

func (*Expression) Imports

func (e *Expression) Imports() ImportMap

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 {
	ID       string    `json:"id"`
	Desc     string    `json:"desc"`
	Comments []Comment `json:"comments"`
	Name     Name      `json:"name"`
	Type     string    `json:"type"`
}

type Form

type Form struct {
	Name   Name
	Desc   string
	Fields []Field
	Handle http.HandlerFunc
}

func (*Form) ServeHTTP

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

type Function

type Function struct {
	ID       string      `json:"id"`
	Desc     string      `json:"desc"`
	Comments []Comment   `json:"comments"`
	Name     Name        `json:"name"`
	Inputs   []Field     `json:"inputs"`
	Outputs  []Field     `json:"outputs"`
	Body     []Statement `json:"body"`
}

func (*Function) Imports

func (f *Function) Imports() ImportMap

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
}

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 ImportMap

type ImportMap map[string]string

ImportMap maps symbols to Go import strings

func (ImportMap) Go

func (im ImportMap) Go() string

func (ImportMap) TypeScript

func (im ImportMap) TypeScript() 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 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 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 MapType

type MapType struct {
	Name        Name                 `json:"name"`
	Description string               `json:"description"`
	ElemType    string               `json:"elem_type"`
	Methods     map[string]*Function `json:"methods"`
	DefaultJSON string               `json:"default_json"`
}

func (*MapType) WriteGoFile

func (t *MapType) WriteGoFile(path string) error

func (*MapType) WriteTypeScriptFile

func (t *MapType) WriteTypeScriptFile(path string) error

type Metadata

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

type Method

type Method struct {
	Recv *Field
	Fn   *Function
}

type MethodCall

type MethodCall struct {
	Method string   `json:"m"`
	Args   []string `json:"args"`
}

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 Name

type Name []Word

func NewName

func NewName(s string) Name

func ParsePascalCaseName

func ParsePascalCaseName(name string) Name

Function to parse PascalCase name into words

func (Name) GoExported

func (n Name) GoExported() string

GoExported returns an exported Go name. Ex: "Green Button" => "GreenButton"

func (Name) GoUnexported

func (n Name) GoUnexported() string

func (Name) ID

func (n Name) ID() string

ID returns the id friendly string. Ex: "Green Button" => "green_button"

func (Name) LocalVarName

func (n Name) LocalVarName() string

func (Name) SnakeCase

func (n Name) SnakeCase() string

SnakeCase returns the pascal case representation of the string. Ex: "Green Button" => "green_button"

func (Name) String

func (n Name) String() string

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)
}

type Org

type Org struct {
	Readers Set[string]
	Writers Set[string]
}

func (*Org) IsReader

func (o *Org) IsReader(userID string) bool

func (*Org) IsWriter

func (o *Org) IsWriter(userID string) bool

type Package

type Package struct {
	ID        string              `json:"id"`
	Desc      string              `json:"desc"`
	Comments  []Comment           `json:"comments"`
	Types     map[string]Type     `json:"types"`
	Functions map[string]Function `json:"functions"`
	Variables map[string]Value    `json:"variables"`
	Constants map[string]Value    `json:"constants"`
}

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 PostgresDB

type PostgresDB struct {
	User string
	Pass string
	Host string
	DB   string
}

func (*PostgresDB) Open

func (pg *PostgresDB) Open() *sql.DB

type ProgrammingLanguage

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

type Prompt

type Prompt struct {
	Name    Name
	Desc    string
	Options []PromptOption
}

func (*Prompt) ServeHTTP

func (p *Prompt) ServeHTTP(w http.ResponseWriter, r *http.Request)

type PromptOption

type PromptOption struct {
	Name Name
	URL  string
}

type ReactComponent

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

func (*ReactComponent) Write

func (rc *ReactComponent) Write(path string) error

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 ReactHook

type ReactHook struct{}

func (*ReactHook) Write

func (h *ReactHook) Write(path string) error

type Ref

type Ref struct {
	From string `json:"from"`
	Name string `json:"name"`
}

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 Route

type Route struct {
	GetRoot  http.HandlerFunc
	PostRoot http.HandlerFunc
	GetID    func(id string, w http.ResponseWriter, r *http.Request)
	PostID   func(id string, w http.ResponseWriter, r *http.Request)
	PutID    func(id string, w http.ResponseWriter, r *http.Request)
	PatchID  func(id string, w http.ResponseWriter, r *http.Request)
	DeleteID func(id string, w http.ResponseWriter, r *http.Request)
}

func (*Route) ServeHTTP

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

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

type Sender

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

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]) Has

func (s Set[T]) Has(v T) bool

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 SinglePageApp

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

func (*SinglePageApp) ServeHTTP

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

type Statement

type Statement struct {
	IsReturn bool        `json:"isReturn"`
	Return   *Expression `json:"return"`

	IsAssign bool        `json:"isAssign"`
	Name     string      `json:"name"`
	Value    *Expression `json:"value"`

	IsIf      bool         `json:"isIf"`
	Condition *Expression  `json:"condition"`
	Body      []*Statement `json:"body"`
}

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.

func (*Statement) Imports

func (st *Statement) Imports() ImportMap

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 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 Table

type Table[T any] struct {
	DataDir  string
	IndexDir string
	Indexes  Set[string]
	// contains filtered or unexported fields
}

func (*Table[T]) Delete

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

func (*Table[T]) FindIDsBy

func (t *Table[T]) FindIDsBy(k, v string) (Set[string], error)

func (*Table[T]) Get

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

func (*Table[T]) Len

func (t *Table[T]) Len() int

func (*Table[T]) ListAll

func (t *Table[T]) ListAll() []string

func (*Table[T]) Post

func (t *Table[T]) Post(v *T) error

func (*Table[T]) Set

func (t *Table[T]) Set(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 {
	ID          string     `json:"id"`
	Desc        string     `json:"desc"`
	Comments    []Comment  `json:"comments"`
	Name        Name       `json:"name"`
	PluralName  Name       `json:"pluralName"`
	IsScalar    bool       `json:"isScalar"`
	IsArray     bool       `json:"isArray"`
	IsMap       bool       `json:"isMap"`
	ElemType    string     `json:"elemType"`
	IsStruct    bool       `json:"isStruct"`
	Fields      []Field    `json:"fields"`
	Methods     []Function `json:"methods"`
	DefaultJSON string     `json:"defaultJSON"`
}

func (*Type) Imports

func (t *Type) Imports() ImportMap

type User

type User struct {
	Email        string
	PasswordHash string
}

func (*User) IsPassword

func (u *User) IsPassword(pass string) bool

func (*User) SetPassword

func (u *User) SetPassword(pass string)

type Value

type Value struct {
	ID       string    `json:"id"`
	Desc     string    `json:"desc"`
	Comments []Comment `json:"comments"`
	Type     string    `json:"type"`
	JSON     string    `json:"json"`
}

type Video

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

type WebpageMetadata

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

type Word

type Word string

func (Word) Lower

func (w Word) Lower() Word

func (Word) String

func (w Word) String() string

func (Word) StripNonAlphaNumeric

func (w Word) StripNonAlphaNumeric() Word

func (Word) Title

func (w Word) Title() Word

func (Word) Upper

func (w Word) Upper() Word

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

Jump to

Keyboard shortcuts

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