Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

add golangci linter #17

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
linters:
disable-all: false
disable:
- thelper
- varnamelen
- tagliatelle
- wrapcheck
linters-settings:
gocyclo:
min-complexity: 11
issues:
exclude:
- composite
run:
tests: false
go: "1.21"
15 changes: 12 additions & 3 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,20 @@ var (

func init() {
deployCmd.Flags().StringVar(&deployArgs.url, "url", "", "Fullnode URL to interact with blockchain")
deployCmd.MarkFlagRequired("url")
err := deployCmd.MarkFlagRequired("url")
if err != nil {
logrus.WithError(err).Error("Failed to MarkFlagRequired flag: url")
}
deployCmd.Flags().StringVar(&deployArgs.key, "key", "", "Private key to create smart contract")
deployCmd.MarkFlagRequired("key")
err = deployCmd.MarkFlagRequired("key")
if err != nil {
logrus.WithError(err).Error("Failed to MarkFlagRequired flag: key")
}
deployCmd.Flags().StringVar(&deployArgs.bytecodeOrFile, "bytecode", "", "ZeroGStorage smart contract bytecode")
deployCmd.MarkFlagRequired("bytecode")
err = deployCmd.MarkFlagRequired("bytecode")
if err != nil {
logrus.WithError(err).Error("Failed to MarkFlagRequired flag: bytecode")
}

rootCmd.AddCommand(deployCmd)
}
Expand Down
15 changes: 12 additions & 3 deletions cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,20 @@ var (

func init() {
downloadCmd.Flags().StringVar(&downloadArgs.file, "file", "", "File name to download")
downloadCmd.MarkFlagRequired("file")
err := downloadCmd.MarkFlagRequired("file")
if err != nil {
logrus.WithError(err).Error("Failed to MarkFlagRequired flag: file")
}
downloadCmd.Flags().StringSliceVar(&downloadArgs.nodes, "node", []string{}, "ZeroGStorage storage node URL. Multiple nodes could be specified and separated by comma, e.g. url1,url2,url3")
downloadCmd.MarkFlagRequired("node")
err = downloadCmd.MarkFlagRequired("node")
if err != nil {
logrus.WithError(err).Error("Failed to MarkFlagRequired flag: node")
}
downloadCmd.Flags().StringVar(&downloadArgs.root, "root", "", "Merkle root to download file")
downloadCmd.MarkFlagRequired("root")
err = downloadCmd.MarkFlagRequired("root")
if err != nil {
logrus.WithError(err).Error("Failed to MarkFlagRequired flag: root")
}
downloadCmd.Flags().BoolVar(&downloadArgs.proof, "proof", false, "Whether to download with merkle proof for validation")

rootCmd.AddCommand(downloadCmd)
Expand Down
5 changes: 4 additions & 1 deletion cmd/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ var (

func init() {
indexderCmd.Flags().StringSliceVar(&nodes, "nodes", nil, "Storage node URLs that separated by comma")
indexderCmd.MarkFlagRequired("nodes")
err := indexderCmd.MarkFlagRequired("nodes")
if err != nil {
logrus.WithError(err).Error("Failed to MarkFlagRequired flag: nodes")
}
indexderCmd.Flags().StringVar(&endpoint, "endpoint", ":12345", "Indexer RPC endpoint")

rootCmd.AddCommand(indexderCmd)
Expand Down
25 changes: 20 additions & 5 deletions cmd/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,33 @@ var (

func init() {
uploadCmd.Flags().StringVar(&uploadArgs.file, "file", "", "File name to upload")
uploadCmd.MarkFlagRequired("file")
err := uploadCmd.MarkFlagRequired("file")
if err != nil {
logrus.WithError(err).Error("Failed to MarkFlagRequired flag: file")
}
uploadCmd.Flags().StringVar(&uploadArgs.tags, "tags", "0x", "Tags of the file")

uploadCmd.Flags().StringVar(&uploadArgs.url, "url", "", "Fullnode URL to interact with ZeroGStorage smart contract")
uploadCmd.MarkFlagRequired("url")
err = uploadCmd.MarkFlagRequired("url")
if err != nil {
logrus.WithError(err).Error("Failed to MarkFlagRequired flag: url")
}
uploadCmd.Flags().StringVar(&uploadArgs.contract, "contract", "", "ZeroGStorage smart contract to interact with")
uploadCmd.MarkFlagRequired("contract")
err = uploadCmd.MarkFlagRequired("contract")
if err != nil {
logrus.WithError(err).Error("Failed to MarkFlagRequired flag: contract")
}
uploadCmd.Flags().StringVar(&uploadArgs.key, "key", "", "Private key to interact with smart contract")
uploadCmd.MarkFlagRequired("key")
err = uploadCmd.MarkFlagRequired("key")
if err != nil {
logrus.WithError(err).Error("Failed to MarkFlagRequired flag: key")
}

uploadCmd.Flags().StringSliceVar(&uploadArgs.node, "node", []string{}, "ZeroGStorage storage node URL")
uploadCmd.MarkFlagRequired("node")
err = uploadCmd.MarkFlagRequired("node")
if err != nil {
logrus.WithError(err).Error("Failed to MarkFlagRequired flag: node")
}

uploadCmd.Flags().BoolVar(&uploadArgs.force, "force", false, "Force to upload file even already exists")
uploadCmd.Flags().UintVar(&uploadArgs.taskSize, "task-size", 10, "Number of segments to upload in single rpc request")
Expand Down
4 changes: 2 additions & 2 deletions common/blockchain/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package blockchain

import (
"encoding/json"
"io/ioutil"
"math/big"
"os"
"strings"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -62,7 +62,7 @@ func parseBytecode(dataOrFile string) (hexutil.Bytes, error) {
return hexutil.Decode(dataOrFile)
}

content, err := ioutil.ReadFile(dataOrFile)
content, err := os.ReadFile(dataOrFile)
if err != nil {
return nil, errors.WithMessage(err, "Failed to read file")
}
Expand Down
5 changes: 4 additions & 1 deletion common/util/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ func MustServeRPC(endpoint string, apis map[string]interface{}) {
logrus.WithError(err).WithField("endpoint", endpoint).Fatal("Failed to listen to endpoint")
}

httpServer.Serve(listener)
err = httpServer.Serve(listener)
if err != nil {
logrus.WithError(err).Fatal("Failed to serve http listener")
}
}
30 changes: 24 additions & 6 deletions example/kv_iterator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,46 @@ func main() {
iter := kvClient.NewIterator(streamId)

fmt.Println("begin to end:")
iter.SeekToFirst(ctx)
err = iter.SeekToFirst(ctx)
if err != nil {
fmt.Printf("SeekToFirst error: %s", err)
}
for iter.Valid() {
pair := iter.KeyValue()
fmt.Printf("%v: %v\n", string(pair.Key), string(pair.Data))
iter.Next(ctx)
err = iter.Next(ctx)
if err != nil {
fmt.Printf("Next error: %s", err)
}
}

fmt.Println("end to begin:")
iter.SeekToLast(ctx)
err = iter.SeekToLast(ctx)
if err != nil {
fmt.Printf("SeekToLast error: %s", err)
}
for iter.Valid() {
pair := iter.KeyValue()
fmt.Printf("%v: %v\n", string(pair.Key), string(pair.Data))
iter.Prev(ctx)
err = iter.Prev(ctx)
if err != nil {
fmt.Printf("Prev error: %s", err)
}
}

fmt.Printf("seek before %v\n", string(key1))
iter.SeekBefore(ctx, key1)
err = iter.SeekBefore(ctx, key1)
if err != nil {
fmt.Printf("SeekBefore error: %s", err)
}
pair := iter.KeyValue()
fmt.Printf("%v: %v\n", string(pair.Key), string(pair.Data))

fmt.Printf("seek after %v\n", string(key0))
iter.SeekAfter(ctx, key0)
err = iter.SeekAfter(ctx, key0)
if err != nil {
fmt.Printf("SeekAfter error: %s", err)
}
pair = iter.KeyValue()
fmt.Printf("%v: %v\n", string(pair.Key), string(pair.Data))
}