serve

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

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

Go to latest
Published: Aug 4, 2019 License: MIT Imports: 16 Imported by: 0

README

* why
caddy is nice - but it's huge (~15k LOC) and not that easy to grok - i mainly want an http server that serves my blog (static) and
maybe proxies a few random services to the outside world. nginx or whatever would also be possible but i hope this will teach me something
about http servers and nginx is just so annoying to configure...
* todo
- tests (httptest)
  - not sure yet how i want to structure tests - seems hard to use the fixture pattern and i really like that one right now
  - e.g. for log other outputs are required - maybe i'll have to write tests by hand here
- middleware: [[https://blog.golang.org/http-tracing][tracing]], pprof
- systemd: socket activation
- systemd: paths for StateDirectory, LogsDirectory...
* limitations
- limited feature scope and configurability - the goal is something more barebones/simple
- no wildcard routing / certs
- no ecosystem of 3rd party middlewares
- no fancy caddyfile syntax - just json for now. what annoys me about other http servers is not the configuration format itself but
  how much you have to configure - i want the sane defaults thing from caddy but will keep json because i don't see value in adding the complexity
  of a custom configfile format (for now; i do like writing parsers...)
* misc
** git fs

type GitFS struct{ http.FileSystem }

func (fs *GitFS) Open(name string) (http.File, error) {
	switch path.Base(name) {
	// https://stackoverflow.com/questions/12605576/git-special-files
	case ".git", ".gitignore", ".gitattributes", ".gitmodules":
		return nil, os.ErrNotExist
	default:
		return fs.FileSystem.Open(name)
	}
}
* inspiration
- https://github.com/mholt/caddy/
- https://github.com/oklog/run/blob/master/group.go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReloadSignalContext

func ReloadSignalContext(signals ...os.Signal) context.Context

func Start

func Start(ctx context.Context, c *Config) error

Types

type Config

type Config struct {
	HTTPConfig struct {
		HTTPAddress  string
		HTTPSAddress string
		server.Config
	}
	LetsEncrypt  server.LetsEncryptConfig
	VirtualHosts []VirtualHost
}

func ReadConfig

func ReadConfig(path string) (*Config, error)

func ReadConfigDirectory

func ReadConfigDirectory(path string) (*Config, error)

type Handler

type Handler interface {
	Wrap(http.Handler) (http.Handler, func(context.Context) error, error)
}

type Middleware

type Middleware struct {
	Name string
	Handler
}

func (*Middleware) UnmarshalJSON

func (d *Middleware) UnmarshalJSON(bytes []byte) error

type VirtualHost

type VirtualHost struct {
	Patterns    []string
	Middlewares []Middleware
}

type WaitGroup

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

func NewWaitGroup

func NewWaitGroup(ctx context.Context) *WaitGroup

func (*WaitGroup) Cancel

func (wg *WaitGroup) Cancel()

func (*WaitGroup) Start

func (wg *WaitGroup) Start(fn func(context.Context) error)

func (*WaitGroup) Wait

func (wg *WaitGroup) Wait() error

Directories

Path Synopsis
cmd
We should not log access.log to journald
We should not log access.log to journald

Jump to

Keyboard shortcuts

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