From 2619fe758ca3a5e29cf2d2b61b76b097cbd0328c Mon Sep 17 00:00:00 2001 From: jianli-97 Date: Tue, 28 May 2024 17:11:37 +0800 Subject: [PATCH] Fix some members are not initialized in struct HTTPService --- pkg/httpserver/httpserver.go | 6 ++++-- pkg/infra/ipxe.go | 4 +--- pkg/infra/pxe.go | 6 ++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/pkg/httpserver/httpserver.go b/pkg/httpserver/httpserver.go index 13ae939..5370e58 100644 --- a/pkg/httpserver/httpserver.go +++ b/pkg/httpserver/httpserver.go @@ -48,8 +48,10 @@ type HTTPService struct { func NewHTTPService(port string) *HTTPService { return &HTTPService{ - Port: port, - FileCache: make(map[string][]byte), + Port: port, + FileCache: make(map[string][]byte), + HttpLastRequestTime: time.Now().Unix(), + Ch: make(chan struct{}, 1), } } diff --git a/pkg/infra/ipxe.go b/pkg/infra/ipxe.go index 7db532a..9dd35f0 100644 --- a/pkg/infra/ipxe.go +++ b/pkg/infra/ipxe.go @@ -21,7 +21,6 @@ import ( "nestos-kubernetes-deployer/pkg/constants" "nestos-kubernetes-deployer/pkg/httpserver" "os" - "time" ) type IPXE struct { @@ -34,7 +33,6 @@ type IPXE struct { func (i *IPXE) deployHTTP(port string, dirPath string, filePath string) error { i.HTTPService.Port = port i.HTTPService.DirPath = dirPath - i.HTTPService.HttpLastRequestTime = time.Now().Unix() fileContent, err := os.ReadFile(filePath) if err != nil { @@ -46,7 +44,7 @@ func (i *IPXE) deployHTTP(port string, dirPath string, filePath string) error { } if err := i.HTTPService.Start(); err != nil { - return fmt.Errorf("error starting file service: %v", err) + return fmt.Errorf("error starting http service: %v", err) } return nil diff --git a/pkg/infra/pxe.go b/pkg/infra/pxe.go index 9eb512e..3fbd403 100644 --- a/pkg/infra/pxe.go +++ b/pkg/infra/pxe.go @@ -17,10 +17,10 @@ limitations under the License. package infra import ( - "github.com/sirupsen/logrus" "nestos-kubernetes-deployer/pkg/httpserver" "nestos-kubernetes-deployer/pkg/tftpserver" - "time" + + "github.com/sirupsen/logrus" ) type PXE struct { @@ -35,8 +35,6 @@ type PXE struct { func (p *PXE) deployHTTP(port string, dirPath string) error { p.HTTPService.Port = port p.HTTPService.DirPath = dirPath - p.HTTPService.HttpLastRequestTime = time.Now().Unix() - p.HTTPService.Ch = make(chan struct{}, 1) if err := p.HTTPService.Start(); err != nil { return err } -- Gitee