Skip to content

Commit

Permalink
refactor: replace fmt.Print with logger utils in routes (#2257)
Browse files Browse the repository at this point in the history
  • Loading branch information
saithsab877 authored Dec 20, 2024
1 parent 5aa7662 commit 1bc2518
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions routes/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/stakwork/sphinx-tribes/utils"
)


// NewRouter creates a chi router
func NewRouter() *http.Server {
r := initChi()
Expand Down Expand Up @@ -108,12 +107,11 @@ func NewRouter() *http.Server {
server := &http.Server{Addr: ":" + PORT, Handler: r}

go func() {
fmt.Println("Listening on port " + PORT)
utils.Log.Info("Listening on port %s", PORT)
if err := server.ListenAndServe(); err != nil {
fmt.Println("server err:", err.Error())
utils.Log.Error("server err: %s", err.Error())
}
}()

return server
}

Expand Down Expand Up @@ -150,21 +148,21 @@ func getFromAuth(path string) (*extractResponse, error) {

func sendEdgeListToJarvis(edgeList utils.EdgeList) error {
if config.JarvisUrl == "" || config.JarvisToken == "" {
fmt.Println("Jarvis configuration not found, skipping error reporting")
utils.Log.Info("Jarvis configuration not found, skipping error reporting")
return nil
}

jarvisURL := fmt.Sprintf("%s/node/edge/bulk", config.JarvisUrl)

jsonData, err := json.Marshal(edgeList)
if err != nil {
fmt.Printf("Failed to marshal edge list: %v\n", err)
utils.Log.Error("Failed to marshal edge list: %v", err)
return nil
}

req, err := http.NewRequest("POST", jarvisURL, bytes.NewBuffer(jsonData))
if err != nil {
fmt.Printf("Failed to create Jarvis request: %v\n", err)
utils.Log.Error("Failed to create Jarvis request: %v", err)
return nil
}

Expand All @@ -177,13 +175,13 @@ func sendEdgeListToJarvis(edgeList utils.EdgeList) error {

resp, err := client.Do(req)
if err != nil {
fmt.Printf("Failed to send error to Jarvis: %v\n", err)
utils.Log.Error("Failed to send error to Jarvis: %v", err)
return err
}
defer resp.Body.Close()

if resp.StatusCode >= 200 && resp.StatusCode < 300 {
fmt.Println("Successfully sent error to Jarvis")
utils.Log.Info("Successfully sent error to Jarvis")
return nil
}

Expand Down

0 comments on commit 1bc2518

Please sign in to comment.