Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ func main() {

listener, err := net.Listen("tcp", net.JoinHostPort(LOCALHOST, "0"))
if err != nil {
panic(err)
logger.Error("Failed to create TCP listener", zap.Error(err))
return
}
routers := []string{
"/v1/sys",
Expand All @@ -155,8 +156,8 @@ func main() {
Target: "http://" + listener.Addr().String(),
})
if err != nil {
fmt.Println("err", err)
panic(err)
logger.Error("Failed to create route", zap.Error(err), zap.String("path", apiPath))
continue
Comment on lines +159 to +160

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why continue loading the server? This hides server loading issues, and it takes a while for whomever ran this service to know something is off (as the process didn't exit)

}
}

Expand All @@ -169,7 +170,7 @@ func main() {
if response != nil && response.StatusCode() != http.StatusOK {
logger.Error("error when trying to register one or more event types - some event type will not be discoverable", zap.String("status", response.Status()), zap.String("body", string(response.Body)))
}
if response.StatusCode() == http.StatusOK {
if response != nil && response.StatusCode() == http.StatusOK {
break
}
time.Sleep(time.Second)
Expand Down Expand Up @@ -224,6 +225,7 @@ func main() {
// defer service.MyService.Storage().UnmountAllStorage()
err = s.Serve(listener) // not using http.serve() to fix G114: Use of net/http serve function that has no support for setting timeouts (see https://github.com/securego/gosec)
if err != nil {
panic(err)
logger.Error("Server failed to start", zap.Error(err))
return
Comment on lines +228 to +229

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return is redundant

Suggested change
logger.Error("Server failed to start", zap.Error(err))
return
logger.Error("Server failed to start", zap.Error(err))

}
}
6 changes: 3 additions & 3 deletions pkg/utils/httper/httper.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func Post(url string, data []byte, contentType string, head map[string]string) (
req.Header.Add(k, v)
}
if err != nil {
panic(err)
return ""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this "proper error handling"

Error should be bubbled up, so that whomever did the Post can handle it.

Empty content might be ok in some cases

}

client := &http.Client{Timeout: 5 * time.Second}
Expand All @@ -120,14 +120,14 @@ func ZeroTierGet(url string, head map[string]string) (content string, code int)
req.Header.Add(k, v)
}
if err != nil {
panic(err)
return "", 0
}

client := &http.Client{Timeout: 20 * time.Second}
resp, error := client.Do(req)

if error != nil {
panic(error)
return "", 0
}
defer resp.Body.Close()
code = resp.StatusCode
Expand Down