diff --git a/data/context.go b/data/context.go index 90ee917..77eaf09 100644 --- a/data/context.go +++ b/data/context.go @@ -4,6 +4,7 @@ import ( "fmt" "time" + "github.com/rs/zerolog/log" "github.com/spf13/viper" "gorm.io/driver/postgres" "gorm.io/gorm" @@ -39,9 +40,8 @@ type RewardFund struct { Price float64 `gorm:"type:decimal(19,7)" json:"price"` AmountAvailable float64 `gorm:"type:decimal(19,7)" json:"amountAvailable"` MinContribution float64 `gorm:"type:decimal(19,7)" json:"minContribution"` + TelegramLink string `json:"telegramLink"` Contributions []Contribution `json:"contributions"` - Title string `gorm:"type:varchar(50)" json:"title"` - Description string `gorm:"type:text" json:"description"` Bonuses []Bonus `json:"bonuses"` QueueOrder QueueOrder `json:"queueOrder"` } @@ -81,10 +81,10 @@ func InitializeDatabase() { viper.GetString("database.ssl")) Db, err = gorm.Open(postgres.Open(dcs), &gorm.Config{}) if err != nil { - panic("Could not open database") + log.Error().Err(err).Msg("Could not open database") } err = Db.AutoMigrate(User{}, Queue{}, RewardFund{}, QueueOrder{}, Contribution{}, Bonus{}) if err != nil { - panic("Could not migrate database") + log.Error().Err(err).Msg("Could not migrate database") } } diff --git a/endpoints/closerewardfund.go b/endpoints/closerewardfund.go index a6a9e84..5a8da9c 100644 --- a/endpoints/closerewardfund.go +++ b/endpoints/closerewardfund.go @@ -6,6 +6,7 @@ import ( "github.com/imosed/signet/auth" . "github.com/imosed/signet/data" + "github.com/rs/zerolog/log" ) type CloseRewardFundRequest struct { @@ -17,13 +18,15 @@ func CloseRewardFund(w http.ResponseWriter, r *http.Request) { var req CloseRewardFundRequest err := json.NewDecoder(r.Body).Decode(&req) if err != nil { - panic("Could not decode body") + log.Error().Err(err).Msg("Could not decode body in CloseRewardFund call") + return } var claims *auth.Claims claims, err = auth.GetUserClaims(r) if err != nil { - panic("Could not determine if user is authenticated") + log.Error().Err(err).Msg("Could not determine if user is authenticated") + return } var fund RewardFund @@ -38,6 +41,6 @@ func CloseRewardFund(w http.ResponseWriter, r *http.Request) { err = json.NewEncoder(w).Encode(resp) if err != nil { - panic("Could not deliver response") + log.Error().Err(err).Msg("Could not deliver response in CloseRewardFund call") } } diff --git a/endpoints/contribute.go b/endpoints/contribute.go index 4011288..56fb811 100644 --- a/endpoints/contribute.go +++ b/endpoints/contribute.go @@ -7,6 +7,7 @@ import ( "strings" . "github.com/imosed/signet/data" + "github.com/rs/zerolog/log" "github.com/stellar/go/clients/horizonclient" "github.com/stellar/go/keypair" "github.com/stellar/go/network" @@ -24,7 +25,8 @@ func Contribute(resp http.ResponseWriter, req *http.Request) { var cont ContributeRequest err := json.NewDecoder(req.Body).Decode(&cont) if err != nil { - panic("Could not read in contribution") + log.Error().Err(err).Msg("Could not read in contribution") + return } var fund RewardFund @@ -34,7 +36,7 @@ func Contribute(resp http.ResponseWriter, req *http.Request) { if cont.Amount < fund.MinContribution || !strings.HasPrefix(cont.PrivateKey, "S") || !fund.DeletedAt.Time.IsZero() { err = json.NewEncoder(resp).Encode(&SuccessResponse{Success: false}) if err != nil { - panic("Could not deliver unsuccessful contribution response") + log.Error().Err(err).Msg("Could not deliver unsuccessful contribution response") } return } @@ -44,7 +46,8 @@ func Contribute(resp http.ResponseWriter, req *http.Request) { var sourceAcct horizon.Account sourceAcct, err = client.AccountDetail(sourceReq) if err != nil { - panic("Horizon client: could not get account details") + log.Error().Err(err).Msg("Could not get account details from Horizon client") + return } tx, err := txnbuild.NewTransaction( @@ -66,18 +69,21 @@ func Contribute(resp http.ResponseWriter, req *http.Request) { }, }) if err != nil { - panic("Could not create contribution transaction") + log.Error().Err(err).Msg("Could not create contribution transaction") + return } tx, err = tx.Sign(network.TestNetworkPassphrase, source) if err != nil { - panic("Could not sign contribution transaction") + log.Error().Err(err).Msg("Could not sign contribution transaction") + return } var response horizon.Transaction response, err = client.SubmitTransaction(tx) if err != nil { - panic("Could not submit contribution transaction") + log.Error().Err(err).Msg("Could not submit contribution transaction") + return } fmt.Println("Successful Transaction:") @@ -89,6 +95,6 @@ func Contribute(resp http.ResponseWriter, req *http.Request) { err = json.NewEncoder(resp).Encode(&result) if err != nil { - panic("Could not create response for new contribution") + log.Error().Err(err).Msg("Could not create response for new contribution") } } diff --git a/endpoints/contributionstream.go b/endpoints/contributionstream.go index eea4965..14e4aa1 100644 --- a/endpoints/contributionstream.go +++ b/endpoints/contributionstream.go @@ -1,13 +1,13 @@ package endpoints import ( - "fmt" "net/http" "strconv" "strings" "github.com/gorilla/websocket" . "github.com/imosed/signet/data" + "github.com/rs/zerolog/log" "github.com/spf13/viper" "github.com/stellar/go/clients/horizonclient" "github.com/stellar/go/protocols/horizon" @@ -36,7 +36,8 @@ func ContributorStream(resp http.ResponseWriter, req *http.Request) { var err error wsConn, err = upgrader.Upgrade(resp, req, nil) if err != nil { - panic("Could not establish websocket connection") + log.Error().Err(err).Msg("Could not establish websocket connection") + return } } @@ -59,11 +60,13 @@ func InitializeContributionStreams() { tx, err = client.TransactionDetail(payment.GetTransactionHash()) if err != nil { - panic("Could not get transaction from hash") + log.Error().Err(err).Msg("Could not get transaction from hash") + return } amt, err = strconv.ParseFloat(payment.Amount, 64) if err != nil { - panic("Could not convert payment to float") + log.Error().Err(err).Msg("Could not convert payment to float") + return } if tx.Memo == "" { @@ -83,10 +86,10 @@ func InitializeContributionStreams() { if wsConn != nil { err = wsConn.WriteJSON(contribution) if err != nil { - panic("Unable to write json to contribution stream") + log.Error().Err(err).Msg("Unable to write json to contribution stream") } } else { - fmt.Println("No websocket connections") + log.Info().Msg("No websocket connections") } Db.Table("contributions").Create(&contribution) @@ -103,7 +106,7 @@ func InitializeContributionStreams() { cancellations = append(cancellations, cancellation) err = client.StreamOperations(ctx, opReq, contributionUpdateHandler) if err != nil { - panic(err.Error()) + log.Error().Err(err).Msg("Failed to stream contributions from Horizon client") } } } diff --git a/endpoints/createqueue.go b/endpoints/createqueue.go index 7bb78ef..eb4dca7 100644 --- a/endpoints/createqueue.go +++ b/endpoints/createqueue.go @@ -5,6 +5,7 @@ import ( "net/http" . "github.com/imosed/signet/data" + "github.com/rs/zerolog/log" ) type CreateQueueRequest struct { @@ -19,7 +20,8 @@ func CreateQueue(w http.ResponseWriter, r *http.Request) { var req CreateQueueRequest err := json.NewDecoder(r.Body).Decode(&req) if err != nil { - panic("Could not decode body") + log.Error().Err(err).Msg("Could not decode body in CreateQueue call") + return } var specificQueue Queue @@ -41,6 +43,6 @@ func CreateQueue(w http.ResponseWriter, r *http.Request) { err = json.NewEncoder(w).Encode(resp) if err != nil { - panic("Could not deliver response") + log.Error().Err(err).Msg("Could not deliver response in CreateQueue call") } } diff --git a/endpoints/createrewardfund.go b/endpoints/createrewardfund.go index d0897eb..5f09373 100644 --- a/endpoints/createrewardfund.go +++ b/endpoints/createrewardfund.go @@ -8,6 +8,7 @@ import ( "github.com/imosed/signet/auth" . "github.com/imosed/signet/data" + "github.com/rs/zerolog/log" "github.com/stellar/go/clients/horizonclient" "github.com/stellar/go/protocols/horizon" ) @@ -19,8 +20,7 @@ type CreateRewardFundRequest struct { IssuerWallet string `json:"issuerWallet"` Memo string `json:"memo"` MinContribution float64 `gorm:"type:decimal(19,7)" json:"minContribution"` - Title string `gorm:"type:varchar(50)" json:"title"` - Description string `gorm:"type:text" json:"description"` + TelegramLink string `json:"telegramLink"` QueueID uint `json:"queueID"` Bonuses []Bonus `json:"bonuses"` } @@ -34,7 +34,8 @@ func CreateRewardFund(resp http.ResponseWriter, req *http.Request) { dec := json.NewDecoder(req.Body) err := dec.Decode(&fund) if err != nil { - panic("Could not read submitted reward fund") + log.Error().Err(err).Msg("Could not read submitted reward fund") + return } var bonuses []Bonus @@ -48,8 +49,7 @@ func CreateRewardFund(resp http.ResponseWriter, req *http.Request) { Price: 0, AmountAvailable: 0, MinContribution: fund.MinContribution, - Title: fund.Title, - Description: fund.Description, + TelegramLink: fund.TelegramLink, Contributions: nil, } @@ -70,7 +70,8 @@ func CreateRewardFund(resp http.ResponseWriter, req *http.Request) { op, err := client.Offers(offerReq) if err != nil { - panic("Could not get offers") + log.Error().Err(err).Msg("Could not get offers") + return } offers := op.Embedded.Records var price float64 @@ -78,11 +79,13 @@ func CreateRewardFund(resp http.ResponseWriter, req *http.Request) { if len(offers) == 1 { price, err = strconv.ParseFloat(op.Embedded.Records[0].Price, 64) if err != nil { - panic("Could not parse price to float") + log.Error().Err(err).Msg("Could not parse price to float") + return } amt, err = strconv.ParseFloat(op.Embedded.Records[0].Amount, 64) if err != nil { - panic("Could not parse amount to float") + log.Error().Err(err).Msg("Could not parse amount to float") + return } rewardFund.Price = price rewardFund.AmountAvailable = amt @@ -92,7 +95,8 @@ func CreateRewardFund(resp http.ResponseWriter, req *http.Request) { for _, o := range op.Embedded.Records { parsedAmt, err := strconv.ParseFloat(o.Amount, 64) if err != nil { - panic("Could not parse amount to float") + log.Error().Err(err).Msg("Could not parse amount to float") + return } if parsedAmt > maxOffers { correctOffer = o @@ -101,13 +105,14 @@ func CreateRewardFund(resp http.ResponseWriter, req *http.Request) { } price, err = strconv.ParseFloat(correctOffer.Price, 64) if err != nil { - panic("Could not parse price to float") + log.Error().Err(err).Msg("Could not parse price to float") + return } rewardFund.Price = price amt, err = strconv.ParseFloat(correctOffer.Amount, 64) if err != nil { - panic("Could not parse amount to float") + log.Error().Err(err).Msg("Could not parse amount to float") } rewardFund.AmountAvailable = amt } else { @@ -118,7 +123,8 @@ func CreateRewardFund(resp http.ResponseWriter, req *http.Request) { var claims *auth.Claims claims, err = auth.GetUserClaims(req) if err != nil { - panic("Could not determine if user is authenticated") + log.Error().Err(err).Msg("Could not determine if user is authenticated") + return } if claims.Privileges <= Admin { @@ -138,7 +144,7 @@ func CreateRewardFund(resp http.ResponseWriter, req *http.Request) { err = json.NewEncoder(resp).Encode(&SuccessResponse{Success: true}) if err != nil { - panic("Could not create response for created reward fund") + log.Error().Err(err).Msg("Could not create response for created reward fund") } } else { resp.WriteHeader(403) diff --git a/endpoints/escalateprivileges.go b/endpoints/escalateprivileges.go index 11e212a..ab285bb 100644 --- a/endpoints/escalateprivileges.go +++ b/endpoints/escalateprivileges.go @@ -6,6 +6,7 @@ import ( "github.com/imosed/signet/auth" . "github.com/imosed/signet/data" + "github.com/rs/zerolog/log" ) type EscalatePrivilegesRequest struct { @@ -16,7 +17,8 @@ func EscalatePrivileges(w http.ResponseWriter, r *http.Request) { var req EscalatePrivilegesRequest err := json.NewDecoder(r.Body).Decode(&req) if err != nil { - panic("Could not decode body") + log.Error().Err(err).Msg("Could not decode body in EscalatePrivileges call") + return } var resp SuccessResponse @@ -32,7 +34,7 @@ func EscalatePrivileges(w http.ResponseWriter, r *http.Request) { err = json.NewEncoder(w).Encode(resp) if err != nil { - panic("Could not deliver failed escalate privileges response") + log.Error().Err(err).Msg("Could not deliver failed escalate privileges response") } return } @@ -45,6 +47,6 @@ func EscalatePrivileges(w http.ResponseWriter, r *http.Request) { err = json.NewEncoder(w).Encode(resp) if err != nil { - panic("Could not deliver successful escalate privileges response") + log.Error().Err(err).Msg("Could not deliver successful escalate privileges response") } } diff --git a/endpoints/getbalance.go b/endpoints/getbalance.go index 4dc86c9..e32de36 100644 --- a/endpoints/getbalance.go +++ b/endpoints/getbalance.go @@ -5,6 +5,7 @@ import ( "net/http" "strconv" + "github.com/rs/zerolog/log" "github.com/stellar/go/clients/horizonclient" "github.com/stellar/go/keypair" "github.com/stellar/go/protocols/horizon" @@ -22,7 +23,8 @@ func GetBalance(w http.ResponseWriter, r *http.Request) { var req GetBalanceRequest err := json.NewDecoder(r.Body).Decode(&req) if err != nil { - panic("Could not decode body") + log.Error().Err(err).Msg("Could not decode body in GetBalance call") + return } var kp keypair.KP @@ -38,7 +40,8 @@ func GetBalance(w http.ResponseWriter, r *http.Request) { var acct horizon.Account acct, err = client.AccountDetail(acctReq) if err != nil { - panic("Could not get account data from public key") + log.Error().Err(err).Msg("Could not get account data from public key") + return } var blnce = -1.0 @@ -49,7 +52,8 @@ func GetBalance(w http.ResponseWriter, r *http.Request) { } if blnce == -1.0 { - panic("Could not get XLM balance") + log.Error().Err(err).Msg("Could not get XLM balance") + return } var resp GetBalanceResponse @@ -57,6 +61,6 @@ func GetBalance(w http.ResponseWriter, r *http.Request) { err = json.NewEncoder(w).Encode(resp) if err != nil { - panic("Could not deliver response") + log.Error().Err(err).Msg("Could not deliver response in GetBalance call") } } diff --git a/endpoints/getqueuemembers.go b/endpoints/getqueuemembers.go index e0c5809..a4556b0 100644 --- a/endpoints/getqueuemembers.go +++ b/endpoints/getqueuemembers.go @@ -5,6 +5,7 @@ import ( "net/http" . "github.com/imosed/signet/data" + "github.com/rs/zerolog/log" ) type QueueMember struct { @@ -26,7 +27,8 @@ func GetQueueMembers(w http.ResponseWriter, r *http.Request) { var req GetQueueMembersRequest err := json.NewDecoder(r.Body).Decode(&req) if err != nil { - panic("Could not decode body") + log.Error().Err(err).Msg("Could not decode body in GetQueueMembers call") + return } var members []QueueMember @@ -40,6 +42,6 @@ func GetQueueMembers(w http.ResponseWriter, r *http.Request) { err = json.NewEncoder(w).Encode(resp) if err != nil { - panic("Could not deliver response") + log.Error().Err(err).Msg("Could not deliver response in GetQueueMembers call") } } diff --git a/endpoints/getqueues.go b/endpoints/getqueues.go index 562eca6..a7759b9 100644 --- a/endpoints/getqueues.go +++ b/endpoints/getqueues.go @@ -5,6 +5,7 @@ import ( "net/http" . "github.com/imosed/signet/data" + "github.com/rs/zerolog/log" ) type GetQueuesResponse struct { @@ -18,6 +19,6 @@ func GetQueues(w http.ResponseWriter, _ *http.Request) { err := json.NewEncoder(w).Encode(resp) if err != nil { - panic("Could not deliver response") + log.Error().Err(err).Msg("Could not deliver response in GetQueues call") } } diff --git a/endpoints/getrewardfund.go b/endpoints/getrewardfund.go index 597b856..1507c92 100644 --- a/endpoints/getrewardfund.go +++ b/endpoints/getrewardfund.go @@ -6,6 +6,7 @@ import ( "time" . "github.com/imosed/signet/data" + "github.com/rs/zerolog/log" "gorm.io/gorm/clause" ) @@ -33,7 +34,7 @@ func GetRewardFund(resp http.ResponseWriter, req *http.Request) { dec := json.NewDecoder(req.Body) err := dec.Decode(&requestedFund) if err != nil { - panic("Could not read requested fund") + log.Error().Err(err).Msg("Could not read requested fund") } found := Db.Preload(clause.Associations).Find(&fund, requestedFund.ID).RowsAffected @@ -65,8 +66,7 @@ func GetRewardFund(resp http.ResponseWriter, req *http.Request) { Price: fund.Price, AmountAvailable: fund.AmountAvailable, MinContribution: fund.MinContribution, - Title: fund.Title, - Description: fund.Description, + TelegramLink: fund.TelegramLink, Bonuses: fund.Bonuses, }, Contributions: contribs, @@ -75,7 +75,7 @@ func GetRewardFund(resp http.ResponseWriter, req *http.Request) { err = json.NewEncoder(resp).Encode(r) if err != nil { - panic("Could not deliver requested fund") + log.Error().Err(err).Msg("Could not deliver requested fund") } } @@ -98,7 +98,8 @@ func GetContributions(w http.ResponseWriter, r *http.Request) { var req GetContributionsRequest err := json.NewDecoder(r.Body).Decode(&req) if err != nil { - panic("Could not decode body") + log.Error().Err(err).Msg("Could not decode body in GetContributions call") + return } var resp GetContributionsResponse @@ -120,7 +121,8 @@ func GetContributions(w http.ResponseWriter, r *http.Request) { t, err = time.Parse("2006-Jan-02", req.ForDate) t = t.Add(time.Hour * 24) if err != nil { - panic("Could not interpret time") + log.Error().Err(err).Msg("Could not interpret time") + return } if req.ConsolidateContributions { baseQuery.Select("wallet, sum(amount) amount").Where("created_at < ?", t).Group("wallet").Scan(&resp.List) @@ -133,7 +135,7 @@ func GetContributions(w http.ResponseWriter, r *http.Request) { err = json.NewEncoder(w).Encode(resp) if err != nil { - panic("Could not deliver response") + log.Error().Err(err).Msg("Could not deliver response in GetContributions call") } } @@ -147,7 +149,6 @@ type FundInfo struct { Price float64 `json:"price"` AmountAvailable float64 `json:"amountAvailable"` MinContribution float64 `json:"minContribution"` - Title string `json:"title"` - Description string `json:"description"` + TelegramLink string `json:"telegramLink"` Bonuses []Bonus `json:"bonuses"` } diff --git a/endpoints/getrewardfunds.go b/endpoints/getrewardfunds.go index d61939b..b7abbb6 100644 --- a/endpoints/getrewardfunds.go +++ b/endpoints/getrewardfunds.go @@ -5,6 +5,7 @@ import ( "net/http" . "github.com/imosed/signet/data" + "github.com/rs/zerolog/log" ) func getQualifiedRewardFunds() []RewardFund { @@ -71,7 +72,8 @@ func GetRewardFunds(w http.ResponseWriter, r *http.Request) { var req GetRewardFundsRequest err := json.NewDecoder(r.Body).Decode(&req) if err != nil { - panic("Could not decode body") + log.Error().Err(err).Msg("Could not decode body in GetRewardFunds call") + return } var resp GetRewardFundsResponse @@ -88,15 +90,14 @@ func GetRewardFunds(w http.ResponseWriter, r *http.Request) { Memo: f.Memo, AmountAvailable: f.AmountAvailable, MinContribution: f.MinContribution, - Title: f.Title, - Description: f.Description, + TelegramLink: f.TelegramLink, Bonuses: f.Bonuses, }) } err = json.NewEncoder(w).Encode(resp) if err != nil { - panic("Could not deliver response") + log.Error().Err(err).Msg("Could not deliver response in GetRewardFunds call") } } diff --git a/endpoints/login.go b/endpoints/login.go index 9f966a2..414d3d9 100644 --- a/endpoints/login.go +++ b/endpoints/login.go @@ -8,6 +8,7 @@ import ( "github.com/golang-jwt/jwt/v4" "github.com/imosed/signet/auth" . "github.com/imosed/signet/data" + "github.com/rs/zerolog/log" "github.com/spf13/viper" ) @@ -19,7 +20,8 @@ func Login(w http.ResponseWriter, r *http.Request) { var req AuthenticationRequest err := json.NewDecoder(r.Body).Decode(&req) if err != nil { - panic("Could not decode body") + log.Error().Err(err).Msg("Failed to decode body in login attempt") + return } var userData struct { @@ -34,11 +36,15 @@ func Login(w http.ResponseWriter, r *http.Request) { var passwordMatches bool passwordMatches, err = ComparePasswordAndHash(req.Password, userData.Password) if err != nil { - panic("Could not compare password to hash") + log.Error().Err(err).Msg("Could not compare password to hash in login attempt") + return } if !passwordMatches { resp.Token = nil err = json.NewEncoder(w).Encode(resp) + if err != nil { + log.Error().Err(err).Msg("Failed to deliver failed login attempt response") + } return } @@ -53,12 +59,13 @@ func Login(w http.ResponseWriter, r *http.Request) { secret := viper.GetString("app.secretKey") tokenString, err := token.SignedString([]byte(secret)) if err != nil { - panic("Could not generate JWT token") + log.Error().Err(err).Msg("Could not generate JWT token") + return } resp.Token = &tokenString err = json.NewEncoder(w).Encode(resp) if err != nil { - panic("Could not deliver response") + log.Error().Err(err).Msg("Could not deliver response in Login call") } } diff --git a/endpoints/register.go b/endpoints/register.go index 068554c..2ccb00b 100644 --- a/endpoints/register.go +++ b/endpoints/register.go @@ -12,6 +12,7 @@ import ( "github.com/imosed/signet/auth" . "github.com/imosed/signet/data" + "github.com/rs/zerolog/log" "github.com/spf13/viper" "golang.org/x/crypto/argon2" ) @@ -127,13 +128,15 @@ func Register(w http.ResponseWriter, r *http.Request) { var req AuthenticationRequest err := json.NewDecoder(r.Body).Decode(&req) if err != nil { - panic("Could not decode body") + log.Error().Err(err).Msg("Could not decode body in Register call") + return } var claims *auth.Claims claims, err = auth.GetUserClaims(r) if err != nil { - panic("Could not determine if user is authenticated") + log.Error().Err(err).Msg("Could not determine if user is authenticated") + return } if noUsersRegistered() || claims.Privileges <= AdminPlus { @@ -145,7 +148,8 @@ func Register(w http.ResponseWriter, r *http.Request) { KeyLength: uint32(viper.GetInt("hashing.keyLength")), }) if err != nil { - panic("Could not generate hash for registration") + log.Error().Err(err).Msg("Could not generate hash for registration") + return } Db.Create(&User{ @@ -156,12 +160,12 @@ func Register(w http.ResponseWriter, r *http.Request) { err = json.NewEncoder(w).Encode(SuccessResponse{Success: true}) if err != nil { - panic("Could not deliver successful account creation response") + log.Error().Err(err).Msg("Could not deliver successful account creation response") } } else if !noUsersRegistered() { err = json.NewEncoder(w).Encode(SuccessResponse{Success: false}) if err != nil { - panic("Could not deliver unsuccessful account creation response") + log.Error().Err(err).Msg("Could not deliver unsuccessful account creation response") } } else if claims.Privileges > SuperUser { w.WriteHeader(403) diff --git a/endpoints/submitfund.go b/endpoints/submitfund.go index e882659..847372e 100644 --- a/endpoints/submitfund.go +++ b/endpoints/submitfund.go @@ -6,6 +6,7 @@ import ( "net/http" . "github.com/imosed/signet/data" + "github.com/rs/zerolog/log" "github.com/stellar/go/clients/horizonclient" "github.com/stellar/go/protocols/horizon" ) @@ -20,7 +21,7 @@ func SubmitFund(w http.ResponseWriter, r *http.Request) { var req SubmitFundRequest err := json.NewDecoder(r.Body).Decode(&req) if err != nil { - panic("Could not decode body") + log.Error().Err(err).Msg("Could not decode body in SubmitFund call") } var fund RewardFund @@ -71,12 +72,12 @@ func SubmitFund(w http.ResponseWriter, r *http.Request) { // }, // }) // if err != nil { - // panic("Could not submit reward fund") + // log.Error().Err(err).Msg("Could not submit reward fund") // } // // tx, err = tx.Sign(network.TestNetworkPassphrase, source) // if err != nil { - // panic("Could not submit fund") + // log.Error().Err(err).Msg("Could not submit fund") // } // // var response horizon.Transaction @@ -87,6 +88,6 @@ func SubmitFund(w http.ResponseWriter, r *http.Request) { err = json.NewEncoder(w).Encode(resp) if err != nil { - panic("Could not deliver response") + log.Error().Err(err).Msg("Could not deliver response in SubmitFund call") } } diff --git a/endpoints/users.go b/endpoints/users.go index 8c8b9ed..5e373ce 100644 --- a/endpoints/users.go +++ b/endpoints/users.go @@ -5,6 +5,7 @@ import ( "net/http" . "github.com/imosed/signet/data" + "github.com/rs/zerolog/log" ) func UsersExist(w http.ResponseWriter, _ *http.Request) { @@ -16,6 +17,6 @@ func UsersExist(w http.ResponseWriter, _ *http.Request) { err := json.NewEncoder(w).Encode(resp) if err != nil { - panic("Could not deliver response") + log.Error().Err(err).Msg("Could not deliver response in UsersExist call") } } diff --git a/go.mod b/go.mod index 8e026fb..2f85142 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/golang-jwt/jwt/v4 v4.4.3 github.com/gorilla/mux v1.8.0 github.com/gorilla/websocket v1.5.0 - github.com/pdrum/swagger-automation v0.0.0-20190629163613-c8c7c80ba858 + github.com/rs/zerolog v1.15.0 github.com/spf13/viper v0.0.0-20150621231900-db7ff930a189 github.com/stellar/go v0.0.0-20221028081946-9308f9531041 golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa @@ -34,12 +34,8 @@ require ( github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect github.com/kr/pretty v0.1.0 // indirect github.com/kr/text v0.1.0 // indirect - github.com/labstack/echo v3.3.10+incompatible // indirect - github.com/labstack/gommon v0.2.9 // indirect github.com/magiconair/properties v1.5.4 // indirect github.com/manucorporat/sse v0.0.0-20160126180136-ee05b128a739 // indirect - github.com/mattn/go-colorable v0.1.6 // indirect - github.com/mattn/go-isatty v0.0.12 // indirect github.com/mitchellh/mapstructure v0.0.0-20150613213606-2caf8efc9366 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect @@ -51,8 +47,6 @@ require ( github.com/stellar/go-xdr v0.0.0-20211103144802-8017fc4bdfee // indirect github.com/stretchr/objx v0.4.0 // indirect github.com/stretchr/testify v1.8.0 // indirect - github.com/valyala/bytebufferpool v1.0.0 // indirect - github.com/valyala/fasttemplate v1.0.1 // indirect golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 // indirect golang.org/x/text v0.3.7 // indirect gopkg.in/yaml.v2 v2.2.8 // indirect diff --git a/go.sum b/go.sum index ae5d485..812ea1b 100644 --- a/go.sum +++ b/go.sum @@ -12,7 +12,6 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/fatih/structs v1.0.0 h1:BrX964Rv5uQ3wwS+KRUAJCBBw5PQmgJfJ6v4yly5QwU= github.com/gavv/monotime v0.0.0-20161010190848-47d58efa6955 h1:gmtGRvSexPU4B1T/yYo0sLOKzER1YT+b4kPxPpm0Ty4= github.com/go-chi/chi v4.0.3+incompatible h1:gakN3pDJnzZN5jqFV2TEdF66rTfKeITyR8qu6ekICEY= @@ -99,10 +98,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg= -github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s= -github.com/labstack/gommon v0.2.9 h1:heVeuAYtevIQVYkGj6A41dtfT91LrvFG220lavpWhrU= -github.com/labstack/gommon v0.2.9/go.mod h1:E8ZTmW9vw5az5/ZyHWCp0Lw4OH2ecsaBP1C/NKavGG4= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= @@ -113,21 +108,15 @@ github.com/magiconair/properties v1.5.4/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czP github.com/manucorporat/sse v0.0.0-20160126180136-ee05b128a739 h1:ykXz+pRRTibcSjG1yRhpdSHInF8yZY/mfn+Rz2Nd1rE= github.com/manucorporat/sse v0.0.0-20160126180136-ee05b128a739/go.mod h1:zUx1mhth20V3VKgL5jbd1BSQcW4Fy6Qs4PZvQwRFwzM= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= -github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE= github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mitchellh/mapstructure v0.0.0-20150613213606-2caf8efc9366 h1:1ypTpKUfEOyX1YsJru6lLq7hrmK+QGECpJQ1PHUHuGo= github.com/mitchellh/mapstructure v0.0.0-20150613213606-2caf8efc9366/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/moul/http2curl v0.0.0-20161031194548-4e24498b31db h1:eZgFHVkk9uOTaOQLC6tgjkzdp7Ays8eEVecBcfHZlJQ= github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= -github.com/pdrum/swagger-automation v0.0.0-20190629163613-c8c7c80ba858 h1:lgbJiJQx8bXo+eM88AFdd0VxUvaTLzCBXpK+H9poJ+Y= -github.com/pdrum/swagger-automation v0.0.0-20190629163613-c8c7c80ba858/go.mod h1:y02HeaN0visd95W6cEX2NXDv5sCwyqfzucWTdDGEwYY= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -136,6 +125,7 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= +github.com/rs/zerolog v1.15.0 h1:uPRuwkWF4J6fGsJ2R0Gn2jB1EQiav9k3S6CSdygQJXY= github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/segmentio/go-loggly v0.5.1-0.20171222203950-eb91657e62b2 h1:S4OC0+OBKz6mJnzuHioeEat74PuQ4Sgvbf8eus695sc= @@ -173,10 +163,7 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= -github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.34.0 h1:d3AAQJ2DRcxJYHm7OXNXtXt2as1vMDfxeIcFvhmGGm4= -github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8= -github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= github.com/xdrpp/goxdr v0.1.1 h1:E1B2c6E8eYhOVyd7yEpOyopzTPirUeF6mVOfXfGyJyc= github.com/xeipuuv/gojsonpointer v0.0.0-20151027082146-e0fe6f683076 h1:KM4T3G70MiR+JtqplcYkNVoNz7pDwYaBxWBXQK804So= github.com/xeipuuv/gojsonreference v0.0.0-20150808065054-e02fc20de94c h1:XZWnr3bsDQWAZg4Ne+cPoXRPILrNlPNQfxBuwLl43is= @@ -199,7 +186,6 @@ go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -227,7 +213,6 @@ golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/main.go b/main.go index ca523a5..93c0bd9 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,8 @@ import ( "github.com/gorilla/mux" "github.com/imosed/signet/data" "github.com/imosed/signet/endpoints" + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" "github.com/spf13/viper" ) @@ -19,9 +21,11 @@ func main() { viper.SetConfigFile("config.production.json") err = viper.ReadInConfig() if err != nil { - panic("Could not read in Viper config") + log.Error().Err(err).Msg("Could not read in Viper config") } + zerolog.TimeFieldFormat = zerolog.TimeFormatUnix + data.InitializeDatabase() go endpoints.InitializeContributionStreams() @@ -48,6 +52,6 @@ func main() { fmt.Printf("Running on port %d...\n", port) err = http.ListenAndServe(fmt.Sprintf(":%d", port), router) if err != nil { - panic(fmt.Sprintf("Could not bind to port %d", port)) + log.Error().Err(err).Msg(fmt.Sprintf("Could not bind to port %d", port)) } }