diff --git a/.github/pre-commit b/.github/pre-commit new file mode 100644 index 0000000..dea99a9 --- /dev/null +++ b/.github/pre-commit @@ -0,0 +1,23 @@ +#!/bin/sh +# Copyright 2021 ecodeclub +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# To use, store as .git/hooks/pre-commit inside your repository and make sure +# it has execute permissions. +# +# This script does not handle file names that contain spaces. + +# Pre-commit configuration + +exit 0 \ No newline at end of file diff --git a/.github/pre-push b/.github/pre-push new file mode 100644 index 0000000..f836559 --- /dev/null +++ b/.github/pre-push @@ -0,0 +1,50 @@ +#!/bin/sh +# Copyright 2021 ecodeclub +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# git test pre-push hook +# +# To use, store as .git/hooks/pre-push inside your repository and make sure +# it has execute permissions. +# +# This script does not handle file names that contain spaces. + +# Pre-push configuration +remote=$1 +url=$2 +echo >&2 "Try pushing $2 to $1" + +TEST="go test ./... -race -cover -failfast" +LINTER="golangci-lint run -c .golangci.yml" + +# Run test and return if failed +printf "Running go test..." +$TEST +RESULT=$? +if [ $RESULT -ne 0 ]; then + echo >&2 "$TEST" + echo >&2 "Check code to pass test." + exit 1 +fi + +# Run linter and return if failed +printf "Running go linter..." +$LINTER +RESULT=$? +if [ $RESULT -ne 0 ]; then + echo >&2 "$LINTER" + echo >&2 "Check code to pass linter." + exit 1 +fi + +exit 0 \ No newline at end of file diff --git a/.github/workflows/go-fmt.yml b/.github/workflows/go-fmt.yml new file mode 100644 index 0000000..7d4669e --- /dev/null +++ b/.github/workflows/go-fmt.yml @@ -0,0 +1,44 @@ +# Copyright 2021 ecodeclub +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Format Go code + +on: + push: + branches: [ main,dev ] + pull_request: + branches: [ main,dev ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: ">=1.20.0" + + - name: Install goimports + run: | + go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest && \ + go install golang.org/x/tools/cmd/goimports@latest + + - name: Check + run: | + make check + if [ -n "$(git status --porcelain)" ]; then + echo >&2 "错误: 请在本地运行命令'make check'后再提交." + exit 1 + fi \ No newline at end of file diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..03bbc73 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,40 @@ +# Copyright 2021 ecodeclub +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Go + +on: + push: + branches: [ dev ] + pull_request: + branches: [ dev ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ">=1.21.0" + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -race -coverprofile=cover.out -v ./... + + - name: Post Coverage + uses: codecov/codecov-action@v3 diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..e344aae --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,57 @@ +# Copyright 2021 ecodeclub +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: golangci-lint +on: + push: + branches: [dev, main] + pull_request: + branches: [dev, main] +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + pull-requests: read +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v3 + with: + go-version: ">=1.20.0" + - uses: actions/checkout@v4 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: latest + + # Optional: working directory, useful for monorepos + # working-directory: somedir + + # Optional: golangci-lint command line arguments. + # args: -c .golangci.yml + + # Optional: show only new issues if it's a pull request. The default value is `false`. + only-new-issues: true + + # Optional: if set to true then the all caching functionality will be complete disabled, + # takes precedence over all other caching options. + # skip-cache: true + + # Optional: if set to true then the action don't cache or restore ~/go/pkg. + # skip-pkg-cache: true + + # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. + # skip-build-cache: true \ No newline at end of file diff --git a/.github/workflows/license.yml b/.github/workflows/license.yml new file mode 100644 index 0000000..8440474 --- /dev/null +++ b/.github/workflows/license.yml @@ -0,0 +1,28 @@ +# Copyright 2021 ecodeclub +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Check License Lines +on: + pull_request: + types: [opened, synchronize, reopened, labeled, unlabeled] + branches: + - main + - dev +jobs: + check-license-lines: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Check License Lines + uses: kt3k/license_checker@v1.0.6 \ No newline at end of file diff --git a/.github/workflows/notify-go.yml b/.github/workflows/notify-go.yml deleted file mode 100644 index bcc3ebe..0000000 --- a/.github/workflows/notify-go.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Go - -on: - push: - branches: [ dev ] - pull_request: - branches: [ dev ] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.21.3 - - - name: Build - run: go build -v ./... - - - name: Test - run: go test -race -coverprofile=cover.out -v ./... - - - name: Post Coverage - uses: codecov/codecov-action@v3 - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..7a3b508 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,18 @@ +# Copyright 2021 ecodeclub +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +run: + go: '1.21' + skip-dirs: + - .idea \ No newline at end of file diff --git a/.licenserc.json b/.licenserc.json new file mode 100644 index 0000000..87cb298 --- /dev/null +++ b/.licenserc.json @@ -0,0 +1,5 @@ +{ + "**/*.go": "// Copyright 2021 ecodeclub", + "**/*.{yml}": "# Copyright 2021 ecodeclub", + "**/*.sh": "# Copyright 2021 ecodeclub" +} \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a203921 --- /dev/null +++ b/Makefile @@ -0,0 +1,29 @@ +.PHONY: bench +bench: + @go test -bench=. -benchmem ./... + +.PHONY: ut +ut: + @go test -race ./... -failfast + +.PHONY: setup +setup: + @sh ./script/setup.sh + +.PHONY: fmt +fmt: + @goimports -l -w $$(find . -type f -name '*.go' -not -path "./.idea/*") + +.PHONY: lint +lint: + @golangci-lint run -c .golangci.yml + +.PHONY: tidy +tidy: + @go mod tidy -v + +.PHONY: check +check: + @$(MAKE) fmt + @$(MAKE) tidy + @$(MAKE) lint \ No newline at end of file diff --git a/README.md b/README.md index a255a84..037fbde 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Go](https://github.com/hookokoko/notify-go_dev/actions/workflows/notify-go.yml/badge.svg?branch=dev)](https://github.com/hookokoko/notify-go_dev/actions/workflows/notify-go.yml) +[![Go](https://github.com/hookokoko/notify-go_dev/actions/workflows/go.yml/badge.svg?branch=dev)](https://github.com/hookokoko/notify-go_dev/actions/workflows/notify-go.yml) [![codecov](https://codecov.io/github/hookokoko/notify-go_dev/graph/badge.svg?token=H9D9S5Y2VM)](https://codecov.io/github/hookokoko/notify-go_dev) # notify-go diff --git a/channel/channel.go b/channel/channel.go index 4206efd..8d7ed36 100644 --- a/channel/channel.go +++ b/channel/channel.go @@ -1,3 +1,17 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package channel import ( diff --git a/channel/email/email.go b/channel/email/email.go index 32f875e..ba1ebe7 100644 --- a/channel/email/email.go +++ b/channel/email/email.go @@ -1,3 +1,17 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package email import ( diff --git a/channel/email/email_test.go b/channel/email/email_test.go deleted file mode 100644 index 517e53c..0000000 --- a/channel/email/email_test.go +++ /dev/null @@ -1,29 +0,0 @@ -package email - -import ( - "testing" -) - -func TestSend(t *testing.T) { - //e := NewEmailChannel(Config{ - // SenderAddress: "Hooko ", - // SmtpHostAddr: "gz-smtp.qcloudmail.com:465", - // SmtpUserName: "hooko_1@cooode.fun", - // SmtpPwd: "xxx", - //}) - // - //deli := notifier.Delivery{ - // Receivers: []notifier.Receiver{ - // {Email: "648646891@qq.com"}, - // }, - // Content: notifier.Content{ - // Title: "发送主题-测试", - // Data: []byte("\n\n\n\nhello world\n\n\n " + - // "

我的第一个标题

\n

我的第一个段落。

\n\n"), - // }, - //} - //ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) - //defer cancel() - //err := e.Execute(ctx, deli) - //t.Log(err) -} diff --git a/channel/push/push.go b/channel/push/push.go index 5bf127e..b1ccba6 100644 --- a/channel/push/push.go +++ b/channel/push/push.go @@ -1,16 +1,31 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package push import ( "context" "crypto/sha256" "fmt" + "strconv" + "time" + "github.com/ecodeclub/ekit/slice" "github.com/ecodeclub/notify-go/pkg/notifier" "github.com/ecodeclub/notify-go/pkg/ral" "github.com/pborman/uuid" "github.com/pkg/errors" - "strconv" - "time" ) type Config struct { diff --git a/channel/sms/sms.go b/channel/sms/sms.go index 6cf0e87..94d7b63 100644 --- a/channel/sms/sms.go +++ b/channel/sms/sms.go @@ -1,3 +1,17 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package sms import ( diff --git a/content/content.go b/content/content.go index 78c6616..d007076 100644 --- a/content/content.go +++ b/content/content.go @@ -1,3 +1,17 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package content import ( @@ -40,7 +54,7 @@ func (s *Service) GetContent(ctx context.Context, receivers []notifier.Receiver, // 通过模版渲染出发送内容 cont, err = s.renderContent(ctx, tpl, variable) - return cont, nil + return cont, err } func (s *Service) renderContent(ctx context.Context, tpl string, diff --git a/content/template.go b/content/template.go index 30f612d..3caa6bb 100644 --- a/content/template.go +++ b/content/template.go @@ -1 +1,15 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package content diff --git a/example/base/main.go b/example/base/main.go index b00327a..47a6c5a 100644 --- a/example/base/main.go +++ b/example/base/main.go @@ -1,18 +1,33 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package main import ( "context" + "log" + "time" + "github.com/BurntSushi/toml" "github.com/ecodeclub/ekit/slice" - notify_go "github.com/ecodeclub/notify-go" + notifygo "github.com/ecodeclub/notify-go" "github.com/ecodeclub/notify-go/channel" "github.com/ecodeclub/notify-go/channel/push" "github.com/ecodeclub/notify-go/pkg/notifier" "github.com/ecodeclub/notify-go/pkg/ral" "github.com/ecodeclub/notify-go/queue" "github.com/ecodeclub/notify-go/queue/kafka" - "log" - "time" ) var ( @@ -77,7 +92,7 @@ func sendPushSync(recvs []notifier.Receiver, msg notifier.Content) { // 同步发送 syncChannel := channel.SyncChannel{IChannel: push.NewPushChannel(pushConfig, ral.NewClient(getui))} - n := notify_go.NewNotification(syncChannel, recvs, msg) + n := notifygo.NewNotification(syncChannel, recvs, msg) err := n.Send(context.TODO()) if err != nil { log.Fatal(err) @@ -87,7 +102,7 @@ func sendPushSync(recvs []notifier.Receiver, msg notifier.Content) { func sendPushAsync(q queue.IQueue, recvs []notifier.Receiver, msg notifier.Content) { // 异步发送 asyncChannel := channel.AsyncChannel{Queue: q, IChannel: push.NewPushChannel(pushConfig, ral.NewClient(getui))} - n := notify_go.NewNotification(asyncChannel, recvs, msg) + n := notifygo.NewNotification(asyncChannel, recvs, msg) err := n.Send(context.TODO()) if err != nil { log.Fatal(err) @@ -97,9 +112,9 @@ func sendPushAsync(q queue.IQueue, recvs []notifier.Receiver, msg notifier.Conte func triggerSend(q queue.IQueue, recvs []notifier.Receiver, msg notifier.Content) { // 异步发送 asyncChannel := channel.AsyncChannel{Queue: q, IChannel: push.NewPushChannel(pushConfig, ral.NewClient(getui))} - n := notify_go.NewNotification(asyncChannel, recvs, msg) + n := notifygo.NewNotification(asyncChannel, recvs, msg) - task := notify_go.NewTriggerTask(n, time.Now().Add(time.Minute)) + task := notifygo.NewTriggerTask(n, time.Now().Add(time.Minute)) task.Send(context.TODO()) <-task.Err } diff --git a/notification.go b/notification.go index 45017e0..5fad21c 100644 --- a/notification.go +++ b/notification.go @@ -1,3 +1,17 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package notify_go import ( diff --git a/pkg/error/error.go b/pkg/error/error.go index b04c6b8..8cef45f 100644 --- a/pkg/error/error.go +++ b/pkg/error/error.go @@ -1 +1,15 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package error diff --git a/pkg/log/log.go b/pkg/log/log.go index 345a12b..122f782 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -1,3 +1,17 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package log import ( diff --git a/pkg/notifier/channel.go b/pkg/notifier/channel.go index 266d8ee..94b23df 100644 --- a/pkg/notifier/channel.go +++ b/pkg/notifier/channel.go @@ -1,3 +1,17 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package notifier import "context" diff --git a/pkg/notifier/content.go b/pkg/notifier/content.go index b6f8ad3..7797d99 100644 --- a/pkg/notifier/content.go +++ b/pkg/notifier/content.go @@ -1,3 +1,17 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package notifier type Content struct { diff --git a/pkg/notifier/recevicer.go b/pkg/notifier/recevicer.go index 525e3d2..ed90636 100644 --- a/pkg/notifier/recevicer.go +++ b/pkg/notifier/recevicer.go @@ -1,3 +1,17 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package notifier type Receiver struct { diff --git a/pkg/ral/ral.go b/pkg/ral/ral.go index afb0833..b295e00 100644 --- a/pkg/ral/ral.go +++ b/pkg/ral/ral.go @@ -1,3 +1,17 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package ral import ( diff --git a/pkg/ral/record.go b/pkg/ral/record.go index 4600caa..01c4882 100644 --- a/pkg/ral/record.go +++ b/pkg/ral/record.go @@ -1,3 +1,17 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package ral import ( diff --git a/pkg/ral/service.go b/pkg/ral/service.go index aedbcb0..2171c49 100644 --- a/pkg/ral/service.go +++ b/pkg/ral/service.go @@ -1,8 +1,23 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package ral import ( - "github.com/BurntSushi/toml" "log" + + "github.com/BurntSushi/toml" ) type Service struct { diff --git a/queue/kafka/balancer.go b/queue/kafka/balancer.go index 0892a0a..afd7c91 100644 --- a/queue/kafka/balancer.go +++ b/queue/kafka/balancer.go @@ -1,3 +1,17 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package kafka import ( diff --git a/queue/kafka/kafka.go b/queue/kafka/kafka.go index f03d0e8..ca6c292 100644 --- a/queue/kafka/kafka.go +++ b/queue/kafka/kafka.go @@ -1,13 +1,28 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package kafka import ( "context" "encoding/json" - "github.com/ecodeclub/notify-go/pkg/log" "log/slog" "sync" "time" + "github.com/ecodeclub/notify-go/pkg/log" + "github.com/IBM/sarama" "github.com/ecodeclub/notify-go/pkg/notifier" ) diff --git a/queue/queue.go b/queue/queue.go index df64026..a60a37c 100644 --- a/queue/queue.go +++ b/queue/queue.go @@ -1,3 +1,17 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package queue import ( diff --git a/script/setup.sh b/script/setup.sh new file mode 100644 index 0000000..50647ef --- /dev/null +++ b/script/setup.sh @@ -0,0 +1,36 @@ +# Copyright 2021 ecodeclub +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +SOURCE_COMMIT=.github/pre-commit +TARGET_COMMIT=.git/hooks/pre-commit +SOURCE_PUSH=.github/pre-push +TARGET_PUSH=.git/hooks/pre-push + +# copy pre-commit file if not exist. +#echo "设置 git pre-commit hooks..." +#cp $SOURCE_COMMIT $TARGET_COMMIT + +# copy pre-push file if not exist. +echo "设置 git pre-push hooks..." +cp $SOURCE_PUSH $TARGET_PUSH + +# add permission to TARGET_PUSH and TARGET_COMMIT file. +test -x $TARGET_PUSH || chmod +x $TARGET_PUSH +#test -x $TARGET_COMMIT || chmod +x $TARGET_COMMIT + +echo "安装 golangci-lint..." +go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + +echo "安装 goimports..." +go install golang.org/x/tools/cmd/goimports@latest \ No newline at end of file diff --git a/store/mysql/db.go b/store/mysql/db.go index b29abef..e560010 100644 --- a/store/mysql/db.go +++ b/store/mysql/db.go @@ -1,7 +1,22 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package mysql import ( "log/slog" + "xorm.io/xorm" ) diff --git a/store/mysql/model.go b/store/mysql/model.go index 6c229bf..ed7d534 100644 --- a/store/mysql/model.go +++ b/store/mysql/model.go @@ -1,3 +1,17 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package mysql import ( diff --git a/store/mysql/type.go b/store/mysql/type.go index 37cbb6c..6eee371 100644 --- a/store/mysql/type.go +++ b/store/mysql/type.go @@ -1,3 +1,17 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package mysql import "time" diff --git a/target/target.go b/target/target.go index 915d421..1e95366 100644 --- a/target/target.go +++ b/target/target.go @@ -1,3 +1,17 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package target import ( diff --git a/task.go b/task.go index 0633c3f..79c8f6e 100644 --- a/task.go +++ b/task.go @@ -1,3 +1,17 @@ +// Copyright 2021 ecodeclub +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package notify_go import ( @@ -40,10 +54,9 @@ func (tt *TriggerTask) Send(ctx context.Context) *TriggerTask { case <-ctx.Done(): tt.Err <- ctx.Err() return tt - case <-time.After(tt.TriggerTime.Sub(time.Now())): + case <-time.After(time.Until(tt.TriggerTime)): err := tt.Notification.Send(ctx) tt.Err <- err - default: } } } diff --git a/tool/tool.go b/tool/tool.go deleted file mode 100644 index 9001287..0000000 --- a/tool/tool.go +++ /dev/null @@ -1,16 +0,0 @@ -package tool - -import ( - "math/rand" - "time" -) - -// RandIntN 生成指定范围内的随机整数 -func RandIntN(min, max int) int { - // 初始化随机数生成器 - rand.Seed(time.Now().UnixNano()) - - randomNumber := rand.Intn(max-min+1) + min - - return randomNumber -}