Skip to content

Commit

Permalink
Fix package names, protojson pretty print
Browse files Browse the repository at this point in the history
  • Loading branch information
ProfMoo committed Apr 24, 2024
1 parent b5ebdb1 commit da1b98b
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 69 deletions.
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,13 @@ func main() {
log.Fatalf("error listing rewards: %s", err.Error())
}

marshaled, err := protojson.Marshal(reward)
marshaler := protojson.MarshalOptions{Indent: "\t"}
marshaled, err := marshaler.Marshal(reward)
if err != nil {
log.Fatalf("error marshaling reward: %s", err.Error())
}

var prettyJSON bytes.Buffer
if err := json.Indent(&prettyJSON, marshaled, "", "\t"); err != nil {
log.Fatalf("JSON parse error: %s", err)
return
}

fmt.Println(prettyJSON.String())
fmt.Println(string(marshaled))
}
}
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rewards_filter
package rewardsfilter

import (
"time"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package rewards_filter_test
package rewardsfilter_test

import (
"fmt"
"testing"
"time"

filter "github.com/coinbase/staking-client-library-go/client/rewards/rewards_filter"
filter "github.com/coinbase/staking-client-library-go/client/rewards/rewardsfilter"
"github.com/stretchr/testify/assert"
"github.com/test-go/testify/suite"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package stakes_filter
package stakesfilter

import (
"time"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package stakes_filter_test
package stakesfilter_test

import (
"testing"
"time"

filter "github.com/coinbase/staking-client-library-go/client/rewards/stakes_filter"
filter "github.com/coinbase/staking-client-library-go/client/rewards/stakesfilter"
"github.com/stretchr/testify/assert"
"github.com/test-go/testify/suite"
)
Expand Down
15 changes: 4 additions & 11 deletions examples/cosmos/list-rewards/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package main

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"log"
Expand All @@ -13,7 +11,7 @@ import (
"github.com/coinbase/staking-client-library-go/client"
"github.com/coinbase/staking-client-library-go/client/options"
"github.com/coinbase/staking-client-library-go/client/rewards"
filter "github.com/coinbase/staking-client-library-go/client/rewards/rewards_filter"
filter "github.com/coinbase/staking-client-library-go/client/rewards/rewardsfilter"
api "github.com/coinbase/staking-client-library-go/gen/go/coinbase/staking/rewards/v1"
"google.golang.org/api/iterator"
"google.golang.org/protobuf/encoding/protojson"
Expand Down Expand Up @@ -65,17 +63,12 @@ func main() {
log.Fatalf("error listing rewards: %s", err.Error())
}

marshaled, err := protojson.Marshal(reward)
marshaler := protojson.MarshalOptions{Indent: "\t"}
marshaled, err := marshaler.Marshal(reward)
if err != nil {
log.Fatalf("error marshaling reward: %s", err.Error())
}

var prettyJSON bytes.Buffer
if err := json.Indent(&prettyJSON, marshaled, "", "\t"); err != nil {
log.Fatalf("JSON parse error: %s", err)
return
}

fmt.Println(prettyJSON.String())
fmt.Println(string(marshaled))
}
}
15 changes: 4 additions & 11 deletions examples/cosmos/list-stakes/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package main

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"log"
Expand All @@ -12,7 +10,7 @@ import (
"github.com/coinbase/staking-client-library-go/client"
"github.com/coinbase/staking-client-library-go/client/options"
"github.com/coinbase/staking-client-library-go/client/rewards"
filter "github.com/coinbase/staking-client-library-go/client/rewards/stakes_filter"
filter "github.com/coinbase/staking-client-library-go/client/rewards/stakesfilter"
api "github.com/coinbase/staking-client-library-go/gen/go/coinbase/staking/rewards/v1"
"google.golang.org/api/iterator"
"google.golang.org/protobuf/encoding/protojson"
Expand Down Expand Up @@ -62,17 +60,12 @@ func main() {
log.Fatalf("error listing stakes: %s", err.Error())
}

marshaled, err := protojson.Marshal(stake)
marshaler := protojson.MarshalOptions{Indent: "\t"}
marshaled, err := marshaler.Marshal(stake)
if err != nil {
log.Fatalf("error marshaling reward: %s", err.Error())
}

var prettyJSON bytes.Buffer
if err := json.Indent(&prettyJSON, marshaled, "", "\t"); err != nil {
log.Fatalf("JSON parse error: %s", err)
return
}

fmt.Println(prettyJSON.String())
fmt.Println(string(marshaled))
}
}
15 changes: 4 additions & 11 deletions examples/ethereum/list-rewards/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
package main

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"log"
Expand All @@ -17,7 +15,7 @@ import (
"github.com/coinbase/staking-client-library-go/client"
"github.com/coinbase/staking-client-library-go/client/options"
"github.com/coinbase/staking-client-library-go/client/rewards"
filter "github.com/coinbase/staking-client-library-go/client/rewards/rewards_filter"
filter "github.com/coinbase/staking-client-library-go/client/rewards/rewardsfilter"
api "github.com/coinbase/staking-client-library-go/gen/go/coinbase/staking/rewards/v1"
"google.golang.org/api/iterator"
"google.golang.org/protobuf/encoding/protojson"
Expand Down Expand Up @@ -68,17 +66,12 @@ func main() {
log.Fatalf("error listing rewards: %s", err.Error())
}

marshaled, err := protojson.Marshal(reward)
marshaler := protojson.MarshalOptions{Indent: "\t"}
marshaled, err := marshaler.Marshal(reward)
if err != nil {
log.Fatalf("error marshaling reward: %s", err.Error())
}

var prettyJSON bytes.Buffer
if err := json.Indent(&prettyJSON, marshaled, "", "\t"); err != nil {
log.Fatalf("JSON parse error: %s", err)
return
}

fmt.Println(prettyJSON.String())
fmt.Println(string(marshaled))
}
}
15 changes: 4 additions & 11 deletions examples/ethereum/list-stakes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
package main

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"log"
Expand All @@ -16,7 +14,7 @@ import (
"github.com/coinbase/staking-client-library-go/client"
"github.com/coinbase/staking-client-library-go/client/options"
"github.com/coinbase/staking-client-library-go/client/rewards"
filter "github.com/coinbase/staking-client-library-go/client/rewards/stakes_filter"
filter "github.com/coinbase/staking-client-library-go/client/rewards/stakesfilter"
api "github.com/coinbase/staking-client-library-go/gen/go/coinbase/staking/rewards/v1"
"google.golang.org/api/iterator"
"google.golang.org/protobuf/encoding/protojson"
Expand Down Expand Up @@ -65,17 +63,12 @@ func main() {
log.Fatalf("error listing stakes: %s", err.Error())
}

marshaled, err := protojson.Marshal(stake)
marshaler := protojson.MarshalOptions{Indent: "\t"}
marshaled, err := marshaler.Marshal(stake)
if err != nil {
log.Fatalf("error marshaling reward: %s", err.Error())
}

var prettyJSON bytes.Buffer
if err := json.Indent(&prettyJSON, marshaled, "", "\t"); err != nil {
log.Fatalf("JSON parse error: %s", err)
return
}

fmt.Println(prettyJSON.String())
fmt.Println(string(marshaled))
}
}
15 changes: 4 additions & 11 deletions examples/solana/list-rewards/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
package main

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"log"
Expand All @@ -18,7 +16,7 @@ import (
"github.com/coinbase/staking-client-library-go/client"
"github.com/coinbase/staking-client-library-go/client/options"
"github.com/coinbase/staking-client-library-go/client/rewards"
filter "github.com/coinbase/staking-client-library-go/client/rewards/rewards_filter"
filter "github.com/coinbase/staking-client-library-go/client/rewards/rewardsfilter"
api "github.com/coinbase/staking-client-library-go/gen/go/coinbase/staking/rewards/v1"
"google.golang.org/api/iterator"
"google.golang.org/protobuf/encoding/protojson"
Expand Down Expand Up @@ -70,17 +68,12 @@ func main() {
log.Fatalf("error listing rewards: %s", err.Error())
}

marshaled, err := protojson.Marshal(reward)
marshaler := protojson.MarshalOptions{Indent: "\t"}
marshaled, err := marshaler.Marshal(reward)
if err != nil {
log.Fatalf("error marshaling reward: %s", err.Error())
}

var prettyJSON bytes.Buffer
if err := json.Indent(&prettyJSON, marshaled, "", "\t"); err != nil {
log.Fatalf("JSON parse error: %s", err)
return
}

fmt.Println(prettyJSON.String())
fmt.Println(string(marshaled))
}
}

0 comments on commit da1b98b

Please sign in to comment.