mirror of
https://github.com/mjl-/mox.git
synced 2024-12-25 16:03:48 +03:00
6706c5c84a
- serve static files, serving index.html or optionally listings for directories - redirects - reverse-proxy, forwarding requests to a backend these are configurable through the config file. a domain and path regexp have to be configured. path prefixes can be stripped. configured domains are added to the autotls allowlist, so acme automatically fetches certificates for them. all webserver requests now have (access) logging, metrics, rate limiting. on http errors, the error message prints an encrypted cid for relating with log files. this also adds a new mechanism for example config files.
29 lines
455 B
Go
29 lines
455 B
Go
package mox
|
|
|
|
import (
|
|
"context"
|
|
"sync/atomic"
|
|
"time"
|
|
|
|
"github.com/mjl-/mox/mlog"
|
|
)
|
|
|
|
var cid atomic.Int64
|
|
|
|
func init() {
|
|
cid.Store(time.Now().UnixMilli())
|
|
}
|
|
|
|
// Cid returns a new unique id to be used for connections/sessions/requests.
|
|
func Cid() int64 {
|
|
return cid.Add(1)
|
|
}
|
|
|
|
// CidFromCtx returns the cid in the context, or 0.
|
|
func CidFromCtx(ctx context.Context) int64 {
|
|
v := ctx.Value(mlog.CidKey)
|
|
if v == nil {
|
|
return 0
|
|
}
|
|
return v.(int64)
|
|
}
|