Skip to content

Commit f867efa

Browse files
committed
refactor: rename vhostMux to vhostHandler
1 parent ce1e4d4 commit f867efa

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

src/app/main.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import (
55
"../param"
66
"../serverErrHandler"
77
"../serverLog"
8-
"../vhostMux"
8+
"../vhostHandler"
99
"os"
1010
)
1111

1212
type App struct {
13-
vhostSvc *goVirtualHost.Service
14-
vhostMuxes []*vhostMux.VhostMux
13+
vhostSvc *goVirtualHost.Service
14+
vhostHandlers []*vhostHandler.VhostHandler
1515
}
1616

1717
func (app *App) Open() {
@@ -22,22 +22,22 @@ func (app *App) Open() {
2222
}
2323

2424
func (app *App) Close() {
25-
for _, vhMux := range app.vhostMuxes {
26-
vhMux.Close()
25+
for _, vhHandler := range app.vhostHandlers {
26+
vhHandler.Close()
2727
}
2828

2929
app.vhostSvc.Close()
3030
}
3131

3232
func (app *App) ReOpenLog() {
33-
for _, vhMux := range app.vhostMuxes {
34-
vhMux.ReOpenLog()
33+
for _, vhhandler := range app.vhostHandlers {
34+
vhhandler.ReOpenLog()
3535
}
3636
}
3737

3838
func NewApp(params []*param.Param) *App {
3939
vhSvc := goVirtualHost.NewService()
40-
vhMuxes := make([]*vhostMux.VhostMux, 0, len(params))
40+
vhHandlers := make([]*vhostHandler.VhostHandler, 0, len(params))
4141

4242
for _, p := range params {
4343
// logger
@@ -49,8 +49,8 @@ func NewApp(params []*param.Param) *App {
4949
errHandler := serverErrHandler.NewErrHandler(logger)
5050

5151
// ServeMux
52-
vhMux := vhostMux.NewServeMux(p, logger, errHandler)
53-
vhMuxes = append(vhMuxes, vhMux)
52+
vhHandler := vhostHandler.NewHandler(p, logger, errHandler)
53+
vhHandlers = append(vhHandlers, vhHandler)
5454

5555
// init vhost
5656
listens := p.Listens
@@ -68,7 +68,7 @@ func NewApp(params []*param.Param) *App {
6868
ListensTLS: p.ListensTLS,
6969
Cert: p.Certificate,
7070
HostNames: p.HostNames,
71-
Handler: vhMux.ServeMux,
71+
Handler: vhHandler.Handler,
7272
})
7373
if len(errors) > 0 {
7474
serverErrHandler.CheckFatal(errors...)
@@ -78,7 +78,7 @@ func NewApp(params []*param.Param) *App {
7878
}
7979

8080
return &App{
81-
vhostSvc: vhSvc,
82-
vhostMuxes: vhMuxes,
81+
vhostSvc: vhSvc,
82+
vhostHandlers: vhHandlers,
8383
}
8484
}

src/vhostMux/main.go renamed to src/vhostHandler/main.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package vhostMux
1+
package vhostHandler
22

33
import (
44
"../param"
@@ -10,18 +10,18 @@ import (
1010
"net/http"
1111
)
1212

13-
type VhostMux struct {
13+
type VhostHandler struct {
1414
p *param.Param
1515
logger *serverLog.Logger
1616
errorHandler *serverErrHandler.ErrHandler
17-
ServeMux *http.ServeMux
17+
Handler http.Handler
1818
}
1919

20-
func NewServeMux(
20+
func NewHandler(
2121
p *param.Param,
2222
logger *serverLog.Logger,
2323
errorHandler *serverErrHandler.ErrHandler,
24-
) *VhostMux {
24+
) *VhostHandler {
2525
users := user.NewUsers()
2626
for _, u := range p.UsersPlain {
2727
errorHandler.LogError(users.AddPlain(u.Username, u.Password))
@@ -61,30 +61,31 @@ func NewServeMux(
6161
handlers[urlPath] = serverHandler.NewHandler(fsPath, emptyHandlerRoot, urlPath, p, users, pageTpl, logger, errorHandler)
6262
}
6363

64-
// create ServeMux
64+
var handler http.Handler
6565
serveMux := &http.ServeMux{}
6666
for urlPath, handler := range handlers {
6767
serveMux.Handle(urlPath, handler)
6868
if len(urlPath) > 1 {
6969
serveMux.Handle(urlPath+"/", handler)
7070
}
7171
}
72+
handler = serveMux
7273

73-
vhostMux := &VhostMux{
74+
vhostHandler := &VhostHandler{
7475
p: p,
7576
logger: logger,
7677
errorHandler: errorHandler,
77-
ServeMux: serveMux,
78+
Handler: handler,
7879
}
7980

80-
return vhostMux
81+
return vhostHandler
8182
}
8283

83-
func (m *VhostMux) ReOpenLog() {
84+
func (m *VhostHandler) ReOpenLog() {
8485
errors := m.logger.ReOpen()
8586
serverErrHandler.CheckError(errors...)
8687
}
8788

88-
func (m *VhostMux) Close() {
89+
func (m *VhostHandler) Close() {
8990
m.logger.Close()
9091
}

0 commit comments

Comments
 (0)