Skip to content

Commit

Permalink
Fix bad merge and don't use a global.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbruens committed Oct 7, 2024
1 parent be65ae3 commit 9de7a6a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
23 changes: 12 additions & 11 deletions caddy/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

var replayCache outline.ReplayCache
const outlineModuleName = "outline"

func init() {
caddy.RegisterModule(OutlineApp{})
replayCache = outline.NewReplayCache(0)
replayCache := outline.NewReplayCache(0)
caddy.RegisterModule(ModuleRegistration{
ID: outlineModuleName,
New: func() caddy.Module {
app := new(OutlineApp)
app.ReplayCache = replayCache
return app
},
})
}

const outlineModuleName = "outline"

type ShadowsocksConfig struct {
ReplayHistory int `json:"replay_history,omitempty"`
}
Expand All @@ -55,10 +60,7 @@ var (
)

func (OutlineApp) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{
ID: outlineModuleName,
New: func() caddy.Module { return new(OutlineApp) },
}
return caddy.ModuleInfo{ID: outlineModuleName}
}

// Provision sets up Outline.
Expand All @@ -68,8 +70,7 @@ func (app *OutlineApp) Provision(ctx caddy.Context) error {
app.logger.Info("provisioning app instance")

if app.ShadowsocksConfig != nil {
replayCache.Resize(app.ShadowsocksConfig.ReplayHistory)
app.ReplayCache = replayCache
app.ReplayCache.Resize(app.ShadowsocksConfig.ReplayHistory)
}

if err := app.defineMetrics(); err != nil {
Expand Down
1 change: 0 additions & 1 deletion caddy/config_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
},
"layer4": {
"servers": {

"1": {
"listen": [
"tcp/[::]:9000",
Expand Down
12 changes: 7 additions & 5 deletions caddy/shadowsocks_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ import (
"github.com/mholt/caddy-l4/layer4"
)

const ssModuleName = "layer4.handlers.shadowsocks"

func init() {
caddy.RegisterModule(&ShadowsocksHandler{})
caddy.RegisterModule(ModuleRegistration{
ID: ssModuleName,
New: func() caddy.Module { return new(ShadowsocksHandler) },
})
}

type KeyConfig struct {
Expand All @@ -50,10 +55,7 @@ var (
)

func (*ShadowsocksHandler) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{
ID: "layer4.handlers.shadowsocks",
New: func() caddy.Module { return new(ShadowsocksHandler) },
}
return caddy.ModuleInfo{ID: ssModuleName}
}

// Provision implements caddy.Provisioner.
Expand Down

0 comments on commit 9de7a6a

Please sign in to comment.