Skip to content

Commit b7884d0

Browse files
committed
adding required updates regarding readFile
1 parent f146435 commit b7884d0

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

internal/mode/static/nginx/runtime/manager.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ type ProcessHandler interface {
5656
ctx context.Context,
5757
timeout time.Duration,
5858
) (int, error)
59-
ReadFile(file string) ([]byte, error)
59+
readFile(file string) ([]byte, error)
6060
Kill(pid int) error
6161
}
6262

6363
type ProcessHandlerImpl struct {
64-
ReadFile ReadFileFunc
64+
readFile ReadFileFunc
6565
checkFile CheckFileFunc
6666
}
6767

@@ -130,7 +130,7 @@ func (m *ManagerImpl) Reload(ctx context.Context, configVersion int) error {
130130
}
131131

132132
childProcFile := fmt.Sprintf(childProcPathFmt, pid)
133-
previousChildProcesses, err := m.processHandler.ReadFile(childProcFile)
133+
previousChildProcesses, err := m.processHandler.readFile(childProcFile)
134134
if err != nil {
135135
return err
136136
}
@@ -193,11 +193,16 @@ func (m *ManagerImpl) GetUpstreams() (ngxclient.Upstreams, error) {
193193
return *upstreams, nil
194194
}
195195

196-
type NewProcessHandlerImpl struct {
197-
checkFile func(file string) (string, error)
196+
func NewProcessHandlerImpl(readFile ReadFileFunc, checkFile CheckFileFunc) *ProcessHandlerImpl {
197+
ph := &ProcessHandlerImpl{
198+
readFile: readFile,
199+
checkFile: checkFile,
200+
}
201+
202+
return ph
198203
}
199204

200-
func (p *NewProcessHandlerImpl) FindMainProcess(
205+
func (p *ProcessHandlerImpl) FindMainProcess(
201206
ctx context.Context,
202207
timeout time.Duration,
203208
) (int, error) {
@@ -222,7 +227,7 @@ func (p *NewProcessHandlerImpl) FindMainProcess(
222227
return 0, err
223228
}
224229

225-
content, err := p.ReadFile(PidFile)
230+
content, err := p.readFile(PidFile)
226231
if err != nil {
227232
return 0, err
228233
}
@@ -235,10 +240,10 @@ func (p *NewProcessHandlerImpl) FindMainProcess(
235240
return pid, nil
236241
}
237242

238-
func (p *NewProcessHandlerImpl) ReadFile(file string) ([]byte, error) {
243+
func (p *ProcessHandlerImpl) ReadFile(file string) ([]byte, error) {
239244
return p.ReadFile(file)
240245
}
241246

242-
func (p *NewProcessHandlerImpl) Kill(pid int) error {
247+
func (p *ProcessHandlerImpl) Kill(pid int) error {
243248
return syscall.Kill(pid, syscall.SIGHUP)
244249
}

0 commit comments

Comments
 (0)