app

package
v0.0.0-...-431d0f3 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: MIT Imports: 18 Imported by: 5

Documentation

Overview

Copyright (C) 2024 early (MIT)

Copyright (C) 2024 early (MIT)

Copyright (C) 2024 early (MIT)

Index

Constants

View Source
const (
	ENV_APP_NAME    = "APP_NAME"
	ENV_LISTEN_HTTP = "LISTEN_HTTP"
	ENV_LOG_LEVEL   = "LOG_LEVEL"
)

Variables

This section is empty.

Functions

func AppendEnv

func AppendEnv(vars []string, env Env) []string

AppendEnv appends the env as key=value pairs to a list of vars. This is intended for use with os.Environ() to pass environments to subprocesses:

cmd := exec.Command(...)
osEnv := os.Environ()
subprocessEnv := app.Env{...}
osEnv = app.AppendEnv(osEnv, subprocessEnv)
cmd.Exec()

Types

type AcceptsEnv

type AcceptsEnv interface {
	Apply(env Env)
}

type App

type App struct {
	http.Server
	http.ServeMux

	Logger *slog.Logger
	// contains filtered or unexported fields
}

func New

func New() *App

func (*App) Handle

func (app *App) Handle(expr string, handler http.Handler)

func (*App) ListenAndServe

func (app *App) ListenAndServe() error

func (*App) ServeHTTP

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

func (*App) Shutdown

func (app *App) Shutdown(ctx context.Context) error

func (*App) ShutdownOnSignal

func (app *App) ShutdownOnSignal(sigs ...os.Signal)

ShutdownOnSignal will start the process of an app shutting down if an OS signal is received.

func (*App) Static

func (app *App) Static(rootPath, rootDir string) error

Static serves the files in rootDir at rootPath.

  • .html files have their extensions stripped, and are served as their filenames, following a directory structure. If there is an index.html in a directory, it is served under the directory name, with a trailing slash, so /foo/bar/index.html is served at /foo/bar/.
  • Other non-excluded files are served with their extensions intact. Currently, .go files and anything in a hidden directory are excluded. MIME types are chosen by Go's standard HTTP library behavior until that becomes a pain.
  • If using today-engine, page.New and page.Static will *override* the default behavior of Static. *This is only possible when using today-engine.*
  • If static is called twice for the same rootPath, the second call will override the first.

func (*App) Subprocess

func (app *App) Subprocess(process func(done <-chan struct{}) error)

Subprocess will run process and ask the app to wait on it to close. Process must accept a channel that indicates when it should stop, and it should respect that command when possible.

type Env

type Env struct {
	AppName    string
	ListenHTTP string
	LogLevel   slog.Level
}

func GetEnv

func GetEnv() Env

GetEnv gets a set of values from environment variables that are common when running web applications. You don't have to use GetEnv for this

func (Env) Apply

func (env Env) Apply(app *App)

Jump to

Keyboard shortcuts

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