Skip to content

Commit

Permalink
build(golangci): add golangci configuration and fix format (#36)
Browse files Browse the repository at this point in the history
Signed-off-by: Flc゛ <[email protected]>
  • Loading branch information
flc1125 authored Mar 26, 2024
1 parent 68d1980 commit 8171442
Show file tree
Hide file tree
Showing 14 changed files with 209 additions and 118 deletions.
28 changes: 28 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
linters:
disable-all: true

enable:
- bodyclose
- dogsled
- durationcheck
- errcheck
- exportloopref
- govet
- gosimple
- gofmt
- gofumpt
- goconst
- goimports
- gomnd
- gocyclo
- ineffassign
- lll
- prealloc
- revive
- staticcheck
- typecheck
- unused
- whitespace
- wastedassign
- unconvert
- misspell
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.PHONY: init
init:
go install mvdan.cc/gofumpt@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

.PHONY: lint
lint:
golangci-lint run
@echo "✅ Linting completed"

.PHONY: fix
fix:
golangci-lint run --fix
@echo "✅ Lint fixing completed"

.PHONY: test
test:
go test ./...
@echo "✅ Testing completed"

.PHONY: fmt
fmt:
gofmt -w -e "vendor" .
@echo "✅ Formatting completed"

.PHONY: fumpt
fumpt:
gofumpt -w -e "vendor" .
@echo "✅ Formatting completed"

.PHONY: nilaway-install
nilaway-install:
go install go.uber.org/nilaway/cmd/nilaway@latest

.PHONY: nilaway
nilaway:
nilaway ./...
@echo "✅ Nilaway completed"
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "net/http"
type Config struct {
Addr string
Buin int
AppId string
AppID string
AesKey string
}

Expand All @@ -23,7 +23,7 @@ func WithEncryptor(encryptor *Encryptor) func(c *Client) {
}
}

func WithHttpClient(client *http.Client) func(c *Client) {
func WithHTTPClient(client *http.Client) func(c *Client) {
return func(c *Client) {
c.httpClient = client
}
Expand Down
32 changes: 16 additions & 16 deletions dept.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,47 @@ import (
)

type DeptItem struct {
Id int `json:"id"`
ID int `json:"id"`
Name string `json:"name"`
ParentId int `json:"parentId"`
SortId int `json:"sortId"`
ParentID int `json:"parentId"`
SortID int `json:"sortId"`
}

type DeptListResponse struct {
DeptList []DeptItem `json:"deptList"`
}

type DeptAliasItem struct {
Id int `json:"id"`
ID int `json:"id"`
Alias string `json:"alias"`
}

type DeptAliasListResponse struct {
AliasList []DeptAliasItem `json:"aliasList"`
}

type DeptIdByAliasResponse struct {
Id int `json:"id"`
type DeptIDByAliasResponse struct {
ID int `json:"id"`
}

type CreateDeptRequest struct {
Name string `json:"name"`
Alias string `json:"alias"`
Id int `json:"id"`
ParentId int `json:"parentId"`
SortId int `json:"sortId"`
ID int `json:"id"`
ParentID int `json:"parentId"`
SortID int `json:"sortId"`
}

type CreateDeptResponse struct {
Id int `json:"id"`
ID int `json:"id"`
}

type UpdateDeptRequest struct {
Name string `json:"name"`
Alias string `json:"alias"`
Id int `json:"id"`
ParentId int `json:"parentId"`
SortId int `json:"sortId"`
ID int `json:"id"`
ParentID int `json:"parentId"`
SortID int `json:"sortId"`
}

func (c *Client) GetDeptList(ctx context.Context, id ...int) (response DeptListResponse, err error) {
Expand Down Expand Up @@ -86,7 +86,7 @@ func (c *Client) GetDeptAliasList(ctx context.Context) (response DeptAliasListRe
return
}

func (c *Client) GetDeptIdByAlias(ctx context.Context, alias string) (response DeptIdByAliasResponse, err error) {
func (c *Client) GetDeptIDByAlias(ctx context.Context, alias string) (response DeptIDByAliasResponse, err error) {
opts := []requestOption{
withRequestAccessToken(),
withRequestEncrypt(),
Expand Down Expand Up @@ -130,10 +130,10 @@ func (c *Client) UpdateDept(ctx context.Context, request UpdateDeptRequest) (res
return
}

func (c *Client) DeleteDept(ctx context.Context, deptId int) (response Response, err error) {
func (c *Client) DeleteDept(ctx context.Context, deptID int) (response Response, err error) {
req, err := c.newRequest(ctx, http.MethodGet, "/cgi/dept/delete",
withRequestAccessToken(),
withRequestParamsKV("id", strconv.Itoa(deptId)),
withRequestParamsKV("id", strconv.Itoa(deptID)),
)
if err != nil {
return
Expand Down
14 changes: 7 additions & 7 deletions encryptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

type RawData struct {
AppId string
AppID string
Data []byte
Length int32
}
Expand All @@ -37,19 +37,19 @@ func NewEncryptorWithConfig(config *Config) *Encryptor {
panic(err)
}

return NewEncryptor(key, config.AppId)
return NewEncryptor(key, config.AppID)
}

func (e *Encryptor) Encrypt(plaintext []byte) (string, error) {
plainText := make([]byte, 0)

randBs := make([]byte, 16)
randBs := make([]byte, 16) // nolint:gomnd
_, err := io.ReadFull(rand.Reader, randBs)
if err != nil {
return "", err
}

lenBs := make([]byte, 4)
lenBs := make([]byte, 4) // nolint:gomnd
binary.BigEndian.PutUint32(lenBs, uint32(len(plaintext)))

plainText = append(plainText, randBs...)
Expand Down Expand Up @@ -101,8 +101,8 @@ func (e *Encryptor) Decrypt(ciphertext string) (*RawData, error) {
}

result.Data = plainText[20 : 20+result.Length]
result.AppId = string(plainText[20+result.Length:])
if len(plainText) < int(20+result.Length) {
result.AppID = string(plainText[20+result.Length:])
if len(plainText) < int(20+result.Length) { // nolint:gomnd
return nil, errors.New("invalid ciphertext")
}

Expand All @@ -117,7 +117,7 @@ type pkcs7 struct {
// newPkcs7 is used to create a new pkcs7.
func newPkcs7() *pkcs7 {
return &pkcs7{
blockSize: 32,
blockSize: 32, // nolint:gomnd
}
}

Expand Down
37 changes: 21 additions & 16 deletions group.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ type CreateGroupRequest struct {
}

type CreateGroupResponse struct {
Id string `json:"id"`
ID string `json:"id"`
}

type UpdateGroupRequest struct {
Id string `json:"id"`
ID string `json:"id"`
Name string `json:"name"`
}

type GroupUpdateMemberRequest struct {
Id string `json:"id"`
ID string `json:"id"`
UserList []string `json:"userList"`
}

Expand All @@ -30,13 +30,13 @@ type GroupInfoMember struct {
}

type GroupInfoResponse struct {
Id string `json:"id"`
ID string `json:"id"`
Name string `json:"name"`
Members []GroupInfoMember `json:"members"`
}

type GroupItem struct {
Id string `json:"id"`
ID string `json:"id"`
Name string `json:"name"`
}

Expand All @@ -48,7 +48,10 @@ type IsGroupMemberResponse struct {
Belong bool `json:"belong"`
}

func (c *Client) CreateGroup(ctx context.Context, request CreateGroupRequest) (response CreateGroupResponse, err error) {
func (c *Client) CreateGroup(
ctx context.Context,
request CreateGroupRequest,
) (response CreateGroupResponse, err error) {
req, err := c.newRequest(ctx, http.MethodPost, "/cgi/group/create",
withRequestBody(request), withRequestAccessToken(), withRequestEncrypt())
if err != nil {
Expand All @@ -59,10 +62,10 @@ func (c *Client) CreateGroup(ctx context.Context, request CreateGroupRequest) (r
return
}

func (c *Client) DeleteGroup(ctx context.Context, groupId string) (response Response, err error) {
func (c *Client) DeleteGroup(ctx context.Context, groupID string) (response Response, err error) {
req, err := c.newRequest(ctx, http.MethodGet, "/cgi/group/delete",
withRequestAccessToken(),
withRequestParamsKV("id", groupId),
withRequestParamsKV("id", groupID),
)
if err != nil {
return
Expand Down Expand Up @@ -105,11 +108,11 @@ func (c *Client) DelGroupMember(ctx context.Context, request GroupUpdateMemberRe
return
}

func (c *Client) GetGroupInfo(ctx context.Context, groupId string) (response GroupInfoResponse, err error) {
func (c *Client) GetGroupInfo(ctx context.Context, groupID string) (response GroupInfoResponse, err error) {
req, err := c.newRequest(ctx, http.MethodGet, "/cgi/group/info",
withRequestAccessToken(),
withRequestEncrypt(),
withRequestParamsKV("id", groupId),
withRequestParamsKV("id", groupID),
)
if err != nil {
return
Expand All @@ -119,14 +122,14 @@ func (c *Client) GetGroupInfo(ctx context.Context, groupId string) (response Gro
return
}

func (c *Client) GetGroupList(ctx context.Context, userId ...string) (response GroupListResponse, err error) {
func (c *Client) GetGroupList(ctx context.Context, userID ...string) (response GroupListResponse, err error) {
opts := []requestOption{
withRequestAccessToken(),
withRequestEncrypt(),
}

if len(userId) > 0 {
opts = append(opts, withRequestParamsKV("userId", userId[0]))
if len(userID) > 0 {
opts = append(opts, withRequestParamsKV("userId", userID[0]))
}

req, err := c.newRequest(ctx, http.MethodGet, "/cgi/group/list", opts...)
Expand All @@ -138,12 +141,14 @@ func (c *Client) GetGroupList(ctx context.Context, userId ...string) (response G
return
}

func (c *Client) IsGroupMember(ctx context.Context, groupId string, userId string) (response IsGroupMemberResponse, err error) {
func (c *Client) IsGroupMember(
ctx context.Context, groupID string, userID string,
) (response IsGroupMemberResponse, err error) {
req, err := c.newRequest(ctx, http.MethodGet, "/cgi/group/ismember",
withRequestAccessToken(),
withRequestEncrypt(),
withRequestParamsKV("id", groupId),
withRequestParamsKV("userId", userId),
withRequestParamsKV("id", groupID),
withRequestParamsKV("userId", userID),
)
if err != nil {
return
Expand Down
17 changes: 12 additions & 5 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,28 +124,35 @@ func (c *Client) SendMpNewsMessage(ctx context.Context, request MpNewsMessageReq
return c.SendMessage(ctx, request)
}

func (c *Client) SendLinkMessage(ctx context.Context, request LinkMessageRequest) (response Response, err error) {
func (c *Client) SendLinkMessage(
ctx context.Context, request LinkMessageRequest,
) (response Response, err error) {
request.MsgType = MsgTypeLink
return c.SendMessage(ctx, request)
}

func (c *Client) SendExLinkMessage(ctx context.Context, request ExLinkMessageRequest) (response Response, err error) {
func (c *Client) SendExLinkMessage(
ctx context.Context, request ExLinkMessageRequest,
) (response Response, err error) {
request.MsgType = MsgTypeExLink
return c.SendMessage(ctx, request)
}

func (c *Client) SendSysMessage(ctx context.Context, request MessageSysMessageRequest) (response Response, err error) {
func (c *Client) SendSysMessage(
ctx context.Context, request MessageSysMessageRequest,
) (response Response, err error) {
request.MsgType = MsgTypeSysMsg
return c.SendMessage(ctx, request)
}

func (c *Client) SendPopWindowMessage(ctx context.Context, request PopWindowMessageRequest) (response Response, err error) {
func (c *Client) SendPopWindowMessage(
ctx context.Context, request PopWindowMessageRequest,
) (response Response, err error) {
req, err := c.newRequest(ctx, http.MethodPost, "/cgi/popwindow",
withRequestBody(request),
withRequestEncrypt(),
withRequestType(SpecialRequestType),
)

if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type ReceiveRequest struct {
type ReceiveMessage struct {
FromUser string `json:"fromUser"`
CreateTime int `json:"createTime"`
PackageId string `json:"packageId"`
PackageID string `json:"packageId"`
MsgType MsgType `json:"msgType"`
Text MessageText `json:"text,omitempty"`
Image MessageMedia `json:"image,omitempty"`
Expand Down
Loading

0 comments on commit 8171442

Please sign in to comment.