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
|
go tool cover -html=./sdk.cover -o ./sdk.html
|
||||||
fmt:
|
fmt:
|
||||||
find ./ -name "*.go" | xargs gofmt -w
|
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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,17 +6,19 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
|
|
||||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/chatbot"
|
"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/handler"
|
||||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/logger"
|
"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/payload"
|
||||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/plugin"
|
"github.com/open-dingtalk/dingtalk-stream-sdk-go/plugin"
|
||||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/utils"
|
"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 ttype, subs := range cli.subscriptions {
|
||||||
for ttopic, _ := range subs {
|
for ttopic := range subs {
|
||||||
requestModel.Subscriptions = append(requestModel.Subscriptions, &payload.SubscriptionModel{
|
requestModel.Subscriptions = append(requestModel.Subscriptions, &payload.SubscriptionModel{
|
||||||
Type: ttype,
|
Type: ttype,
|
||||||
Topic: ttopic,
|
Topic: ttopic,
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,11 @@ package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
package event
|
package event
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package event
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/logger"
|
"github.com/open-dingtalk/dingtalk-stream-sdk-go/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,9 @@ package event
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
package event
|
package event
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
||||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/utils"
|
"github.com/open-dingtalk/dingtalk-stream-sdk-go/utils"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package event
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/logger"
|
"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/payload"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,11 @@ package event
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/chatbot"
|
"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/client"
|
||||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/event"
|
"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))
|
replyMsg := []byte(fmt.Sprintf("msg received: [%s]", data.Text.Content))
|
||||||
|
|
||||||
chatbotReplier := chatbot.NewChatbotReplier()
|
chatbotReplier := chatbot.NewChatbotReplier()
|
||||||
chatbotReplier.SimpleReplyText(ctx, data.SessionWebhook, replyMsg)
|
if err := chatbotReplier.SimpleReplyText(ctx, data.SessionWebhook, replyMsg); err != nil {
|
||||||
chatbotReplier.SimpleReplyMarkdown(ctx, data.SessionWebhook, []byte("Markdown消息"), replyMsg)
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := chatbotReplier.SimpleReplyMarkdown(ctx, data.SessionWebhook, []byte("Markdown消息"), replyMsg); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return []byte(""), nil
|
return []byte(""), nil
|
||||||
}
|
}
|
||||||
|
|
@ -58,7 +63,9 @@ func OnEventReceived(ctx context.Context, df *payload.DataFrame) (frameResp *pay
|
||||||
df.Data)
|
df.Data)
|
||||||
|
|
||||||
frameResp = payload.NewSuccessDataFrameResponse()
|
frameResp = payload.NewSuccessDataFrameResponse()
|
||||||
frameResp.SetJson(event.NewEventProcessResultSuccess())
|
if err := frameResp.SetJson(event.NewEventProcessResultSuccess()); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
package logger
|
package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
package payload
|
package payload
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,9 @@ package payload
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package payload
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
package payload
|
package payload
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package plugin
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"
|
"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}
|
pluginResponse := &PluginResponse{RequestId: msgData.RequestId, Result: result}
|
||||||
callbackResponse := &CallbackResponse{Response: pluginResponse}
|
callbackResponse := &CallbackResponse{Response: pluginResponse}
|
||||||
frameResp := payload.NewSuccessDataFrameResponse()
|
frameResp := payload.NewSuccessDataFrameResponse()
|
||||||
frameResp.SetJson(callbackResponse)
|
if err = frameResp.SetJson(callbackResponse); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return frameResp, nil
|
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
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetFirstLanIP(t *testing.T) {
|
func TestGetFirstLanIP(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue