Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Replace fmt.Print with Logger Utils in Routes Package #2257

Merged
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
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)
kevkevinpal marked this conversation as resolved.
Show resolved Hide resolved
if err := server.ListenAndServe(); err != nil {
fmt.Println("server err:", err.Error())
utils.Log.Error("server err: %s", err.Error())
kevkevinpal marked this conversation as resolved.
Show resolved Hide resolved
}
}()

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
Loading