Merge pull request #11 from ronething/chore/goimports
chore: go imports and add github workflow for lint
This commit is contained in:
commit
ef2467ee84
|
|
@ -0,0 +1,51 @@
|
|||
name: Lint Check
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- release/**
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
- release/**
|
||||
permissions: read-all
|
||||
jobs:
|
||||
gofmt:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Setup Go Environment
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: '1.20.3'
|
||||
- name: Run gofmt Check
|
||||
working-directory: ./
|
||||
run: |
|
||||
diffs=`gofmt -l .`
|
||||
if [[ -n $diffs ]]; then
|
||||
echo "Files are not formatted by gofmt:"
|
||||
echo $diffs
|
||||
exit 1
|
||||
fi
|
||||
golint:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Setup Go Environment
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: '1.20.3'
|
||||
- name: Install jq
|
||||
run: sudo apt install -y jq
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: '16'
|
||||
- name: Download golangci-lint
|
||||
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2
|
||||
- name: Run Golang Linters
|
||||
working-directory: ./
|
||||
run: |
|
||||
PATH=${PATH}:$(go env GOPATH)/bin make lint
|
||||
4
Makefile
4
Makefile
|
|
@ -22,3 +22,7 @@ test:
|
|||
go tool cover -html=./sdk.cover -o ./sdk.html
|
||||
fmt:
|
||||
find ./ -name "*.go" | xargs gofmt -w
|
||||
|
||||
lint: ## Apply go lint check
|
||||
@golangci-lint run --timeout 10m ./...
|
||||
.PHONY: lint
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package chatbot
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,17 +6,19 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/chatbot"
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/handler"
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/logger"
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/plugin"
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/utils"
|
||||
"io"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
/**
|
||||
|
|
@ -279,7 +281,7 @@ func (cli *StreamClient) GetConnectionEndpoint(ctx context.Context) (*payload.Co
|
|||
}
|
||||
|
||||
for ttype, subs := range cli.subscriptions {
|
||||
for ttopic, _ := range subs {
|
||||
for ttopic := range subs {
|
||||
requestModel.Subscriptions = append(requestModel.Subscriptions, &payload.SubscriptionModel{
|
||||
Type: ttype,
|
||||
Topic: ttopic,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@ package client
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
||||
)
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package event
|
||||
|
||||
import (
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
||||
"strconv"
|
||||
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
||||
)
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package event
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/logger"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@ package event
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
package event
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/utils"
|
||||
"testing"
|
||||
)
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package event
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/logger"
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -3,9 +3,11 @@ package event
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
||||
)
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/chatbot"
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/client"
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/event"
|
||||
|
|
@ -22,8 +23,12 @@ func OnChatBotMessageReceived(ctx context.Context, data *chatbot.BotCallbackData
|
|||
replyMsg := []byte(fmt.Sprintf("msg received: [%s]", data.Text.Content))
|
||||
|
||||
chatbotReplier := chatbot.NewChatbotReplier()
|
||||
chatbotReplier.SimpleReplyText(ctx, data.SessionWebhook, replyMsg)
|
||||
chatbotReplier.SimpleReplyMarkdown(ctx, data.SessionWebhook, []byte("Markdown消息"), replyMsg)
|
||||
if err := chatbotReplier.SimpleReplyText(ctx, data.SessionWebhook, replyMsg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := chatbotReplier.SimpleReplyMarkdown(ctx, data.SessionWebhook, []byte("Markdown消息"), replyMsg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return []byte(""), nil
|
||||
}
|
||||
|
|
@ -58,7 +63,9 @@ func OnEventReceived(ctx context.Context, df *payload.DataFrame) (frameResp *pay
|
|||
df.Data)
|
||||
|
||||
frameResp = payload.NewSuccessDataFrameResponse()
|
||||
frameResp.SetJson(event.NewEventProcessResultSuccess())
|
||||
if err := frameResp.SetJson(event.NewEventProcessResultSuccess()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package handler
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package logger
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package payload
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@ package payload
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package payload
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
package payload
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package plugin
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
||||
)
|
||||
|
||||
|
|
@ -40,6 +41,8 @@ func (h *DefaultPluginFrameHandler) OnEventReceived(ctx context.Context, df *pay
|
|||
pluginResponse := &PluginResponse{RequestId: msgData.RequestId, Result: result}
|
||||
callbackResponse := &CallbackResponse{Response: pluginResponse}
|
||||
frameResp := payload.NewSuccessDataFrameResponse()
|
||||
frameResp.SetJson(callbackResponse)
|
||||
if err = frameResp.SetJson(callbackResponse); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return frameResp, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
go install github.com/incu6us/goimports-reviser/v2@latest
|
||||
|
||||
PROJECT_NAME=github.com/open-dingtalk/dingtalk-stream-sdk-go
|
||||
|
||||
find . -name '*.go' -print0 | while IFS= read -r -d '' file; do
|
||||
goimports-reviser -file-path "$file" -project-name "$PROJECT_NAME"
|
||||
done
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetFirstLanIP(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue