Skip to content

Commit

Permalink
Merge pull request #237 from lbbniu/feat/lbbniu/golangci-lint
Browse files Browse the repository at this point in the history
feat: 添加golangci-lint,并修复lint检查
  • Loading branch information
aceld authored Jun 9, 2023
2 parents 5c02636 + 7b96b31 commit 37b1fe5
Show file tree
Hide file tree
Showing 53 changed files with 230 additions and 166 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: reviewdog
on: [pull_request]
jobs:
golangci-lint:
runs-on: ubuntu-latest
name: runner / golangci-lint
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: golangci-lint
uses: reviewdog/action-golangci-lint@v2
with:
github_token: ${{ secrets.github_token }}
# Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review].
reporter: github-pr-review
# Report all results.
filter_mode: nofilter
# Exit with 1 when it finds at least one finding.
fail_on_error: true
#golangci_lint_flags
28 changes: 28 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
run:
timeout: 30m
skip-dirs:
- examples

linters:
disable-all: true
enable:
#- unused
- ineffassign
- goimports
- gofmt
- misspell
- unparam
- unconvert
- govet
# - errcheck
- staticcheck

linters-settings:
staticcheck:
go: "1.16"
checks:
- "all"
- "-SA1019"

unused:
go: "1.16"
1 change: 1 addition & 0 deletions logo/zinxlogo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package logo

import (
"fmt"

"github.com/aceld/zinx/zconf"
)

Expand Down
1 change: 1 addition & 0 deletions zasync_op/async_op_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@Author:14March
@File:async_op_result.go
*/

package zasync_op

import (
Expand Down
1 change: 1 addition & 0 deletions zasync_op/async_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@Author:14March
@File:async_worker.go
*/

package zasync_op

import "github.com/aceld/zinx/zlog"
Expand Down
7 changes: 4 additions & 3 deletions zconf/globalobj.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ package zconf
import (
"encoding/json"
"fmt"
"github.com/aceld/zinx/zlog"
"github.com/aceld/zinx/zutils/commandline/args"
"github.com/aceld/zinx/zutils/commandline/uflag"
"io/ioutil"
"os"
"reflect"
"testing"
"time"

"github.com/aceld/zinx/zlog"
"github.com/aceld/zinx/zutils/commandline/args"
"github.com/aceld/zinx/zutils/commandline/uflag"
)

const (
Expand Down
3 changes: 1 addition & 2 deletions zdecoder/crc.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ var crc16_l = []byte{
func GetCrC(buff []byte) []byte {
var hi uint16 = 0x00ff
var low uint16 = 0x00ff
var pos uint16 = 0

for i := 0; i < len(buff); i++ {
pos = (low ^ uint16(buff[i])) & 0x00ff
pos := (low ^ uint16(buff[i])) & 0x00ff
low = hi ^ uint16(crc16_h[pos])
hi = uint16(crc16_l[pos])
}
Expand Down
3 changes: 2 additions & 1 deletion zdecoder/htlvcrcdecoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ package zdecoder

import (
"encoding/hex"
"math"

"github.com/aceld/zinx/ziface"
"github.com/aceld/zinx/zlog"
"math"
)

const HEADER_SIZE = 5
Expand Down
3 changes: 2 additions & 1 deletion zdecoder/ltvdecoder_little.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ package zdecoder
import (
"bytes"
"encoding/binary"
"github.com/aceld/zinx/ziface"
"math"

"github.com/aceld/zinx/ziface"
)

const LTV_HEADER_SIZE = 8 //表示TLV空包长度
Expand Down
3 changes: 2 additions & 1 deletion zdecoder/tlvdecoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ package zdecoder
import (
"bytes"
"encoding/binary"
"github.com/aceld/zinx/ziface"
"math"

"github.com/aceld/zinx/ziface"
)

const TLV_HEADER_SIZE = 8 //表示TLV空包长度
Expand Down
1 change: 1 addition & 0 deletions ziface/iclient.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @Title iclient.go
// @Description Provides all interface declarations for the Client abstraction layer.
// @Author Aceld - 2023-2-28

package ziface

import "time"
Expand Down
2 changes: 1 addition & 1 deletion ziface/iconnmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package ziface

/*
Connection Management Abstract Layer
IConnManager Connection Management Abstract Layer
*/
type IConnManager interface {
Add(IConnection) // Add connection
Expand Down
8 changes: 4 additions & 4 deletions ziface/idatapack.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
package ziface

/*
Package and unpack data.
Operating on the data stream of TCP connections, add header information to transfer data, and solve TCP sticky packets.
(封包数据和拆包数据
直接面向TCP连接中的数据流,为传输数据添加头部信息,用于处理TCP粘包问题。)
IDataPack Package and unpack data.
Operating on the data stream of TCP connections, add header information to transfer data, and solve TCP sticky packets.
(封包数据和拆包数据
直接面向TCP连接中的数据流,为传输数据添加头部信息,用于处理TCP粘包问题。)
*/
type IDataPack interface {
GetHeadLen() uint32 // Get the length of the message header(获取包头长度方法)
Expand Down
4 changes: 1 addition & 3 deletions ziface/imessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// @Author Aceld - Thu Mar 11 10:32:29 CST 2019
package ziface

/*
Package ziface defines an abstract interface for encapsulating a request message into a message
*/
// IMessage Package ziface defines an abstract interface for encapsulating a request message into a message
type IMessage interface {
GetDataLen() uint32 // Gets the length of the message data segment(获取消息数据段长度)
GetMsgID() uint32 // Gets the ID of the message(获取消息ID)
Expand Down
4 changes: 1 addition & 3 deletions ziface/imsghandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// @Author Aceld - Thu Mar 11 10:32:29 CST 2019
package ziface

/*
Abstract layer of message management(消息管理抽象层)
*/
// IMsgHandle Abstract layer of message management(消息管理抽象层)
type IMsgHandle interface {
// Add specific handling logic for messages, msgID supports int and string types
// (为消息添加具体的处理逻辑, msgID,支持整型,字符串)
Expand Down
8 changes: 3 additions & 5 deletions ziface/irequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ type IFuncRequest interface {
CallFunc()
}

/*
IRequest interface:
It actually packages the connection information and request data of the client request into Request
(实际上是把客户端请求的链接信息 和 请求的数据 包装到了 Request里)
*/
// IRequest interface:
// It actually packages the connection information and request data of the client request into Request
// (实际上是把客户端请求的链接信息 和 请求的数据 包装到了 Request里)
type IRequest interface {
GetConnection() IConnection // Get the connection information of the request(获取请求连接信息)

Expand Down
8 changes: 5 additions & 3 deletions zinterceptor/framedocder.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (
"bytes"
"encoding/binary"
"fmt"
"github.com/aceld/zinx/ziface"
"math"
"sync"

"github.com/aceld/zinx/ziface"
)

// FrameDecoder
Expand Down Expand Up @@ -398,10 +399,10 @@ func (d *FrameDecoder) getUnadjustedFrameLength(buf *bytes.Buffer, offset int, l
case 3:
//int占32位,这里取出后24位,返回int类型
if order == binary.LittleEndian {
n := uint(uint(arr[0]) | uint(arr[1])<<8 | uint(arr[2])<<16)
n := uint(arr[0]) | uint(arr[1])<<8 | uint(arr[2])<<16
frameLength = int64(n)
} else {
n := uint(uint(arr[2]) | uint(arr[1])<<8 | uint(arr[0])<<16)
n := uint(arr[2]) | uint(arr[1])<<8 | uint(arr[0])<<16
frameLength = int64(n)
}
case 4:
Expand Down Expand Up @@ -492,6 +493,7 @@ func (d *FrameDecoder) decode(buf []byte) []byte {
actualLengthFieldOffset := d.LengthFieldOffset
//获取长度字段的值,不包括lengthAdjustment的调整值
frameLength := d.getUnadjustedFrameLength(in, actualLengthFieldOffset, d.LengthFieldLength, d.Order)

//如果数据帧长度小于0,说明是个错误的数据包
if frameLength < 0 {
//内部会跳过这个数据包的字节数,并抛异常
Expand Down
2 changes: 1 addition & 1 deletion zinx_app_demo/mmo_game/api/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/golang/protobuf/proto"
)

//玩家移动
// MoveApi 玩家移动
type MoveApi struct {
znet.BaseRouter
}
Expand Down
2 changes: 1 addition & 1 deletion zinx_app_demo/mmo_game/api/world_chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/golang/protobuf/proto"
)

//世界聊天 路由业务
// WorldChatApi 世界聊天 路由业务
type WorldChatApi struct {
znet.BaseRouter
}
Expand Down
5 changes: 4 additions & 1 deletion zinx_app_demo/mmo_game/client_AI_robot.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build robot
// +build robot

package main

import (
Expand Down Expand Up @@ -155,7 +158,7 @@ func (this *TcpClient) AIRobotAction() {
}

/*
处理一个回执业务
处理一个回执业务
*/
func (this *TcpClient) DoMsg(msg *Message) {
//处理消息
Expand Down
26 changes: 13 additions & 13 deletions zinx_app_demo/mmo_game/core/aoi.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const (
)

/*
AOI管理模块
AOIManager AOI管理模块
*/
type AOIManager struct {
MinX int //区域左边界坐标
Expand All @@ -25,7 +25,7 @@ type AOIManager struct {
}

/*
初始化一个AOI区域
初始化一个AOI区域
*/
func NewAOIManager(minX, maxX, cntsX, minY, maxY, cntsY int) *AOIManager {
aoiMgr := &AOIManager{
Expand Down Expand Up @@ -57,17 +57,17 @@ func NewAOIManager(minX, maxX, cntsX, minY, maxY, cntsY int) *AOIManager {
return aoiMgr
}

//得到每个格子在x轴方向的宽度
// 得到每个格子在x轴方向的宽度
func (m *AOIManager) grIDWIDth() int {
return (m.MaxX - m.MinX) / m.CntsX
}

//得到每个格子在x轴方向的长度
// 得到每个格子在x轴方向的长度
func (m *AOIManager) grIDLength() int {
return (m.MaxY - m.MinY) / m.CntsY
}

//打印信息方法
// 打印信息方法
func (m *AOIManager) String() string {
s := fmt.Sprintf("AOIManagr:\nminX:%d, maxX:%d, cntsX:%d, minY:%d, maxY:%d, cntsY:%d\n GrIDs in AOI Manager:\n",
m.MinX, m.MaxX, m.CntsX, m.MinY, m.MaxY, m.CntsY)
Expand All @@ -78,7 +78,7 @@ func (m *AOIManager) String() string {
return s
}

//根据格子的gID得到当前周边的九宫格信息
// 根据格子的gID得到当前周边的九宫格信息
func (m *AOIManager) GetSurroundGrIDsByGID(gID int) (grIDs []*GrID) {
//判断gID是否存在
if _, ok := m.grIDs[gID]; !ok {
Expand Down Expand Up @@ -117,15 +117,15 @@ func (m *AOIManager) GetSurroundGrIDsByGID(gID int) (grIDs []*GrID) {
return
}

//通过横纵坐标获取对应的格子ID
// 通过横纵坐标获取对应的格子ID
func (m *AOIManager) GetGIDByPos(x, y float32) int {
gx := (int(x) - m.MinX) / m.grIDWIDth()
gy := (int(y) - m.MinY) / m.grIDLength()

return gy*m.CntsX + gx
}

//通过横纵坐标得到周边九宫格内的全部PlayerIDs
// 通过横纵坐标得到周边九宫格内的全部PlayerIDs
func (m *AOIManager) GetPIDsByPos(x, y float32) (playerIDs []int) {
//根据横纵坐标得到当前坐标属于哪个格子ID
gID := m.GetGIDByPos(x, y)
Expand All @@ -140,30 +140,30 @@ func (m *AOIManager) GetPIDsByPos(x, y float32) (playerIDs []int) {
return
}

//通过GID获取当前格子的全部playerID
// 通过GID获取当前格子的全部playerID
func (m *AOIManager) GetPIDsByGID(gID int) (playerIDs []int) {
playerIDs = m.grIDs[gID].GetPlyerIDs()
return
}

//移除一个格子中的PlayerID
// 移除一个格子中的PlayerID
func (m *AOIManager) RemovePIDFromGrID(pID, gID int) {
m.grIDs[gID].Remove(pID)
}

//添加一个PlayerID到一个格子中
// 添加一个PlayerID到一个格子中
func (m *AOIManager) AddPIDToGrID(pID, gID int) {
m.grIDs[gID].Add(pID)
}

//通过横纵坐标添加一个Player到一个格子中
// 通过横纵坐标添加一个Player到一个格子中
func (m *AOIManager) AddToGrIDByPos(pID int, x, y float32) {
gID := m.GetGIDByPos(x, y)
grID := m.grIDs[gID]
grID.Add(pID)
}

//通过横纵坐标把一个Player从对应的格子中删除
// 通过横纵坐标把一个Player从对应的格子中删除
func (m *AOIManager) RemoveFromGrIDByPos(pID int, x, y float32) {
gID := m.GetGIDByPos(x, y)
grID := m.grIDs[gID]
Expand Down
2 changes: 1 addition & 1 deletion zinx_app_demo/mmo_game/core/aoi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestNewAOIManager(t *testing.T) {
func TestAOIManagerSuroundGrIDsByGID(t *testing.T) {
aoiMgr := NewAOIManager(0, 250, 5, 0, 250, 5)

for k, _ := range aoiMgr.grIDs {
for k := range aoiMgr.grIDs {
//得到当前格子周边的九宫格
grIDs := aoiMgr.GetSurroundGrIDsByGID(k)
//得到九宫格所有的IDs
Expand Down
Loading

0 comments on commit 37b1fe5

Please sign in to comment.