mirror of
https://github.com/caddyserver/caddy.git
synced 2025-07-09 03:04:57 -04:00
Updated Writing a Plugin: Server Type (markdown)
parent
1162963413
commit
65fb915f42
@ -57,15 +57,22 @@ Ultimately, your goal is to make it so that `MakeServers()` returns a list of [c
|
|||||||
|
|
||||||
For example: the HTTP server [uses its context type](https://github.com/mholt/caddy/blob/aede4ccbce94bcb67161674e30dd1bfa7296448c/caddyhttp/httpserver/plugin.go#L54-L63) to keep a map of site configs. The package also has an exported function, `GetConfig(c Controller)` that gets a config for a certain site, designated by the [caddy.Controller](https://godoc.org/github.com/mholt/caddy#Controller) that is passed in. The config, in turn, stores the list of middleware, etc -- all the information needed to set up a site. Each directive's action calls the GetConfig function so they can help set up the site properly. By the time `MakeServers()` is called, all it has to do is combine those site configs into server instances and return them. (Server instances implement [caddy.Server](https://godoc.org/github.com/mholt/caddy#Server).)
|
For example: the HTTP server [uses its context type](https://github.com/mholt/caddy/blob/aede4ccbce94bcb67161674e30dd1bfa7296448c/caddyhttp/httpserver/plugin.go#L54-L63) to keep a map of site configs. The package also has an exported function, `GetConfig(c Controller)` that gets a config for a certain site, designated by the [caddy.Controller](https://godoc.org/github.com/mholt/caddy#Controller) that is passed in. The config, in turn, stores the list of middleware, etc -- all the information needed to set up a site. Each directive's action calls the GetConfig function so they can help set up the site properly. By the time `MakeServers()` is called, all it has to do is combine those site configs into server instances and return them. (Server instances implement [caddy.Server](https://godoc.org/github.com/mholt/caddy#Server).)
|
||||||
|
|
||||||
The caddy.Server interface has four methods; two are for TCP, two are for UDP or other:
|
## Server
|
||||||
|
|
||||||
|
The `caddy.Server` interface considers both TCP and non-TCP servers. It has four methods; two are for TCP, two are for UDP or other:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
type Server interface {
|
type Server interface {
|
||||||
// Required if using TCP
|
TCPServer // Required if using TCP
|
||||||
|
UDPServer // Required if using UDP or other
|
||||||
|
}
|
||||||
|
|
||||||
|
type TCPServer interface {
|
||||||
Listen() (net.Listener, error)
|
Listen() (net.Listener, error)
|
||||||
Serve(net.Listener) error
|
Serve(net.Listener) error
|
||||||
|
}
|
||||||
|
|
||||||
// Required if using UDP or other
|
type UDPServer interface {
|
||||||
ListenPacket() (net.PacketConn, error)
|
ListenPacket() (net.PacketConn, error)
|
||||||
ServePacket(net.PacketConn) error
|
ServePacket(net.PacketConn) error
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user