Skip to content

Commit

Permalink
chore: git-action: enable golang-ci-lint checks on git action (#208)
Browse files Browse the repository at this point in the history
* enable golang-ci-lint checks on git action
  • Loading branch information
zl03jsj authored Jul 14, 2022
1 parent df5e882 commit 7a62592
Show file tree
Hide file tree
Showing 27 changed files with 115 additions and 80 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ jobs:
go-version: 1.17

- name: Lint
uses: dominikh/staticcheck-action@v1.1.0
with:
install-go: false
version: "2021.1.1"

- name: Test
run: go test -v ./...
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.44.2
golangci-lint run --timeout 10m
- name: Build
env:
Expand All @@ -37,6 +33,12 @@ jobs:
run: |
make
- name: Detect changes
run: |
go mod tidy
git status --porcelain
test -z "$(git status --porcelain)"
- name: Run coverage
run: go test -coverpkg=./... -race -coverprofile=coverage.txt -covermode=atomic ./...

Expand Down
33 changes: 33 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
linters:
disable-all: true
enable:
- gofmt
- govet
- misspell
- goconst
- revive
- errcheck
- unconvert
- staticcheck
- varcheck
- structcheck
- deadcode
- unused
- stylecheck
- gosimple
- goimports

issues:
exclude:
- "should have( a package)? comment"
- "var-naming"
- "(ST1003)"

exclude-rules:
exclude-use-default: false

linters-settings:
goconst:
min-occurrences: 6
run:
skip-dirs-use-default: false
6 changes: 3 additions & 3 deletions api/jwt/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"github.com/filecoin-project/venus-messager/config"
)

type JwtClient struct {
type Client struct {
Local jwtclient.IJwtAuthClient
Remote *RemoteAuthClient
}

func NewJwtClient(jwtCfg *config.JWTConfig) (*JwtClient, error) {
func NewJwtClient(jwtCfg *config.JWTConfig) (*Client, error) {
var err error
jc := &JwtClient{
jc := &Client{
Remote: newRemoteJwtClient(jwtCfg),
}
if jc.Local, err = newLocalJWTClient(jwtCfg); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions api/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"go.uber.org/fx"
)

func BindRateLimit(msgImp *MessageImp, jwtCli *jwt.JwtClient, log *log.Logger, rateLimitCfg *config.RateLimitConfig) (messager.IMessager, error) {
func BindRateLimit(msgImp *MessageImp, jwtCli *jwt.Client, log *log.Logger, rateLimitCfg *config.RateLimitConfig) (messager.IMessager, error) {
var msgAPI messager.IMessagerStruct
permission.PermissionProxy(msgImp, &msgAPI)

Expand All @@ -41,7 +41,7 @@ func BindRateLimit(msgImp *MessageImp, jwtCli *jwt.JwtClient, log *log.Logger, r

// RunAPI bind rpc call and start rpc
// todo
func RunAPI(lc fx.Lifecycle, jwtCli *jwt.JwtClient, lst net.Listener, log *log.Logger, msgImp messager.IMessager) error {
func RunAPI(lc fx.Lifecycle, jwtCli *jwt.Client, lst net.Listener, log *log.Logger, msgImp messager.IMessager) error {
srv := jsonrpc.NewServer()
srv.Register("Message", msgImp)
handler := http.NewServeMux()
Expand Down
4 changes: 2 additions & 2 deletions api/modules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func TestLimitWrap(t *testing.T) {
fx.Supply(&config.RateLimitConfig{
Redis: "test url",
}),
fx.Provide(func() *jwt.JwtClient {
return &jwt.JwtClient{
fx.Provide(func() *jwt.Client {
return &jwt.Client{
Remote: &jwt.RemoteAuthClient{
Cli: &jwtclient.AuthClient{},
},
Expand Down
2 changes: 1 addition & 1 deletion cli/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ var waitMessagerCmd = &cli.Command{
}

id := cctx.Args().Get(0)
msg, err := client.WaitMessage(cctx.Context, id, uint64(constants.MessageConfidence))
msg, err := client.WaitMessage(cctx.Context, id, constants.MessageConfidence)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/tablewriter/tablewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewLineCol(name string) Column {
}
}

// Unlike text/tabwriter, this works with CLI escape codes, and allows for info
// New unlike text/tabwriter, this works with CLI escape codes, and allows for info
// in separate lines
func New(cols ...Column) *TableWriter {
return &TableWriter{
Expand Down
3 changes: 2 additions & 1 deletion config/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/pelletier/go-toml"
)

func ConfigExist(path string) (bool, error) {
func Exist(path string) (bool, error) {
_, err := os.Stat(path)
if err != nil {
if os.IsNotExist(err) {
Expand All @@ -17,6 +17,7 @@ func ConfigExist(path string) (bool, error) {
}
return true, nil
}

func ReadConfig(path string) (*Config, error) {
configBytes, err := ioutil.ReadFile(path)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion gateway/gateway_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type IWalletClient interface {
WalletSign(ctx context.Context, account string, addr address.Address, toSign []byte, meta venusTypes.MsgMeta) (*crypto.Signature, error)
}

// *api.MessageImp and *gateway.WalletClient both implement IWalletClient, so injection will fail
// IWalletCli *api.MessageImp and *gateway.WalletClient both implement IWalletClient, so injection will fail
type IWalletCli struct {
IWalletClient
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func runAction(ctx *cli.Context) error {
return err
}

exist, err := config.ConfigExist(path)
exist, err := config.Exist(path)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions metrics/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package metrics

import (
"context"

"github.com/ipfs-force-community/metrics"
"go.uber.org/fx"

Expand Down
2 changes: 1 addition & 1 deletion models/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/stretchr/testify/assert"

"github.com/filecoin-project/venus-messager/models/repo"
types "github.com/filecoin-project/venus/venus-shared/types/messager"
"github.com/filecoin-project/venus-messager/utils"
types "github.com/filecoin-project/venus/venus-shared/types/messager"
)

func TestSaveAndGetMessage(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions models/mysql/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (s mysqlAddress) TableName() string {
return "addresses"
}

func FromAddress(addr *types.Address) *mysqlAddress {
func fromAddress(addr *types.Address) *mysqlAddress {
mysqlAddr := &mysqlAddress{
ID: addr.ID,
Addr: addr.Addr.String(),
Expand Down Expand Up @@ -93,7 +93,7 @@ func newMysqlAddressRepo(db *gorm.DB) *mysqlAddressRepo {
}

func (s mysqlAddressRepo) SaveAddress(ctx context.Context, a *types.Address) error {
return s.DB.Save(FromAddress(a)).Error
return s.DB.Save(fromAddress(a)).Error
}

func (s mysqlAddressRepo) GetAddress(ctx context.Context, addr address.Address) (*types.Address, error) {
Expand Down
20 changes: 10 additions & 10 deletions models/mysql/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ import (
"github.com/filecoin-project/venus-messager/models/repo"
)

type MysqlRepo struct {
type Repo struct {
*gorm.DB
}

func (d MysqlRepo) MessageRepo() repo.MessageRepo {
func (d Repo) MessageRepo() repo.MessageRepo {
return newMysqlMessageRepo(d.DB)
}

func (d MysqlRepo) AddressRepo() repo.AddressRepo {
func (d Repo) AddressRepo() repo.AddressRepo {
return newMysqlAddressRepo(d.DB)
}

func (d MysqlRepo) SharedParamsRepo() repo.SharedParamsRepo {
func (d Repo) SharedParamsRepo() repo.SharedParamsRepo {
return newMysqlSharedParamsRepo(d.DB)
}

func (d MysqlRepo) NodeRepo() repo.NodeRepo {
func (d Repo) NodeRepo() repo.NodeRepo {
return newMysqlNodeRepo(d.DB)
}

func (d MysqlRepo) AutoMigrate() error {
func (d Repo) AutoMigrate() error {
err := d.GetDb().AutoMigrate(mysqlMessage{})
if err != nil {
return err
Expand All @@ -48,17 +48,17 @@ func (d MysqlRepo) AutoMigrate() error {
return d.GetDb().AutoMigrate(mysqlNode{})
}

func (d MysqlRepo) GetDb() *gorm.DB {
func (d Repo) GetDb() *gorm.DB {
return d.DB
}

func (d MysqlRepo) DbClose() error {
func (d Repo) DbClose() error {
// return d.DbClose()
// todo:
return nil
}

func (d MysqlRepo) Transaction(cb func(txRepo repo.TxRepo) error) error {
func (d Repo) Transaction(cb func(txRepo repo.TxRepo) error) error {
return d.DB.Transaction(func(tx *gorm.DB) error {
txRepo := &TxMysqlRepo{tx}
return cb(txRepo)
Expand Down Expand Up @@ -104,7 +104,7 @@ func OpenMysql(cfg *config.MySqlConfig) (repo.Repo, error) {

// 使用插件
//db.Use(&TracePlugin{})
return &MysqlRepo{
return &Repo{
db,
}, nil
}
6 changes: 3 additions & 3 deletions models/mysql/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (sqlMsg *mysqlMessage) Message() *types.Message {
return destMsg
}

func FromMessage(srcMsg *types.Message) *mysqlMessage {
func fromMessage(srcMsg *types.Message) *mysqlMessage {
destMsg := &mysqlMessage{
ID: srcMsg.ID,
Version: srcMsg.Version,
Expand Down Expand Up @@ -289,14 +289,14 @@ func (m *mysqlMessageRepo) BatchSaveMessage(msgs []*types.Message) error {
}

func (m *mysqlMessageRepo) CreateMessage(msg *types.Message) error {
sqlMsg := FromMessage(msg)
sqlMsg := fromMessage(msg)
sqlMsg.CreatedAt = time.Now()
sqlMsg.UpdatedAt = time.Now()
return m.DB.Create(sqlMsg).Error
}

func (m *mysqlMessageRepo) SaveMessage(msg *types.Message) error {
sqlMsg := FromMessage(msg)
sqlMsg := fromMessage(msg)
sqlMsg.UpdatedAt = time.Now()
return m.DB.Omit("created_at").Save(sqlMsg).Error
}
Expand Down
6 changes: 3 additions & 3 deletions models/mysql/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type mysqlNode struct {
UpdatedAt time.Time `gorm:"column:updated_at;index;NOT NULL"` // 更新时间
}

func FromNode(node *types.Node) *mysqlNode {
func fromNode(node *types.Node) *mysqlNode {
return automapper.MustMapper(node, TMysqlNode).(*mysqlNode)
}

Expand All @@ -48,14 +48,14 @@ func newMysqlNodeRepo(db *gorm.DB) mysqlNodeRepo {
}

func (s mysqlNodeRepo) CreateNode(node *types.Node) error {
sNode := FromNode(node)
sNode := fromNode(node)
sNode.CreatedAt = time.Now()
sNode.UpdatedAt = time.Now()
return s.DB.Create(sNode).Error
}

func (s mysqlNodeRepo) SaveNode(node *types.Node) error {
sNode := FromNode(node)
sNode := fromNode(node)
sNode.UpdatedAt = time.Now()
return s.DB.Save(sNode).Error
}
Expand Down
4 changes: 2 additions & 2 deletions models/mysql/shared_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type mysqlSharedParams struct {
SelMsgNum uint64 `gorm:"column:sel_msg_num;type:BIGINT(20) UNSIGNED;NOT NULL"`
}

func FromSharedParams(sp types.SharedSpec) *mysqlSharedParams {
func fromSharedParams(sp types.SharedSpec) *mysqlSharedParams {
return &mysqlSharedParams{
ID: sp.ID,
GasOverEstimation: sp.GasOverEstimation,
Expand Down Expand Up @@ -73,7 +73,7 @@ func (s mysqlSharedParamsRepo) SetSharedParams(ctx context.Context, params *type
if params.ID == 0 {
params.ID = 1
}
if err := s.DB.Save(FromSharedParams(*params)).Error; err != nil {
if err := s.DB.Save(fromSharedParams(*params)).Error; err != nil {
return 0, err
}
return params.ID, nil
Expand Down
4 changes: 2 additions & 2 deletions models/sqlite/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (s sqliteAddress) TableName() string {
return "addresses"
}

func FromAddress(addr *types.Address) *sqliteAddress {
func fromAddress(addr *types.Address) *sqliteAddress {
sqliteAddr := &sqliteAddress{
ID: addr.ID,
Addr: addr.Addr.String(),
Expand Down Expand Up @@ -92,7 +92,7 @@ func newSqliteAddressRepo(db *gorm.DB) *sqliteAddressRepo {
}

func (s sqliteAddressRepo) SaveAddress(ctx context.Context, addr *types.Address) error {
return s.DB.Save(FromAddress(addr)).Error
return s.DB.Save(fromAddress(addr)).Error
}

func (s sqliteAddressRepo) GetAddress(ctx context.Context, addr address.Address) (*types.Address, error) {
Expand Down
6 changes: 3 additions & 3 deletions models/sqlite/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (sqlMsg *sqliteMessage) Message() *types.Message {
return destMsg
}

func FromMessage(srcMsg *types.Message) *sqliteMessage {
func fromMessage(srcMsg *types.Message) *sqliteMessage {
destMsg := &sqliteMessage{
ID: srcMsg.ID,
Version: srcMsg.Version,
Expand Down Expand Up @@ -261,15 +261,15 @@ func (m *sqliteMessageRepo) BatchSaveMessage(msgs []*types.Message) error {
}

func (m *sqliteMessageRepo) CreateMessage(msg *types.Message) error {
sqlMsg := FromMessage(msg)
sqlMsg := fromMessage(msg)
sqlMsg.CreatedAt = time.Now()
sqlMsg.UpdatedAt = time.Now()
return m.DB.Create(sqlMsg).Error
}

// SaveMessage used to update message and create message with CreateMessage
func (m *sqliteMessageRepo) SaveMessage(msg *types.Message) error {
sqlMsg := FromMessage(msg)
sqlMsg := fromMessage(msg)
sqlMsg.UpdatedAt = time.Now()

return m.DB.Omit("created_at").Save(sqlMsg).Error
Expand Down
Loading

0 comments on commit 7a62592

Please sign in to comment.