diff --git a/handlers/auth.go b/handlers/auth.go index 0070d2001..490272801 100644 --- a/handlers/auth.go +++ b/handlers/auth.go @@ -63,7 +63,7 @@ func (ah *authHandler) CreateConnectionCode(w http.ResponseWriter, r *http.Reque body, err := io.ReadAll(r.Body) if err != nil { - fmt.Println("ReadAll Error", err) + utils.Log.Error("ReadAll Error: %v", err) w.WriteHeader(http.StatusBadRequest) return } @@ -72,7 +72,7 @@ func (ah *authHandler) CreateConnectionCode(w http.ResponseWriter, r *http.Reque err = json.Unmarshal(body, &codeBody) if err != nil { - fmt.Println("Could not unmarshal connection code body") + utils.Log.Error("Could not unmarshal connection code body") w.WriteHeader(http.StatusNotAcceptable) return } @@ -110,7 +110,7 @@ func (ah *authHandler) CreateConnectionCode(w http.ResponseWriter, r *http.Reque _, err = ah.db.CreateConnectionCode(codeArr) if err != nil { - fmt.Println("[auth] => ERR create connection code", err) + utils.Log.Error("[auth] => ERR create connection code: %v", err) w.WriteHeader(http.StatusBadRequest) return } @@ -149,7 +149,7 @@ func MakeConnectionCodeRequest(inviter_pubkey string, inviter_route_hint string, err = json.Unmarshal(body, &inviteReponse) if err != nil { - fmt.Println("Could not get connection code") + utils.Log.Error("Could not get connection code") return "" } @@ -202,7 +202,7 @@ func ReceiveLnAuthData(w http.ResponseWriter, r *http.Request) { exVerify, err := auth.VerifyDerSig(sig, k1, userKey) if err != nil || !exVerify { - fmt.Println("[auth] Error signing signature") + utils.Log.Error("[auth] Error signing signature") w.WriteHeader(http.StatusUnauthorized) json.NewEncoder(w).Encode(err.Error()) return @@ -221,7 +221,7 @@ func ReceiveLnAuthData(w http.ResponseWriter, r *http.Request) { tokenString, err := auth.EncodeJwt(userKey) if err != nil { - fmt.Println("[auth] error creating LNAUTH JWT") + utils.Log.Error("[auth] error creating LNAUTH JWT") w.WriteHeader(http.StatusNotAcceptable) json.NewEncoder(w).Encode(err.Error()) return @@ -245,7 +245,7 @@ func ReceiveLnAuthData(w http.ResponseWriter, r *http.Request) { socket.Conn.WriteJSON(socketMsg) db.Store.DeleteCache(k1[0:20]) } else { - fmt.Println("[auth] Socket Error", err) + utils.Log.Error("[auth] Socket Error: %v", err) } responseMsg["status"] = "OK" @@ -265,7 +265,7 @@ func (ah *authHandler) RefreshToken(w http.ResponseWriter, r *http.Request) { claims, err := ah.decodeJwt(token) if err != nil { - fmt.Println("[auth] Failed to parse JWT") + utils.Log.Error("[auth] Failed to parse JWT") w.WriteHeader(http.StatusUnauthorized) json.NewEncoder(w).Encode(err.Error()) return @@ -280,7 +280,7 @@ func (ah *authHandler) RefreshToken(w http.ResponseWriter, r *http.Request) { tokenString, err := ah.encodeJwt(pubkey) if err != nil { - fmt.Println("[auth] error creating refresh JWT") + utils.Log.Error("[auth] error creating refresh JWT") w.WriteHeader(http.StatusNotAcceptable) json.NewEncoder(w).Encode(err.Error()) return diff --git a/handlers/bots.go b/handlers/bots.go index 8f45af85c..90ae2b623 100644 --- a/handlers/bots.go +++ b/handlers/bots.go @@ -2,7 +2,6 @@ package handlers import ( "encoding/json" - "fmt" "io" "net/http" "regexp" @@ -13,6 +12,7 @@ import ( "github.com/go-chi/chi" "github.com/stakwork/sphinx-tribes/auth" "github.com/stakwork/sphinx-tribes/db" + "github.com/stakwork/sphinx-tribes/utils" ) type botHandler struct { @@ -36,7 +36,7 @@ func (bt *botHandler) CreateOrEditBot(w http.ResponseWriter, r *http.Request) { r.Body.Close() err = json.Unmarshal(body, &bot) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -50,7 +50,7 @@ func (bt *botHandler) CreateOrEditBot(w http.ResponseWriter, r *http.Request) { extractedPubkey, err := bt.verifyTribeUUID(bot.UUID, false) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusUnauthorized) return } @@ -70,7 +70,7 @@ func (bt *botHandler) CreateOrEditBot(w http.ResponseWriter, r *http.Request) { _, err = bt.db.CreateOrEditBot(bot) if err != nil { - fmt.Println("=> ERR createOrEditBot", err) + utils.Log.Error("=> ERR createOrEditBot: %v", err) w.WriteHeader(http.StatusBadRequest) return } @@ -127,7 +127,7 @@ func (bt *botHandler) DeleteBot(w http.ResponseWriter, r *http.Request) { uuid := chi.URLParam(r, "uuid") - fmt.Println("uuid: ", uuid) + utils.Log.Info("uuid: %s", uuid) if uuid == "" { w.WriteHeader(http.StatusUnauthorized) @@ -136,7 +136,7 @@ func (bt *botHandler) DeleteBot(w http.ResponseWriter, r *http.Request) { extractedPubkey, err := bt.verifyTribeUUID(uuid, false) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusUnauthorized) return } diff --git a/handlers/bounties.go b/handlers/bounties.go index 6177442ab..3b56dd547 100644 --- a/handlers/bounties.go +++ b/handlers/bounties.go @@ -2,7 +2,6 @@ package handlers import ( "encoding/json" - "fmt" "io" "log" "net/http" @@ -11,6 +10,7 @@ import ( "github.com/lib/pq" "github.com/stakwork/sphinx-tribes/db" + "github.com/stakwork/sphinx-tribes/utils" ) func GetWantedsHeader(w http.ResponseWriter, r *http.Request) { @@ -54,7 +54,7 @@ func DeleteBountyAssignee(w http.ResponseWriter, r *http.Request) { err = json.Unmarshal(body, &invoice) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -91,17 +91,17 @@ func MigrateBounties(w http.ResponseWriter, r *http.Request) { peeps := db.DB.GetAllPeople() for indexPeep, peep := range peeps { - fmt.Println("peep: ", indexPeep) + utils.Log.Info("peep: %d", indexPeep) bounties, ok := peep.Extras["wanted"].([]interface{}) if !ok { - fmt.Println("Wanted not there") + utils.Log.Info("Wanted not there") continue } for index, bounty := range bounties { - fmt.Println("looping bounties: ", index) + utils.Log.Info("looping bounties: %d", index) migrateBounty := bounty.(map[string]interface{}) migrateBountyFinal := db.Bounty{} @@ -156,8 +156,8 @@ func MigrateBounties(w http.ResponseWriter, r *http.Request) { if !ok7 { migrateBountyFinal.Created = 0 } else { - fmt.Println(reflect.TypeOf(CreatedInt64)) - fmt.Println("Timestamp:", CreatedInt64) + utils.Log.Info("Type: %v", reflect.TypeOf(CreatedInt64)) + utils.Log.Info("Timestamp: %d", CreatedInt64) migrateBountyFinal.Created = CreatedInt64 } @@ -237,7 +237,7 @@ func MigrateBounties(w http.ResponseWriter, r *http.Request) { } else { migrateBountyFinal.EstimatedCompletionDate = EstimatedCompletionDate } - fmt.Println("Bounty about to be added ") + utils.Log.Info("Bounty about to be added ") db.DB.AddBounty(migrateBountyFinal) //Migrate the bounties here } diff --git a/handlers/bounty.go b/handlers/bounty.go index 8e1d4eb2e..ab0317bcb 100644 --- a/handlers/bounty.go +++ b/handlers/bounty.go @@ -61,7 +61,7 @@ func (h *bountyHandler) GetBountyById(w http.ResponseWriter, r *http.Request) { bounties, err := h.db.GetBountyById(bountyId) if err != nil { w.WriteHeader(http.StatusBadRequest) - fmt.Println("[bounty] Error", err) + utils.Log.Error("[bounty] Error: %v", err) } else { var bountyResponse []db.BountyResponse = h.GenerateBountyResponse(bounties) w.WriteHeader(http.StatusOK) @@ -73,7 +73,7 @@ func (h *bountyHandler) GetNextBountyByCreated(w http.ResponseWriter, r *http.Re bounties, err := h.db.GetNextBountyByCreated(r) if err != nil { w.WriteHeader(http.StatusBadRequest) - fmt.Println("[bounty] Error", err) + utils.Log.Error("[bounty] Error: %v", err) } else { w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(bounties) @@ -84,7 +84,7 @@ func (h *bountyHandler) GetPreviousBountyByCreated(w http.ResponseWriter, r *htt bounties, err := h.db.GetPreviousBountyByCreated(r) if err != nil { w.WriteHeader(http.StatusBadRequest) - fmt.Println("[bounty] Error", err) + utils.Log.Error("[bounty] Error: %v", err) } else { w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(bounties) @@ -95,7 +95,7 @@ func (h *bountyHandler) GetWorkspaceNextBountyByCreated(w http.ResponseWriter, r bounties, err := h.db.GetNextWorkspaceBountyByCreated(r) if err != nil { w.WriteHeader(http.StatusBadRequest) - fmt.Println("[bounty] Error", err) + utils.Log.Error("[bounty] Error: %v", err) } else { w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(bounties) @@ -106,7 +106,7 @@ func (h *bountyHandler) GetWorkspacePreviousBountyByCreated(w http.ResponseWrite bounties, err := h.db.GetPreviousWorkspaceBountyByCreated(r) if err != nil { w.WriteHeader(http.StatusBadRequest) - fmt.Println("[bounty] Error", err) + utils.Log.Error("[bounty] Error: %v", err) } else { w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(bounties) @@ -132,7 +132,7 @@ func (h *bountyHandler) GetBountyByCreated(w http.ResponseWriter, r *http.Reques bounties, err := h.db.GetBountyDataByCreated(created) if err != nil { w.WriteHeader(http.StatusBadRequest) - fmt.Println("[bounty] Error", err) + utils.Log.Error("[bounty] Error: %v", err) } else { var bountyResponse []db.BountyResponse = h.GenerateBountyResponse(bounties) @@ -164,7 +164,7 @@ func (h *bountyHandler) GetPersonCreatedBounties(w http.ResponseWriter, r *http. bounties, err := h.db.GetCreatedBounties(r) if err != nil { w.WriteHeader(http.StatusBadRequest) - fmt.Println("[bounty] Error", err) + utils.Log.Error("[bounty] Error: %v", err) } else { var bountyResponse []db.BountyResponse = h.GenerateBountyResponse(bounties) w.WriteHeader(http.StatusOK) @@ -176,7 +176,7 @@ func (h *bountyHandler) GetPersonAssignedBounties(w http.ResponseWriter, r *http bounties, err := h.db.GetAssignedBounties(r) if err != nil { w.WriteHeader(http.StatusBadRequest) - fmt.Println("[bounty] Error", err) + utils.Log.Error("[bounty] Error: %v", err) } else { var bountyResponse []db.BountyResponse = h.GenerateBountyResponse(bounties) w.WriteHeader(http.StatusOK) @@ -193,14 +193,14 @@ func (h *bountyHandler) CreateOrEditBounty(w http.ResponseWriter, r *http.Reques r.Body.Close() if err != nil { - fmt.Println("[bounty read]", err) + utils.Log.Error("[bounty] Read error: %v", err) w.WriteHeader(http.StatusNotAcceptable) return } err = json.Unmarshal(body, &bounty) if err != nil { - fmt.Println("[bounty]", err) + utils.Log.Error("[bounty] Unmarshal error: %v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -260,7 +260,7 @@ func (h *bountyHandler) CreateOrEditBounty(w http.ResponseWriter, r *http.Reques // check if the bounty has a pending payment if dbBounty.PaymentPending { msg := "You cannot update a bounty with a pending payment" - fmt.Println("[bounty]", msg) + utils.Log.Info("[bounty]: %v", msg) w.WriteHeader(http.StatusBadRequest) json.NewEncoder(w).Encode(msg) return @@ -273,14 +273,14 @@ func (h *bountyHandler) CreateOrEditBounty(w http.ResponseWriter, r *http.Reques hasBountyRoles := h.userHasManageBountyRoles(pubKeyFromAuth, bounty.WorkspaceUuid) if !hasBountyRoles { msg := "You don't have the right permission ton update bounty" - fmt.Println("[bounty]", msg) + utils.Log.Info("[bounty]: %v", msg) w.WriteHeader(http.StatusBadRequest) json.NewEncoder(w).Encode(msg) return } } else { msg := "Cannot edit another user's bounty" - fmt.Println("[bounty]", msg) + utils.Log.Info("[bounty]: %v", msg) w.WriteHeader(http.StatusBadRequest) json.NewEncoder(w).Encode(msg) return @@ -304,7 +304,7 @@ func (h *bountyHandler) CreateOrEditBounty(w http.ResponseWriter, r *http.Reques b, err := h.db.CreateOrEditBounty(bounty) if err != nil { - fmt.Println("[bounty]", err) + utils.Log.Error("[bounty] Error: %v", err) w.WriteHeader(http.StatusBadRequest) return } @@ -318,7 +318,7 @@ func (h *bountyHandler) DeleteBounty(w http.ResponseWriter, r *http.Request) { pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("[bounty] no pubkey from auth") + utils.Log.Error("[bounty] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -327,12 +327,12 @@ func (h *bountyHandler) DeleteBounty(w http.ResponseWriter, r *http.Request) { pubkey := chi.URLParam(r, "pubkey") if pubkey == "" { - fmt.Println("[bounty] no pubkey from route") + utils.Log.Error("[bounty] no pubkey from route") w.WriteHeader(http.StatusUnauthorized) return } if created == "" { - fmt.Println("[bounty] no created timestamp from route") + utils.Log.Error("[bounty] no created timestamp from route") w.WriteHeader(http.StatusUnauthorized) return } @@ -341,14 +341,14 @@ func (h *bountyHandler) DeleteBounty(w http.ResponseWriter, r *http.Request) { createdUint, _ := utils.ConvertStringToUint(created) createdBounty, err := h.db.GetBountyByCreated(createdUint) if err != nil { - fmt.Println("[bounty] failed to delete bounty", err.Error()) + utils.Log.Error("[bounty] failed to delete bounty: %v", err) w.WriteHeader(http.StatusInternalServerError) json.NewEncoder(w).Encode("failed to delete bounty") return } if createdBounty.ID == 0 { - fmt.Println("[bounty] failed to delete bounty") + utils.Log.Error("[bounty] failed to delete bounty") w.WriteHeader(http.StatusInternalServerError) json.NewEncoder(w).Encode("failed to delete bounty") return @@ -356,7 +356,7 @@ func (h *bountyHandler) DeleteBounty(w http.ResponseWriter, r *http.Request) { b, err := h.db.DeleteBounty(pubkey, created) if err != nil { - fmt.Println("[bounty] failed to delete bounty", err.Error()) + utils.Log.Error("[bounty] failed to delete bounty: %v", err) w.WriteHeader(http.StatusInternalServerError) json.NewEncoder(w).Encode("failed to delete bounty") return @@ -533,14 +533,14 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request id, err := utils.ConvertStringToUint(idParam) if err != nil { - fmt.Println("[bounty] could not parse id") + utils.Log.Error("[bounty] could not parse id") w.WriteHeader(http.StatusForbidden) h.m.Unlock() return } if pubKeyFromAuth == "" { - fmt.Println("[bounty] no pubkey from auth") + utils.Log.Error("[bounty] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) h.m.Unlock() return @@ -598,7 +598,7 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request body, err := io.ReadAll(r.Body) r.Body.Close() if err != nil { - fmt.Println("[read body]", err) + utils.Log.Error("[bounty] Read body error: %v", err) w.WriteHeader(http.StatusNotAcceptable) h.m.Unlock() return @@ -606,7 +606,7 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request err = json.Unmarshal(body, &request) if err != nil { - fmt.Println("[bounty]", err) + utils.Log.Error("[bounty] Unmarshal error: %v", err) w.WriteHeader(http.StatusNotAcceptable) h.m.Unlock() return @@ -623,7 +623,7 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request if config.IsV2Payment { url := fmt.Sprintf("%s/pay", config.V2BotUrl) - fmt.Println("IS V2 PAYMENT ====") + utils.Log.Info("IS V2 PAYMENT ====") // Build v2 keysend payment data bodyData := utils.BuildV2KeysendBodyData(amount, assignee.OwnerPubKey, assignee.OwnerRouteHint, memoText) @@ -681,7 +681,7 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request err = json.Unmarshal(body, &v2KeysendRes) if err != nil { - fmt.Println("[Unmarshal failed]", err) + utils.Log.Error("[Unmarshal failed]: %v", err) w.WriteHeader(http.StatusNotAcceptable) h.m.Unlock() return @@ -826,7 +826,7 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request defer res.Body.Close() body, err = io.ReadAll(res.Body) if err != nil { - fmt.Println("[read body]", err) + utils.Log.Error("[bounty] Read body error: %v", err) w.WriteHeader(http.StatusNotAcceptable) h.m.Unlock() return @@ -842,7 +842,7 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request err = json.Unmarshal(body, &keysendRes) if err != nil { - fmt.Println("[Unmarshal]", err) + utils.Log.Error("[bounty] Unmarshal error: %v", err) w.WriteHeader(http.StatusNotAcceptable) h.m.Unlock() return @@ -900,13 +900,13 @@ func (h *bountyHandler) GetBountyPaymentStatus(w http.ResponseWriter, r *http.Re id, err := utils.ConvertStringToUint(idParam) if err != nil { - fmt.Println("[bounty] could not parse id") + utils.Log.Error("[bounty] could not parse id") w.WriteHeader(http.StatusForbidden) return } if pubKeyFromAuth == "" { - fmt.Println("[bounty] no pubkey from auth") + utils.Log.Error("[bounty] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -943,13 +943,13 @@ func (h *bountyHandler) UpdateBountyPaymentStatus(w http.ResponseWriter, r *http id, err := utils.ConvertStringToUint(idParam) if err != nil { - fmt.Println("[bounty] could not parse id") + utils.Log.Error("[bounty] could not parse id") w.WriteHeader(http.StatusForbidden) return } if pubKeyFromAuth == "" { - fmt.Println("[bounty] no pubkey from auth") + utils.Log.Error("[bounty] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -1055,7 +1055,7 @@ func (h *bountyHandler) BountyBudgetWithdraw(w http.ResponseWriter, r *http.Requ pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("[bounty] no pubkey from auth") + utils.Log.Error("[bounty] no pubkey from auth") h.m.Unlock() w.WriteHeader(http.StatusUnauthorized) @@ -1447,7 +1447,7 @@ func (h *bountyHandler) PollInvoice(w http.ResponseWriter, r *http.Request) { paymentRequest := chi.URLParam(r, "paymentRequest") if pubKeyFromAuth == "" { - fmt.Println("[bounty] no pubkey from auth") + utils.Log.Error("[bounty] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } diff --git a/handlers/bounty_test.go b/handlers/bounty_test.go index ee8567ef8..02cb94af5 100644 --- a/handlers/bounty_test.go +++ b/handlers/bounty_test.go @@ -235,7 +235,7 @@ func TestCreateOrEditBounty(t *testing.T) { json, err := json.Marshal(updatedBounty) if err != nil { - fmt.Println("Could not marshal json data") + utils.Log.Error("Could not marshal json data") } req, err := http.NewRequestWithContext(ctx, http.MethodPost, "/", bytes.NewReader(json)) @@ -1242,7 +1242,7 @@ func MockNewWSServer(t *testing.T) (*httptest.Server, *websocket.Conn) { upgrader.CheckOrigin = func(r *http.Request) bool { return true } ws, err := upgrader.Upgrade(w, r, nil) if err != nil { - fmt.Println("upgrade:", err) + utils.Log.Error("upgrade error: %v", err) return } defer ws.Close() diff --git a/handlers/channel.go b/handlers/channel.go index b969d2a42..ec6f12c42 100644 --- a/handlers/channel.go +++ b/handlers/channel.go @@ -2,7 +2,6 @@ package handlers import ( "encoding/json" - "fmt" "io" "net/http" "strconv" @@ -10,6 +9,7 @@ import ( "github.com/go-chi/chi" "github.com/stakwork/sphinx-tribes/auth" "github.com/stakwork/sphinx-tribes/db" + "github.com/stakwork/sphinx-tribes/utils" ) type channelHandler struct { @@ -29,13 +29,13 @@ func (ch *channelHandler) DeleteChannel(w http.ResponseWriter, r *http.Request) idString := chi.URLParam(r, "id") id, err := strconv.Atoi(idString) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusUnauthorized) return } if id == 0 { - fmt.Println("id is 0") + utils.Log.Info("id is 0") w.WriteHeader(http.StatusUnauthorized) return } @@ -43,12 +43,12 @@ func (ch *channelHandler) DeleteChannel(w http.ResponseWriter, r *http.Request) existing := ch.db.GetChannel(uint(id)) existingTribe := ch.db.GetTribe(existing.TribeUUID) if existing.ID == 0 { - fmt.Println("existing id is 0") + utils.Log.Info("existing id is 0") w.WriteHeader(http.StatusUnauthorized) return } if existingTribe.OwnerPubKey != pubKeyFromAuth { - fmt.Println("keys dont match") + utils.Log.Info("keys dont match") w.WriteHeader(http.StatusUnauthorized) return } @@ -70,7 +70,7 @@ func (ch *channelHandler) CreateChannel(w http.ResponseWriter, r *http.Request) r.Body.Close() err = json.Unmarshal(body, &channel) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -78,7 +78,7 @@ func (ch *channelHandler) CreateChannel(w http.ResponseWriter, r *http.Request) //check that the tribe has the same pubKeyFromAuth tribe := ch.db.GetTribe(channel.TribeUUID) if tribe.OwnerPubKey != pubKeyFromAuth { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusUnauthorized) return } @@ -86,7 +86,7 @@ func (ch *channelHandler) CreateChannel(w http.ResponseWriter, r *http.Request) tribeChannels := ch.db.GetChannelsByTribe(channel.TribeUUID) for _, tribeChannel := range tribeChannels { if tribeChannel.Name == channel.Name { - fmt.Println("Channel name already in use") + utils.Log.Info("Channel name already in use") w.WriteHeader(http.StatusNotAcceptable) return @@ -95,7 +95,7 @@ func (ch *channelHandler) CreateChannel(w http.ResponseWriter, r *http.Request) channel, err = ch.db.CreateChannel(channel) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusNotAcceptable) return } diff --git a/handlers/features.go b/handlers/features.go index ba44507fa..9e2dc2016 100644 --- a/handlers/features.go +++ b/handlers/features.go @@ -15,6 +15,7 @@ import ( "github.com/rs/xid" "github.com/stakwork/sphinx-tribes/auth" "github.com/stakwork/sphinx-tribes/db" + "github.com/stakwork/sphinx-tribes/utils" ) type PostData struct { @@ -57,7 +58,7 @@ func (oh *featureHandler) CreateOrEditFeatures(w http.ResponseWriter, r *http.Re ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -68,7 +69,7 @@ func (oh *featureHandler) CreateOrEditFeatures(w http.ResponseWriter, r *http.Re err := json.Unmarshal(body, &features) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -112,7 +113,7 @@ func (oh *featureHandler) DeleteFeature(w http.ResponseWriter, r *http.Request) ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -134,7 +135,7 @@ func (oh *featureHandler) GetFeaturesByWorkspaceUuid(w http.ResponseWriter, r *h ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -150,7 +151,7 @@ func (oh *featureHandler) GetWorkspaceFeaturesCount(w http.ResponseWriter, r *ht ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -166,7 +167,7 @@ func (oh *featureHandler) GetFeatureByUuid(w http.ResponseWriter, r *http.Reques ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -240,7 +241,7 @@ func (oh *featureHandler) CreateOrEditFeaturePhase(w http.ResponseWriter, r *htt ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -289,7 +290,7 @@ func (oh *featureHandler) GetFeaturePhases(w http.ResponseWriter, r *http.Reques ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -305,7 +306,7 @@ func (oh *featureHandler) GetFeaturePhaseByUUID(w http.ResponseWriter, r *http.R ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -327,7 +328,7 @@ func (oh *featureHandler) DeleteFeaturePhase(w http.ResponseWriter, r *http.Requ ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -350,7 +351,7 @@ func (oh *featureHandler) CreateOrEditStory(w http.ResponseWriter, r *http.Reque ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -391,7 +392,7 @@ func (oh *featureHandler) GetStoriesByFeatureUuid(w http.ResponseWriter, r *http ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -414,7 +415,7 @@ func (oh *featureHandler) GetStoryByUuid(w http.ResponseWriter, r *http.Request) ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -432,7 +433,7 @@ func (oh *featureHandler) DeleteStory(w http.ResponseWriter, r *http.Request) { ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -458,7 +459,7 @@ func (oh *featureHandler) GetBountiesByFeatureAndPhaseUuid(w http.ResponseWriter ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -482,7 +483,7 @@ func (oh *featureHandler) GetBountiesCountByFeatureAndPhaseUuid(w http.ResponseW ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -555,7 +556,7 @@ func (oh *featureHandler) StoriesSend(w http.ResponseWriter, r *http.Request) { var postData PostData err = json.Unmarshal(body, &postData) if err != nil { - fmt.Println("[StoriesSend] JSON Unmarshal error:", err) + utils.Log.Error("[StoriesSend] JSON Unmarshal error: %v", err) http.Error(w, "Invalid JSON format", http.StatusNotAcceptable) return } @@ -614,7 +615,7 @@ func (oh *featureHandler) BriefSend(w http.ResponseWriter, r *http.Request) { ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -629,7 +630,7 @@ func (oh *featureHandler) BriefSend(w http.ResponseWriter, r *http.Request) { var postData AudioBriefPostData err = json.Unmarshal(body, &postData) if err != nil { - fmt.Println("[BriefSend] JSON Unmarshal error:", err) + utils.Log.Error("[BriefSend] JSON Unmarshal error: %v", err) http.Error(w, "Invalid JSON format", http.StatusNotAcceptable) return } diff --git a/handlers/feed.go b/handlers/feed.go index 253d7c5ba..9695f9214 100644 --- a/handlers/feed.go +++ b/handlers/feed.go @@ -13,6 +13,7 @@ import ( "github.com/stakwork/sphinx-tribes/db" "github.com/stakwork/sphinx-tribes/feeds" + "github.com/stakwork/sphinx-tribes/utils" "google.golang.org/api/option" "google.golang.org/api/youtube/v3" ) @@ -58,7 +59,7 @@ func DownloadYoutubeFeed(w http.ResponseWriter, r *http.Request) { r.Body.Close() err = json.Unmarshal(body, &youtube_download) if err != nil { - fmt.Println("[feed] ", err) + utils.Log.Error("[feed] %v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -94,7 +95,7 @@ func DownloadYoutubeFeed(w http.ResponseWriter, r *http.Request) { func processYoutubeDownload(data []string) { stakworkKey := fmt.Sprintf("Token token=%s", os.Getenv("STAKWORK_KEY")) if stakworkKey == "" { - fmt.Println("[feed] Youtube Download Error: Stakwork key not found") + utils.Log.Error("[feed] Youtube Download Error: Stakwork key not found") } else { type Vars struct { YoutubeContent []string `json:"youtube_content"` @@ -128,7 +129,7 @@ func processYoutubeDownload(data []string) { buf, err := json.Marshal(body) if err != nil { - fmt.Println("[feed] Youtube error: Unable to parse message into byte buffer", err) + utils.Log.Error("[feed] Youtube error: Unable to parse message into byte buffer: %v", err) return } @@ -140,14 +141,14 @@ func processYoutubeDownload(data []string) { client := &http.Client{} response, err := client.Do(request) if err != nil { - fmt.Println("[feed] Youtube Download Request Error ===", err) + utils.Log.Error("[feed] Youtube Download Request Error: %v", err) } defer response.Body.Close() res, err := io.ReadAll(response.Body) if err != nil { - fmt.Println("[feed] Youtube Download Request Error ==", err) + utils.Log.Error("[feed] Youtube Download Request Error: %v", err) } - fmt.Println("[feed] Youtube Download Succces ==", string(res)) + utils.Log.Info("[feed] Youtube Download Success: %s", string(res)) } } @@ -158,6 +159,7 @@ func GetPodcast(w http.ResponseWriter, r *http.Request) { episodes, err := getEpisodes(url, feedid) if err != nil { + utils.Log.Error("[feed] %v", err) w.WriteHeader(http.StatusNotFound) return } @@ -166,7 +168,7 @@ func GetPodcast(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) err = json.NewEncoder(w).Encode(podcast) if err != nil { - fmt.Println("[feed]", err) + utils.Log.Error("[feed] %v", err) } } @@ -266,7 +268,7 @@ func getFeed(feedURL string, feedID string) (*feeds.Podcast, error) { resp, err := client.Do(req) if err != nil { - fmt.Println("[feed] GET error:", err) + utils.Log.Error("[feed] GET error: %v", err) return nil, err } defer resp.Body.Close() @@ -275,7 +277,7 @@ func getFeed(feedURL string, feedID string) (*feeds.Podcast, error) { body, err := io.ReadAll(resp.Body) err = json.Unmarshal(body, &r) if err != nil { - fmt.Println("[feed] json unmarshall error", err) + utils.Log.Error("[feed] json unmarshall error: %v", err) return nil, err } @@ -308,7 +310,7 @@ func getEpisodes(feedURL string, feedID string) ([]feeds.Episode, error) { resp, err := client.Do(req) if err != nil { - fmt.Println("[feed] GET error:", err) + utils.Log.Error("[feed] GET error: %v", err) return nil, err } defer resp.Body.Close() @@ -317,7 +319,7 @@ func getEpisodes(feedURL string, feedID string) ([]feeds.Episode, error) { body, err := io.ReadAll(resp.Body) err = json.Unmarshal(body, &r) if err != nil { - fmt.Println("[feed] json unmarshall error", err) + utils.Log.Error("[feed] json unmarshall error: %v", err) return nil, err } @@ -342,7 +344,7 @@ func searchPodcastIndex(term string) ([]feeds.Podcast, error) { resp, err := client.Do(req) if err != nil { - fmt.Println("[feed] GET error:", err) + utils.Log.Error("[feed] GET error: %v", err) return nil, err } defer resp.Body.Close() @@ -351,7 +353,7 @@ func searchPodcastIndex(term string) ([]feeds.Podcast, error) { body, err := io.ReadAll(resp.Body) err = json.Unmarshal(body, &r) if err != nil { - fmt.Println("[feed] json unmarshall error", err) + utils.Log.Error("[feed] json unmarshall error: %v", err) return nil, err } diff --git a/handlers/github.go b/handlers/github.go index 7af5a69bf..2907a946e 100644 --- a/handlers/github.go +++ b/handlers/github.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "errors" - "fmt" "net/http" "os" "strconv" @@ -14,6 +13,7 @@ import ( "github.com/google/go-github/v39/github" "github.com/stakwork/sphinx-tribes/auth" "github.com/stakwork/sphinx-tribes/db" + "github.com/stakwork/sphinx-tribes/utils" "golang.org/x/oauth2" ) @@ -28,7 +28,7 @@ func GetGithubIssue(w http.ResponseWriter, r *http.Request) { } issue, err := GetIssue(owner, repo, issueNum) if err != nil { - fmt.Println("Github error: ", err.Error()) + utils.Log.Error("Github error: %v", err) w.WriteHeader(http.StatusNotFound) return } diff --git a/handlers/meme.go b/handlers/meme.go index 2ae6294c6..8265c17cb 100644 --- a/handlers/meme.go +++ b/handlers/meme.go @@ -16,6 +16,7 @@ import ( "github.com/stakwork/sphinx-tribes/auth" "github.com/stakwork/sphinx-tribes/config" "github.com/stakwork/sphinx-tribes/db" + "github.com/stakwork/sphinx-tribes/utils" ) func MemeImageUpload(w http.ResponseWriter, r *http.Request) { @@ -23,7 +24,7 @@ func MemeImageUpload(w http.ResponseWriter, r *http.Request) { pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -61,7 +62,7 @@ func MemeImageUpload(w http.ResponseWriter, r *http.Request) { if mErr != "" { msg := "Could not get meme token" - fmt.Println(msg, mErr) + utils.Log.Error("%s: %s", msg, mErr) w.WriteHeader(http.StatusNoContent) json.NewEncoder(w).Encode(msg) } else { @@ -73,7 +74,7 @@ func MemeImageUpload(w http.ResponseWriter, r *http.Request) { } msg := "Could not get meme image" - fmt.Println(msg) + utils.Log.Error("%s", msg) w.WriteHeader(http.StatusNoContent) json.NewEncoder(w).Encode(msg) } @@ -204,7 +205,7 @@ func UploadMemeImage(file multipart.File, token string, fileName string) (error, DeleteFileFromUploadsFolder(filePath) if err != nil { - fmt.Println("meme request Error ===", err) + utils.Log.Error("meme request Error: %v", err) return err, "" } @@ -234,7 +235,7 @@ func DeleteFileFromUploadsFolder(filePath string) { func CreateUploadsDirectory(dirName string) { if _, err := os.Open(dirName); os.IsNotExist(err) { - fmt.Println("The directory named", dirName, "does not exist") + utils.Log.Info("The directory named %s does not exist", dirName) os.Mkdir(dirName, 0755) } } diff --git a/handlers/metrics.go b/handlers/metrics.go index 296fc1131..62f82cca7 100644 --- a/handlers/metrics.go +++ b/handlers/metrics.go @@ -19,6 +19,7 @@ import ( "github.com/stakwork/sphinx-tribes/auth" "github.com/stakwork/sphinx-tribes/config" "github.com/stakwork/sphinx-tribes/db" + "github.com/stakwork/sphinx-tribes/utils" "github.com/tuan78/jsonconv" ) @@ -37,7 +38,7 @@ func PaymentMetrics(w http.ResponseWriter, r *http.Request) { workspace := keys.Get("workspace") if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -64,7 +65,7 @@ func WorkspacetMetrics(w http.ResponseWriter, r *http.Request) { pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -91,7 +92,7 @@ func PeopleMetrics(w http.ResponseWriter, r *http.Request) { pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -127,7 +128,7 @@ func (mh *metricHandler) BountyMetrics(w http.ResponseWriter, r *http.Request) { workspace := keys.Get("workspace") if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -163,7 +164,7 @@ func (mh *metricHandler) BountyMetrics(w http.ResponseWriter, r *http.Request) { return } } else { - fmt.Println("Redis client is not initialized or there is an error with Redis") + utils.Log.Info("Redis client is not initialized or there is an error with Redis") } totalBountiesPosted := mh.db.TotalBountiesPosted(request, workspace) @@ -200,7 +201,7 @@ func (mh *metricHandler) BountyMetrics(w http.ResponseWriter, r *http.Request) { metricsMap := structs.Map(bountyMetrics) db.SetMap(metricsKey, metricsMap) } else { - fmt.Println("Redis client is not initialized or there is an error with Redis") + utils.Log.Info("Redis client is not initialized or there is an error with Redis") } w.WriteHeader(http.StatusOK) @@ -212,7 +213,7 @@ func (mh *metricHandler) MetricsBounties(w http.ResponseWriter, r *http.Request) pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -240,7 +241,7 @@ func (mh *metricHandler) MetricsBountiesCount(w http.ResponseWriter, r *http.Req pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -266,7 +267,7 @@ func (mh *metricHandler) MetricsBountiesProviders(w http.ResponseWriter, r *http pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -292,7 +293,7 @@ func MetricsCsv(w http.ResponseWriter, r *http.Request) { pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -318,7 +319,7 @@ func MetricsCsv(w http.ResponseWriter, r *http.Request) { err, url := UploadMetricsCsv(result, request) if err != nil { - fmt.Println("Error uploading csv ===", err) + utils.Log.Error("Error uploading csv: %v", err) } w.WriteHeader(http.StatusOK) @@ -333,7 +334,7 @@ func GetAdminWorkspaces(w http.ResponseWriter, r *http.Request) { pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -457,19 +458,19 @@ func UploadMetricsCsv(data [][]string, request db.PaymentDateRange) (error, stri err, postPresignedUrl := createPresignedUrl(path) if err != nil { - fmt.Println("Presigned Error", err) + utils.Log.Error("Presigned Error: %v", err) } r, err := http.NewRequest(http.MethodPut, postPresignedUrl, bytes.NewReader(fileBuffer)) if err != nil { - fmt.Println("Posting presign s3 error:", err) + utils.Log.Error("Posting presign s3 error: %v", err) } r.Header.Set("Content-Type", "multipart/form-data") client := &http.Client{} _, err = client.Do(r) if err != nil { - fmt.Println("Error occured while posting presigned URL", err) + utils.Log.Error("Error occurred while posting presigned URL: %v", err) } // Delete image from uploads folder diff --git a/handlers/people.go b/handlers/people.go index ffb3dd385..4fc209ad0 100644 --- a/handlers/people.go +++ b/handlers/people.go @@ -158,7 +158,7 @@ func (ph *peopleHandler) UpdatePerson(w http.ResponseWriter, r *http.Request) { } else { if person.OwnerPubKey != existing.OwnerPubKey && person.OwnerAlias != existing.OwnerAlias { // can't edit someone else's - fmt.Println("cant edit someone else") + utils.Log.Info("cant edit someone else") w.WriteHeader(http.StatusUnauthorized) return } @@ -200,7 +200,7 @@ func (ph *peopleHandler) UpsertLogin(w http.ResponseWriter, r *http.Request) { r.Body.Close() err = json.Unmarshal(body, &person) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -213,7 +213,7 @@ func (ph *peopleHandler) UpsertLogin(w http.ResponseWriter, r *http.Request) { if existing.ID == 0 { if person.ID != 0 { // cant try to "edit" if not exists already - fmt.Println("cant edit non existing") + utils.Log.Info("cant edit non existing") w.WriteHeader(http.StatusUnauthorized) return } @@ -223,7 +223,7 @@ func (ph *peopleHandler) UpsertLogin(w http.ResponseWriter, r *http.Request) { } else { // editing! needs ID if person.ID != 0 && person.ID != existing.ID { // can't edit someone else's - fmt.Println("cant edit someone else") + utils.Log.Info("cant edit someone else") w.WriteHeader(http.StatusUnauthorized) return } @@ -255,7 +255,7 @@ func (ph *peopleHandler) UpsertLogin(w http.ResponseWriter, r *http.Request) { tokenString, err := auth.EncodeJwt(person.OwnerPubKey) if err != nil { - fmt.Println("Cannot generate jwt token") + utils.Log.Info("Cannot generate jwt token") } responseData["jwt"] = tokenString @@ -285,41 +285,41 @@ func DeleteTicketByAdmin(w http.ResponseWriter, r *http.Request) { createdStr := chi.URLParam(r, "created") created, err := strconv.ParseInt(createdStr, 10, 64) if err != nil { - fmt.Println("Unable to convert created to int64") + utils.Log.Info("Unable to convert created to int64") w.WriteHeader(http.StatusInternalServerError) return } if created == 0 || pubKey == "" { - fmt.Println("Insufficient details to delete ticket") + utils.Log.Info("Insufficient details to delete ticket") w.WriteHeader(http.StatusBadRequest) return } if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } existing := db.DB.GetPersonByPubkey(pubKeyFromAuth) if existing.ID == 0 { - fmt.Println("Could not fetch admin details from db") + utils.Log.Info("Could not fetch admin details from db") w.WriteHeader(http.StatusUnauthorized) return } else if PersonIsAdmin(existing.OwnerPubKey) == false { - fmt.Println("Only admin is allowed to delete tickets") + utils.Log.Info("Only admin is allowed to delete tickets") w.WriteHeader(http.StatusUnauthorized) return } person := db.DB.GetPersonByPubkey(pubKey) if person.ID == 0 { - fmt.Println("Could not fetch person from db") + utils.Log.Info("Could not fetch person from db") w.WriteHeader(http.StatusUnauthorized) return } wanteds, ok := person.Extras["wanted"].([]interface{}) if !ok { - fmt.Println("No tickets found for person") + utils.Log.Info("No tickets found for person") w.WriteHeader(http.StatusBadRequest) return } @@ -341,7 +341,7 @@ func DeleteTicketByAdmin(w http.ResponseWriter, r *http.Request) { } if index == -1 { - fmt.Println("Ticket to delete not found") + utils.Log.Info("Ticket to delete not found") w.WriteHeader(http.StatusBadRequest) return } else { @@ -525,7 +525,7 @@ func (ph *peopleHandler) GetPersonByUuid(w http.ResponseWriter, r *http.Request) personResponse["twitter_confirmed"] = person.TwitterConfirmed personResponse["github_issues"] = person.GithubIssues if err != nil { - fmt.Println("==> error: ", err) + utils.Log.Error("==> error: %v", err) } else { var badgeSlice []uint for i := 0; i < len(assetBalanceData); i++ { @@ -533,7 +533,7 @@ func (ph *peopleHandler) GetPersonByUuid(w http.ResponseWriter, r *http.Request) } personResponse["badges"] = badgeSlice } - fmt.Println() + utils.Log.Info("") // FIXME use http to hit sphinx-element server for badges // Todo: response should include no pubKey // FIXME also filter by the tribe "profile_filters" @@ -546,11 +546,11 @@ func GetPersonAssetsByUuid(w http.ResponseWriter, r *http.Request) { person := db.DB.GetPersonByUuid(uuid) assetList, err := GetAssetList(person.OwnerPubKey) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusServiceUnavailable) return } - fmt.Println() + utils.Log.Info("") w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(assetList) } @@ -569,25 +569,25 @@ func (ph *peopleHandler) DeletePerson(w http.ResponseWriter, r *http.Request) { idString := chi.URLParam(r, "id") id, err := strconv.Atoi(idString) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusUnauthorized) return } if id == 0 { - fmt.Println("id is 0") + utils.Log.Info("id is 0") w.WriteHeader(http.StatusUnauthorized) return } existing := ph.db.GetPerson(uint(id)) if existing.ID == 0 { - fmt.Println("existing id is 0") + utils.Log.Info("existing id is 0") w.WriteHeader(http.StatusUnauthorized) return } if existing.OwnerPubKey != pubKeyFromAuth { - fmt.Println("keys dont match") + utils.Log.Info("keys dont match") w.WriteHeader(http.StatusUnauthorized) return } @@ -619,7 +619,7 @@ func GetAssetByPubkey(pubkey string) ([]db.AssetBalanceData, error) { resp, err := client.Do(req) if err != nil { - fmt.Println("GET error:", err) + utils.Log.Error("GET error: %v", err) return nil, err } defer resp.Body.Close() @@ -628,7 +628,7 @@ func GetAssetByPubkey(pubkey string) ([]db.AssetBalanceData, error) { body, err := io.ReadAll(resp.Body) err = json.Unmarshal(body, &r) if err != nil { - fmt.Println("json unmarshall error", err) + utils.Log.Error("json unmarshall error: %v", err) return nil, err } @@ -652,7 +652,7 @@ func GetAssetList(pubkey string) ([]db.AssetListData, error) { resp, err := client.Do(req) if err != nil { - fmt.Println("GET error:", err) + utils.Log.Error("GET error: %v", err) return nil, err } defer resp.Body.Close() @@ -662,7 +662,7 @@ func GetAssetList(pubkey string) ([]db.AssetListData, error) { err = json.Unmarshal(body, &r) if err != nil { - fmt.Println("json unmarshall error", err) + utils.Log.Error("json unmarshall error: %v", err) return nil, err } @@ -678,44 +678,44 @@ func AddOrRemoveBadge(w http.ResponseWriter, r *http.Request) { r.Body.Close() err = json.Unmarshal(body, &badgeCreationData) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusNotAcceptable) return } if badgeCreationData.Badge == "" { - fmt.Println("Badge cannot be Empty") + utils.Log.Info("Badge cannot be Empty") w.WriteHeader(http.StatusBadRequest) return } if badgeCreationData.Action == "" { - fmt.Println("Action cannot be Empty") + utils.Log.Info("Action cannot be Empty") w.WriteHeader(http.StatusBadRequest) return } if !(badgeCreationData.Action == "add" || badgeCreationData.Action == "remove") { - fmt.Println("Invalid action in Request") + utils.Log.Info("Invalid action in Request") w.WriteHeader(http.StatusBadRequest) return } if badgeCreationData.TribeUUID == "" { - fmt.Println("tribeId cannot be Empty") - w.WriteHeader(http.StatusBadRequest) - return + utils.Log.Info("tribeId cannot be Empty") + w.WriteHeader(http.StatusBadRequest) + return } extractedPubkey, err := auth.VerifyTribeUUID(badgeCreationData.TribeUUID, false) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusUnauthorized) return } if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusBadRequest) return } @@ -723,8 +723,8 @@ func AddOrRemoveBadge(w http.ResponseWriter, r *http.Request) { tribe := db.DB.GetTribeByIdAndPubkey(badgeCreationData.TribeUUID, extractedPubkey) if pubKeyFromAuth != tribe.OwnerPubKey { - fmt.Println(pubKeyFromAuth) - fmt.Println("mismatched pubkey") + utils.Log.Info("%s", pubKeyFromAuth) + utils.Log.Info("mismatched pubkey") w.WriteHeader(http.StatusUnauthorized) return } diff --git a/handlers/ticket.go b/handlers/ticket.go index 5e2de19b5..d8a705ed8 100644 --- a/handlers/ticket.go +++ b/handlers/ticket.go @@ -81,7 +81,7 @@ func (th *ticketHandler) UpdateTicket(w http.ResponseWriter, r *http.Request) { pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("[ticket] no pubkey from auth") + utils.Log.Info("[ticket] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) json.NewEncoder(w).Encode(map[string]string{"error": "Unauthorized"}) return @@ -206,7 +206,7 @@ func (th *ticketHandler) DeleteTicket(w http.ResponseWriter, r *http.Request) { pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("[ticket] no pubkey from auth") + utils.Log.Info("[ticket] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) json.NewEncoder(w).Encode(map[string]string{"error": "Unauthorized"}) return @@ -240,7 +240,7 @@ func (th *ticketHandler) PostTicketDataToStakwork(w http.ResponseWriter, r *http pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("[ticket] no pubkey from auth") + utils.Log.Info("[ticket] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) json.NewEncoder(w).Encode(map[string]string{"error": "Unauthorized"}) return @@ -624,7 +624,7 @@ func (th *ticketHandler) GetTicketsByPhaseUUID(w http.ResponseWriter, r *http.Re ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } diff --git a/handlers/tribes.go b/handlers/tribes.go index 336c33471..e3344e303 100644 --- a/handlers/tribes.go +++ b/handlers/tribes.go @@ -91,7 +91,7 @@ func PutTribeStats(w http.ResponseWriter, r *http.Request) { r.Body.Close() err = json.Unmarshal(body, &tribe) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -103,7 +103,7 @@ func PutTribeStats(w http.ResponseWriter, r *http.Request) { extractedPubkey, err := auth.VerifyTribeUUID(tribe.UUID, false) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusUnauthorized) return } @@ -139,7 +139,7 @@ func (th *tribeHandler) DeleteTribe(w http.ResponseWriter, r *http.Request) { extractedPubkey, err := th.verifyTribeUUID(uuid, false) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusUnauthorized) return } @@ -214,13 +214,13 @@ func (th *tribeHandler) CreateOrEditTribe(w http.ResponseWriter, r *http.Request r.Body.Close() err = json.Unmarshal(body, &tribe) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusNotAcceptable) return } if tribe.UUID == "" { - fmt.Println("createOrEditTribe no uuid") + utils.Log.Info("createOrEditTribe no uuid") w.WriteHeader(http.StatusUnauthorized) return } @@ -229,7 +229,7 @@ func (th *tribeHandler) CreateOrEditTribe(w http.ResponseWriter, r *http.Request extractedPubkey, err := th.verifyTribeUUID(tribe.UUID, false) if err != nil { - fmt.Println("extract UUID error", err) + utils.Log.Error("extract UUID error: %v", err) w.WriteHeader(http.StatusUnauthorized) return } @@ -238,7 +238,7 @@ func (th *tribeHandler) CreateOrEditTribe(w http.ResponseWriter, r *http.Request tribe.Created = &now } else { // IF PUBKEY IN CONTEXT, MUST AUTH! if pubKeyFromAuth != extractedPubkey { - fmt.Println("createOrEditTribe pubkeys dont match") + utils.Log.Info("createOrEditTribe pubkeys dont match") w.WriteHeader(http.StatusUnauthorized) return } @@ -249,9 +249,9 @@ func (th *tribeHandler) CreateOrEditTribe(w http.ResponseWriter, r *http.Request tribe.UniqueName, _ = th.tribeUniqueNameFromName(tribe.Name) } else { // already exists! make sure it's owned if existing.OwnerPubKey != extractedPubkey { - fmt.Println("createOrEditTribe tribe.ownerPubKey not match") - fmt.Println(existing.OwnerPubKey) - fmt.Println(extractedPubkey) + utils.Log.Info("createOrEditTribe tribe.ownerPubKey not match") + utils.Log.Info("existing owner: %s", existing.OwnerPubKey) + utils.Log.Info("extracted pubkey: %s", extractedPubkey) w.WriteHeader(http.StatusUnauthorized) return } @@ -263,7 +263,7 @@ func (th *tribeHandler) CreateOrEditTribe(w http.ResponseWriter, r *http.Request _, err = th.db.CreateOrEditTribe(tribe) if err != nil { - fmt.Println("=> ERR createOrEditTribe", err) + utils.Log.Error("=> ERR createOrEditTribe: %v", err) w.WriteHeader(http.StatusBadRequest) return } @@ -284,7 +284,7 @@ func PutTribeActivity(w http.ResponseWriter, r *http.Request) { extractedPubkey, err := auth.VerifyTribeUUID(uuid, false) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusUnauthorized) return } @@ -316,7 +316,7 @@ func (th *tribeHandler) SetTribePreview(w http.ResponseWriter, r *http.Request) extractedPubkey, err := th.verifyTribeUUID(uuid, false) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusUnauthorized) return } @@ -350,7 +350,7 @@ func CreateLeaderBoard(w http.ResponseWriter, r *http.Request) { extractedPubkey, err := auth.VerifyTribeUUID(uuid, false) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusUnauthorized) return } @@ -365,7 +365,7 @@ func CreateLeaderBoard(w http.ResponseWriter, r *http.Request) { r.Body.Close() err = json.Unmarshal(body, &leaderBoard) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -373,7 +373,7 @@ func CreateLeaderBoard(w http.ResponseWriter, r *http.Request) { _, err = db.DB.CreateLeaderBoard(uuid, leaderBoard) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -421,7 +421,7 @@ func UpdateLeaderBoard(w http.ResponseWriter, r *http.Request) { extractedPubkey, err := auth.VerifyTribeUUID(uuid, false) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusUnauthorized) return } @@ -438,7 +438,7 @@ func UpdateLeaderBoard(w http.ResponseWriter, r *http.Request) { r.Body.Close() err = json.Unmarshal(body, &leaderBoard) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -469,7 +469,7 @@ func GenerateInvoice(w http.ResponseWriter, r *http.Request) { r.Body.Close() if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -477,7 +477,7 @@ func GenerateInvoice(w http.ResponseWriter, r *http.Request) { err = json.Unmarshal(body, &invoice) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -570,7 +570,7 @@ func (th *tribeHandler) GenerateV1BudgetInvoice(w http.ResponseWriter, r *http.R r.Body.Close() if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -578,7 +578,7 @@ func (th *tribeHandler) GenerateV1BudgetInvoice(w http.ResponseWriter, r *http.R err = json.Unmarshal(body, &invoice) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -662,7 +662,7 @@ func (th *tribeHandler) GenerateV2BudgetInvoice(w http.ResponseWriter, r *http.R r.Body.Close() if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -670,7 +670,7 @@ func (th *tribeHandler) GenerateV2BudgetInvoice(w http.ResponseWriter, r *http.R err = json.Unmarshal(body, &invoice) if err != nil { - fmt.Println(err) + utils.Log.Error("%v", err) w.WriteHeader(http.StatusNotAcceptable) return } diff --git a/handlers/workspaces.go b/handlers/workspaces.go index dedb3fc3c..2bb224af5 100644 --- a/handlers/workspaces.go +++ b/handlers/workspaces.go @@ -46,7 +46,7 @@ func (oh *workspaceHandler) CreateOrEditWorkspace(w http.ResponseWriter, r *http ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("[workspaces] no pubkey from auth") + utils.Log.Info("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -58,7 +58,7 @@ func (oh *workspaceHandler) CreateOrEditWorkspace(w http.ResponseWriter, r *http err := json.Unmarshal(body, &workspace) if err != nil { - fmt.Println("[workspaces] ", err) + utils.Log.Error("[workspaces] %v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -66,14 +66,14 @@ func (oh *workspaceHandler) CreateOrEditWorkspace(w http.ResponseWriter, r *http workspace.Name = strings.TrimSpace(workspace.Name) if len(workspace.Name) == 0 || len(workspace.Name) > 20 { - fmt.Printf("[workspaces] invalid workspace name %s\n", workspace.Name) + utils.Log.Info("[workspaces] invalid workspace name %s", workspace.Name) w.WriteHeader(http.StatusBadRequest) json.NewEncoder(w).Encode("Error: workspace name must be present and should not exceed 20 character") return } if len(workspace.Description) > 120 { - fmt.Printf("[workspaces] invalid workspace name %s\n", workspace.Description) + utils.Log.Info("[workspaces] invalid workspace name %s", workspace.Description) w.WriteHeader(http.StatusBadRequest) json.NewEncoder(w).Encode("Error: workspace description should not exceed 120 character") return @@ -82,9 +82,9 @@ func (oh *workspaceHandler) CreateOrEditWorkspace(w http.ResponseWriter, r *http if pubKeyFromAuth != workspace.OwnerPubKey { hasRole := db.UserHasAccess(pubKeyFromAuth, workspace.Uuid, db.EditOrg) if !hasRole { - fmt.Println("[workspaces] mismatched pubkey") - fmt.Println("[workspaces] Auth pubkey:", pubKeyFromAuth) - fmt.Println("[workspaces] OwnerPubKey:", workspace.OwnerPubKey) + utils.Log.Info("[workspaces] mismatched pubkey") + utils.Log.Info("[workspaces] Auth pubkey: %s", pubKeyFromAuth) + utils.Log.Info("[workspaces] OwnerPubKey: %s", workspace.OwnerPubKey) w.WriteHeader(http.StatusUnauthorized) json.NewEncoder(w).Encode("Don't have access to Edit workspace") return @@ -96,7 +96,7 @@ func (oh *workspaceHandler) CreateOrEditWorkspace(w http.ResponseWriter, r *http if err != nil { w.WriteHeader(http.StatusBadRequest) msg := fmt.Sprintf("Error: did not pass validation test : %s", err) - json.NewEncoder(w).Encode(msg) + json.NewEncoder(w).Encode(msg) return } @@ -110,7 +110,7 @@ func (oh *workspaceHandler) CreateOrEditWorkspace(w http.ResponseWriter, r *http existing := oh.db.GetWorkspaceByUuid(workspace.Uuid) if existing.ID == 0 { // new! if workspace.ID != 0 { // can't try to "edit" if it does not exist already - fmt.Println("[workspaces] cant edit non existing") + utils.Log.Info("[workspaces] cant edit non existing") w.WriteHeader(http.StatusUnauthorized) return } @@ -177,7 +177,7 @@ func (oh *workspaceHandler) CreateWorkspaceUser(w http.ResponseWriter, r *http.R r.Body.Close() if err != nil { - fmt.Println("[body] ", err) + utils.Log.Error("[body] %v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -192,13 +192,13 @@ func (oh *workspaceHandler) CreateWorkspaceUser(w http.ResponseWriter, r *http.R workspace := oh.db.GetWorkspaceByUuid(workspaceUser.WorkspaceUuid) if err != nil { - fmt.Println("[workspaces] ", err) + utils.Log.Error("[workspaces] %v", err) w.WriteHeader(http.StatusNotAcceptable) return } if pubKeyFromAuth == "" { - fmt.Println("[workspaces] no pubkey from auth") + utils.Log.Info("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -264,7 +264,7 @@ func GetWorkspaceUser(w http.ResponseWriter, r *http.Request) { pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("[workspaces] no pubkey from auth") + utils.Log.Info("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -293,7 +293,7 @@ func DeleteWorkspaceUser(w http.ResponseWriter, r *http.Request) { r.Body.Close() if err != nil { - fmt.Println("[body] ", err) + utils.Log.Error("[body] %v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -305,13 +305,13 @@ func DeleteWorkspaceUser(w http.ResponseWriter, r *http.Request) { } if err != nil { - fmt.Println("[workspaces]", err) + utils.Log.Error("[workspaces] %v", err) w.WriteHeader(http.StatusNotAcceptable) return } if pubKeyFromAuth == "" { - fmt.Println("[workspaces] no pubkey from auth") + utils.Log.Info("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -362,7 +362,7 @@ func (oh *workspaceHandler) AddUserRoles(w http.ResponseWriter, r *http.Request) r.Body.Close() if err != nil { - fmt.Println("[body] ", err) + utils.Log.Error("[body] %v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -370,14 +370,14 @@ func (oh *workspaceHandler) AddUserRoles(w http.ResponseWriter, r *http.Request) err = json.Unmarshal(body, &roles) if err != nil { - fmt.Println("[workspaces]:", err) + utils.Log.Error("[workspaces]: %v", err) w.WriteHeader(http.StatusNotAcceptable) return } if pubKeyFromAuth == "" { w.WriteHeader(http.StatusUnauthorized) - json.NewEncoder(w).Encode("no pubkey from auth") + json.NewEncoder(w).Encode("no pubkey from auth") return } @@ -465,7 +465,7 @@ func GetUserWorkspaces(w http.ResponseWriter, r *http.Request) { userId, _ := utils.ConvertStringToUint(userIdParam) if userId == 0 { - fmt.Println("[workspaces] provide user id") + utils.Log.Info("[workspaces] provide user id") w.WriteHeader(http.StatusNotAcceptable) return } @@ -483,7 +483,7 @@ func (oh *workspaceHandler) GetUserDropdownWorkspaces(w http.ResponseWriter, r * userId, _ := utils.ConvertStringToUint(userIdParam) if userId == 0 { - fmt.Println("[workspaces] provide user id") + utils.Log.Info("[workspaces] provide user id") w.WriteHeader(http.StatusNotAcceptable) return } @@ -582,7 +582,7 @@ func (oh *workspaceHandler) GetWorkspaceBudget(w http.ResponseWriter, r *http.Re uuid := chi.URLParam(r, "uuid") if pubKeyFromAuth == "" { - fmt.Println("[workspaces] no pubkey from auth") + utils.Log.Info("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -628,7 +628,7 @@ func GetPaymentHistory(w http.ResponseWriter, r *http.Request) { uuid := chi.URLParam(r, "uuid") if pubKeyFromAuth == "" { - fmt.Println("[workspaces] no pubkey from auth") + utils.Log.Info("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -668,7 +668,7 @@ func UpdateWorkspacePendingPayments(w http.ResponseWriter, r *http.Request) { workspace_uuid := chi.URLParam(r, "workspace_uuid") if pubKeyFromAuth == "" { - fmt.Println("no pubkey from auth") + utils.Log.Info("no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -722,7 +722,7 @@ func (oh *workspaceHandler) PollBudgetInvoices(w http.ResponseWriter, r *http.Re uuid := chi.URLParam(r, "uuid") if pubKeyFromAuth == "" { - fmt.Println("[workspaces] no pubkey from auth") + utils.Log.Info("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -760,7 +760,7 @@ func (oh *workspaceHandler) PollUserWorkspacesBudget(w http.ResponseWriter, r *h pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("[workspaces] no pubkey from auth") + utils.Log.Info("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -807,7 +807,7 @@ func GetInvoicesCount(w http.ResponseWriter, r *http.Request) { uuid := chi.URLParam(r, "uuid") if pubKeyFromAuth == "" { - fmt.Println("[workspaces] no pubkey from auth") + utils.Log.Info("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -822,7 +822,7 @@ func GetAllUserInvoicesCount(w http.ResponseWriter, r *http.Request) { pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("[workspaces] no pubkey from auth") + utils.Log.Info("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -843,7 +843,7 @@ func (oh *workspaceHandler) DeleteWorkspace(w http.ResponseWriter, r *http.Reque uuid := chi.URLParam(r, "uuid") if pubKeyFromAuth == "" { - fmt.Println("[workspaces] no pubkey from auth") + utils.Log.Info("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -851,7 +851,7 @@ func (oh *workspaceHandler) DeleteWorkspace(w http.ResponseWriter, r *http.Reque workspace := oh.db.GetWorkspaceByUuid(uuid) if pubKeyFromAuth != workspace.OwnerPubKey { msg := "only workspace admin can delete an workspace" - fmt.Println("[workspaces]", msg) + utils.Log.Info("[workspaces] %s", msg) w.WriteHeader(http.StatusUnauthorized) json.NewEncoder(w).Encode(msg) return @@ -860,7 +860,7 @@ func (oh *workspaceHandler) DeleteWorkspace(w http.ResponseWriter, r *http.Reque // Soft delete Workspace and delete user data if err := oh.db.ProcessDeleteWorkspace(uuid); err != nil { msg := "Error removing users from workspace" - fmt.Println(msg, err) + utils.Log.Error("%s: %v", msg, err) w.WriteHeader(http.StatusInternalServerError) json.NewEncoder(w).Encode(msg) return @@ -874,7 +874,7 @@ func (oh *workspaceHandler) UpdateWorkspace(w http.ResponseWriter, r *http.Reque ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("[workspaces] no pubkey from auth") + utils.Log.Info("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -885,7 +885,7 @@ func (oh *workspaceHandler) UpdateWorkspace(w http.ResponseWriter, r *http.Reque err := json.Unmarshal(body, &workspace) if err != nil { - fmt.Println("[workspaces]", err) + utils.Log.Error("[workspaces] %v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -893,9 +893,9 @@ func (oh *workspaceHandler) UpdateWorkspace(w http.ResponseWriter, r *http.Reque if pubKeyFromAuth != workspace.OwnerPubKey { hasRole := db.UserHasAccess(pubKeyFromAuth, workspace.Uuid, db.EditOrg) if !hasRole { - fmt.Println("[workspaces] mismatched pubkey") - fmt.Println("Auth Pubkey:", pubKeyFromAuth) - fmt.Println("OwnerPubKey:", workspace.OwnerPubKey) + utils.Log.Info("[workspaces] mismatched pubkey") + utils.Log.Info("Auth Pubkey: %s", pubKeyFromAuth) + utils.Log.Info("OwnerPubKey: %s", workspace.OwnerPubKey) w.WriteHeader(http.StatusUnauthorized) json.NewEncoder(w).Encode("Don't have access to Edit workspace") return @@ -925,7 +925,7 @@ func (oh *workspaceHandler) CreateOrEditWorkspaceRepository(w http.ResponseWrite ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("[workspaces] no pubkey from auth") + utils.Log.Info("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -936,7 +936,7 @@ func (oh *workspaceHandler) CreateOrEditWorkspaceRepository(w http.ResponseWrite err := json.Unmarshal(body, &workspaceRepo) if err != nil { - fmt.Println("[workspaces]", err) + utils.Log.Error("[workspaces] %v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -985,7 +985,7 @@ func (oh *workspaceHandler) GetWorkspaceRepositorByWorkspaceUuid(w http.Response ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("[workspaces] no pubkey from auth") + utils.Log.Info("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -1001,7 +1001,7 @@ func (oh *workspaceHandler) GetWorkspaceRepoByWorkspaceUuidAndRepoUuid(w http.Re ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("[workspaces] no pubkey from auth") + utils.Log.Info("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -1010,7 +1010,7 @@ func (oh *workspaceHandler) GetWorkspaceRepoByWorkspaceUuidAndRepoUuid(w http.Re uuid := chi.URLParam(r, "uuid") WorkspaceRepository, err := oh.db.GetWorkspaceRepoByWorkspaceUuidAndRepoUuid(workspace_uuid, uuid) if err != nil { - fmt.Println("[workspaces] workspace repository not found:", err) + utils.Log.Error("[workspaces] workspace repository not found: %v", err) w.WriteHeader(http.StatusNotFound) json.NewEncoder(w).Encode(map[string]string{"error": "Repository not found"}) return @@ -1026,7 +1026,7 @@ func (oh *workspaceHandler) DeleteWorkspaceRepository(w http.ResponseWriter, r * pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("[workspaces] no pubkey from auth") + utils.Log.Info("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -1044,7 +1044,7 @@ func (oh *workspaceHandler) GetFeaturesByWorkspaceUuid(w http.ResponseWriter, r ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("[workspaces] no pubkey from auth") + utils.Log.Info("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -1079,7 +1079,7 @@ func (oh *workspaceHandler) GetLastWithdrawal(w http.ResponseWriter, r *http.Req ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("[workspaces] no pubkey from auth") + utils.Log.Info("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -1135,7 +1135,7 @@ func (oh *workspaceHandler) CreateOrEditWorkspaceCodeGraph(w http.ResponseWriter ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("[workspaces] no pubkey from auth") + utils.Log.Info("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -1146,7 +1146,7 @@ func (oh *workspaceHandler) CreateOrEditWorkspaceCodeGraph(w http.ResponseWriter err := json.Unmarshal(body, &codeGraph) if err != nil { - fmt.Println("[workspaces]", err) + utils.Log.Error("[workspaces] %v", err) w.WriteHeader(http.StatusNotAcceptable) return } @@ -1186,7 +1186,7 @@ func (oh *workspaceHandler) GetWorkspaceCodeGraphByUUID(w http.ResponseWriter, r ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("[workspaces] no pubkey from auth") + utils.Log.Info("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -1194,7 +1194,7 @@ func (oh *workspaceHandler) GetWorkspaceCodeGraphByUUID(w http.ResponseWriter, r uuid := chi.URLParam(r, "uuid") codeGraph, err := oh.db.GetCodeGraphByUUID(uuid) if err != nil { - fmt.Println("[workspaces] code graph not found:", err) + utils.Log.Error("[workspaces] code graph not found: %v", err) w.WriteHeader(http.StatusNotFound) json.NewEncoder(w).Encode(map[string]string{"error": "Code graph not found"}) return @@ -1209,7 +1209,7 @@ func (oh *workspaceHandler) GetCodeGraphsByWorkspaceUuid(w http.ResponseWriter, ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("[workspaces] no pubkey from auth") + utils.Log.Info("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return } @@ -1231,7 +1231,7 @@ func (oh *workspaceHandler) DeleteWorkspaceCodeGraph(w http.ResponseWriter, r *h pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) if pubKeyFromAuth == "" { - fmt.Println("[workspaces] no pubkey from auth") + utils.Log.Info("[workspaces] no pubkey from auth") w.WriteHeader(http.StatusUnauthorized) return }