diff --git a/.github/workflows/go-fmt.yml b/.github/workflows/go-fmt.yml index 81a5bb3..7d4669e 100644 --- a/.github/workflows/go-fmt.yml +++ b/.github/workflows/go-fmt.yml @@ -31,7 +31,9 @@ jobs: go-version: ">=1.20.0" - name: Install goimports - run: go install golang.org/x/tools/cmd/goimports@latest + run: | + go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest && \ + go install golang.org/x/tools/cmd/goimports@latest - name: Check run: | diff --git a/.licenserc.json b/.licenserc.json index 2bd5a5f..87cb298 100644 --- a/.licenserc.json +++ b/.licenserc.json @@ -1,5 +1,5 @@ { "**/*.go": "// Copyright 2021 ecodeclub", - "**/*.{yml,toml}": "# Copyright 2021 ecodeclub", + "**/*.{yml}": "# Copyright 2021 ecodeclub", "**/*.sh": "# Copyright 2021 ecodeclub" } \ No newline at end of file diff --git a/Makefile b/Makefile index af32a89..a203921 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ setup: .PHONY: fmt fmt: - @goimports -l -w $(find . -type f -name '*.go' -not -path "./.idea/*") + @goimports -l -w $$(find . -type f -name '*.go' -not -path "./.idea/*") .PHONY: lint lint: 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 f442038..47a6c5a 100644 --- a/example/base/main.go +++ b/example/base/main.go @@ -1,7 +1,24 @@ +// 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" notifygo "github.com/ecodeclub/notify-go" @@ -11,8 +28,6 @@ import ( "github.com/ecodeclub/notify-go/pkg/ral" "github.com/ecodeclub/notify-go/queue" "github.com/ecodeclub/notify-go/queue/kafka" - "log" - "time" ) var ( 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 index 17228da..50647ef 100644 --- a/script/setup.sh +++ b/script/setup.sh @@ -27,7 +27,7 @@ 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 +#test -x $TARGET_COMMIT || chmod +x $TARGET_COMMIT echo "安装 golangci-lint..." go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest 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 -}