diff --git a/internal/applicant/aliyun.go b/internal/applicant/aliyun.go index 6ab27e44..0b0dc61d 100644 --- a/internal/applicant/aliyun.go +++ b/internal/applicant/aliyun.go @@ -1,12 +1,13 @@ package applicant import ( - "certimate/internal/domain" "encoding/json" "fmt" "os" "github.com/go-acme/lego/v4/providers/dns/alidns" + + "certimate/internal/domain" ) type aliyun struct { @@ -20,7 +21,6 @@ func NewAliyun(option *ApplyOption) Applicant { } func (a *aliyun) Apply() (*Certificate, error) { - access := &domain.AliyunAccess{} json.Unmarshal([]byte(a.option.Access), access) diff --git a/internal/applicant/applicant.go b/internal/applicant/applicant.go index fd869f1d..2385bbad 100644 --- a/internal/applicant/applicant.go +++ b/internal/applicant/applicant.go @@ -1,8 +1,6 @@ package applicant import ( - "certimate/internal/domain" - "certimate/internal/utils/app" "crypto" "crypto/ecdsa" "crypto/elliptic" @@ -18,6 +16,9 @@ import ( "github.com/go-acme/lego/v4/lego" "github.com/go-acme/lego/v4/registration" "github.com/pocketbase/pocketbase/models" + + "certimate/internal/domain" + "certimate/internal/utils/app" ) const ( @@ -66,19 +67,21 @@ type ApplyOption struct { Timeout int64 `json:"timeout"` } -type MyUser struct { +type ApplyUser struct { Email string Registration *registration.Resource key crypto.PrivateKey } -func (u *MyUser) GetEmail() string { +func (u *ApplyUser) GetEmail() string { return u.Email } -func (u MyUser) GetRegistration() *registration.Resource { + +func (u ApplyUser) GetRegistration() *registration.Resource { return u.Registration } -func (u *MyUser) GetPrivateKey() crypto.PrivateKey { + +func (u *ApplyUser) GetPrivateKey() crypto.PrivateKey { return u.key } @@ -87,7 +90,6 @@ type Applicant interface { } func Get(record *models.Record) (Applicant, error) { - if record.GetString("applyConfig") == "" { return nil, errors.New("apply config is empty") } @@ -97,7 +99,6 @@ func Get(record *models.Record) (Applicant, error) { record.UnmarshalJSONField("applyConfig", applyConfig) access, err := app.GetApp().Dao().FindRecordById("access", applyConfig.Access) - if err != nil { return nil, fmt.Errorf("access record not found: %w", err) } @@ -129,7 +130,6 @@ func Get(record *models.Record) (Applicant, error) { default: return nil, errors.New("unknown config type") } - } type SSLProviderConfig struct { @@ -162,7 +162,7 @@ func apply(option *ApplyOption, provider challenge.Provider) (*Certificate, erro return nil, err } - myUser := MyUser{ + myUser := ApplyUser{ Email: option.Email, key: privateKey, } @@ -213,7 +213,6 @@ func apply(option *ApplyOption, provider challenge.Provider) (*Certificate, erro IssuerCertificate: string(certificates.IssuerCertificate), Csr: string(certificates.CSR), }, nil - } func getReg(client *lego.Client, sslProvider *SSLProviderConfig) (*registration.Resource, error) { diff --git a/internal/applicant/cloudflare.go b/internal/applicant/cloudflare.go index a2e9e061..75d083fd 100644 --- a/internal/applicant/cloudflare.go +++ b/internal/applicant/cloudflare.go @@ -1,12 +1,13 @@ package applicant import ( - "certimate/internal/domain" "encoding/json" "fmt" "os" cf "github.com/go-acme/lego/v4/providers/dns/cloudflare" + + "certimate/internal/domain" ) type cloudflare struct { diff --git a/internal/applicant/godaddy.go b/internal/applicant/godaddy.go index 911ee7cd..adcfe13b 100644 --- a/internal/applicant/godaddy.go +++ b/internal/applicant/godaddy.go @@ -1,12 +1,13 @@ package applicant import ( - "certimate/internal/domain" "encoding/json" "fmt" "os" godaddyProvider "github.com/go-acme/lego/v4/providers/dns/godaddy" + + "certimate/internal/domain" ) type godaddy struct { @@ -20,7 +21,6 @@ func NewGodaddy(option *ApplyOption) Applicant { } func (a *godaddy) Apply() (*Certificate, error) { - access := &domain.GodaddyAccess{} json.Unmarshal([]byte(a.option.Access), access) diff --git a/internal/applicant/huaweicloud.go b/internal/applicant/huaweicloud.go index 8da5f6ae..294e95a6 100644 --- a/internal/applicant/huaweicloud.go +++ b/internal/applicant/huaweicloud.go @@ -1,12 +1,13 @@ package applicant import ( - "certimate/internal/domain" "encoding/json" "fmt" "os" huaweicloudProvider "github.com/go-acme/lego/v4/providers/dns/huaweicloud" + + "certimate/internal/domain" ) type huaweicloud struct { @@ -20,7 +21,6 @@ func NewHuaweiCloud(option *ApplyOption) Applicant { } func (t *huaweicloud) Apply() (*Certificate, error) { - access := &domain.HuaweiCloudAccess{} json.Unmarshal([]byte(t.option.Access), access) @@ -28,7 +28,7 @@ func (t *huaweicloud) Apply() (*Certificate, error) { os.Setenv("HUAWEICLOUD_ACCESS_KEY_ID", access.AccessKeyId) os.Setenv("HUAWEICLOUD_SECRET_ACCESS_KEY", access.SecretAccessKey) os.Setenv("HUAWEICLOUD_PROPAGATION_TIMEOUT", fmt.Sprintf("%d", t.option.Timeout)) - + dnsProvider, err := huaweicloudProvider.NewDNSProvider() if err != nil { return nil, err diff --git a/internal/applicant/namesilo.go b/internal/applicant/namesilo.go index 69f6277a..0f2aa155 100644 --- a/internal/applicant/namesilo.go +++ b/internal/applicant/namesilo.go @@ -1,12 +1,13 @@ package applicant import ( - "certimate/internal/domain" "encoding/json" "fmt" "os" namesiloProvider "github.com/go-acme/lego/v4/providers/dns/namesilo" + + "certimate/internal/domain" ) type namesilo struct { @@ -20,7 +21,6 @@ func NewNamesilo(option *ApplyOption) Applicant { } func (a *namesilo) Apply() (*Certificate, error) { - access := &domain.NameSiloAccess{} json.Unmarshal([]byte(a.option.Access), access) diff --git a/internal/applicant/tencent.go b/internal/applicant/tencent.go index d7ed6dc9..705f63ad 100644 --- a/internal/applicant/tencent.go +++ b/internal/applicant/tencent.go @@ -1,12 +1,13 @@ package applicant import ( - "certimate/internal/domain" "encoding/json" "fmt" "os" "github.com/go-acme/lego/v4/providers/dns/tencentcloud" + + "certimate/internal/domain" ) type tencent struct { @@ -20,14 +21,13 @@ func NewTencent(option *ApplyOption) Applicant { } func (t *tencent) Apply() (*Certificate, error) { - access := &domain.TencentAccess{} json.Unmarshal([]byte(t.option.Access), access) os.Setenv("TENCENTCLOUD_SECRET_ID", access.SecretId) os.Setenv("TENCENTCLOUD_SECRET_KEY", access.SecretKey) os.Setenv("TENCENTCLOUD_PROPAGATION_TIMEOUT", fmt.Sprintf("%d", t.option.Timeout)) - + dnsProvider, err := tencentcloud.NewDNSProvider() if err != nil { return nil, err diff --git a/internal/deployer/aliyun.go b/internal/deployer/aliyun.go index ce8f0a2d..9c56e6df 100644 --- a/internal/deployer/aliyun.go +++ b/internal/deployer/aliyun.go @@ -1,12 +1,13 @@ package deployer import ( - "certimate/internal/domain" "context" "encoding/json" "fmt" "github.com/aliyun/aliyun-oss-go-sdk/oss" + + "certimate/internal/domain" ) type aliyun struct { @@ -28,7 +29,6 @@ func NewAliyun(option *DeployerOption) (Deployer, error) { } a.client = client return a, nil - } func (a *aliyun) GetID() string { @@ -48,13 +48,11 @@ func (a *aliyun) Deploy(ctx context.Context) error { Force: true, }, }) - if err != nil { return fmt.Errorf("deploy aliyun oss error: %w", err) } return nil - } func (a *aliyun) createClient(accessKeyId, accessKeySecret string) (*oss.Client, error) { diff --git a/internal/deployer/aliyun_cdn.go b/internal/deployer/aliyun_cdn.go index d0f1edd4..0de5959f 100644 --- a/internal/deployer/aliyun_cdn.go +++ b/internal/deployer/aliyun_cdn.go @@ -1,8 +1,6 @@ package deployer import ( - "certimate/internal/domain" - "certimate/internal/utils/rand" "context" "encoding/json" "fmt" @@ -11,6 +9,9 @@ import ( openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client" util "github.com/alibabacloud-go/tea-utils/v2/service" "github.com/alibabacloud-go/tea/tea" + + "certimate/internal/domain" + "certimate/internal/utils/rand" ) type AliyunCdn struct { @@ -46,7 +47,6 @@ func (a *AliyunCdn) GetInfo() []string { } func (a *AliyunCdn) Deploy(ctx context.Context) error { - certName := fmt.Sprintf("%s-%s-%s", a.option.Domain, a.option.DomainId, rand.RandStr(6)) setCdnDomainSSLCertificateRequest := &cdn20180510.SetCdnDomainSSLCertificateRequest{ DomainName: tea.String(getDeployString(a.option.DeployConfig, "domain")), diff --git a/internal/deployer/aliyun_esa.go b/internal/deployer/aliyun_esa.go index 27ce040f..2115d796 100644 --- a/internal/deployer/aliyun_esa.go +++ b/internal/deployer/aliyun_esa.go @@ -6,8 +6,6 @@ package deployer import ( - "certimate/internal/domain" - "certimate/internal/utils/rand" "context" "encoding/json" "fmt" @@ -16,6 +14,9 @@ import ( dcdn20180115 "github.com/alibabacloud-go/dcdn-20180115/v3/client" util "github.com/alibabacloud-go/tea-utils/v2/service" "github.com/alibabacloud-go/tea/tea" + + "certimate/internal/domain" + "certimate/internal/utils/rand" ) type AliyunEsa struct { @@ -51,7 +52,6 @@ func (a *AliyunEsa) GetInfo() []string { } func (a *AliyunEsa) Deploy(ctx context.Context) error { - certName := fmt.Sprintf("%s-%s-%s", a.option.Domain, a.option.DomainId, rand.RandStr(6)) setDcdnDomainSSLCertificateRequest := &dcdn20180115.SetDcdnDomainSSLCertificateRequest{ DomainName: tea.String(getDeployString(a.option.DeployConfig, "domain")), diff --git a/internal/deployer/deployer.go b/internal/deployer/deployer.go index 1a6497a9..d764c37d 100644 --- a/internal/deployer/deployer.go +++ b/internal/deployer/deployer.go @@ -1,9 +1,6 @@ package deployer import ( - "certimate/internal/applicant" - "certimate/internal/domain" - "certimate/internal/utils/app" "context" "encoding/json" "errors" @@ -11,6 +8,10 @@ import ( "strings" "github.com/pocketbase/pocketbase/models" + + "certimate/internal/applicant" + "certimate/internal/domain" + "certimate/internal/utils/app" ) const ( @@ -61,7 +62,6 @@ func Gets(record *models.Record, cert *applicant.Certificate) ([]Deployer, error for _, deployConfig := range deployConfigs { deployer, err := getWithDeployConfig(record, cert, deployConfig) - if err != nil { return nil, err } @@ -70,13 +70,10 @@ func Gets(record *models.Record, cert *applicant.Certificate) ([]Deployer, error } return rs, nil - } func getWithDeployConfig(record *models.Record, cert *applicant.Certificate, deployConfig domain.DeployConfig) (Deployer, error) { - access, err := app.GetApp().Dao().FindRecordById("access", deployConfig.Access) - if err != nil { return nil, fmt.Errorf("access record not found: %w", err) } @@ -169,5 +166,4 @@ func getDeployVariables(conf domain.DeployConfig) map[string]string { } return rs - } diff --git a/internal/deployer/local.go b/internal/deployer/local.go index d092db95..f358215b 100644 --- a/internal/deployer/local.go +++ b/internal/deployer/local.go @@ -10,8 +10,7 @@ import ( "runtime" ) -type localAccess struct { -} +type localAccess struct{} type local struct { option *DeployerOption diff --git a/internal/deployer/qiniu.go b/internal/deployer/qiniu.go index 637b1167..46ccee10 100644 --- a/internal/deployer/qiniu.go +++ b/internal/deployer/qiniu.go @@ -2,8 +2,6 @@ package deployer import ( "bytes" - "certimate/internal/domain" - xhttp "certimate/internal/utils/http" "context" "encoding/json" "fmt" @@ -11,6 +9,9 @@ import ( "net/http" "github.com/qiniu/go-sdk/v7/auth" + + "certimate/internal/domain" + xhttp "certimate/internal/utils/http" ) const qiniuGateway = "http://api.qiniu.com" @@ -42,7 +43,6 @@ func (q *qiuniu) GetInfo() []string { } func (q *qiuniu) Deploy(ctx context.Context) error { - // 上传证书 certId, err := q.uploadCert() if err != nil { diff --git a/internal/deployer/qiniu_test.go b/internal/deployer/qiniu_test.go index 35b0746a..38b54960 100644 --- a/internal/deployer/qiniu_test.go +++ b/internal/deployer/qiniu_test.go @@ -1,10 +1,11 @@ package deployer import ( - "certimate/internal/applicant" "testing" "github.com/qiniu/go-sdk/v7/auth" + + "certimate/internal/applicant" ) func Test_qiuniu_uploadCert(t *testing.T) { diff --git a/internal/deployer/ssh.go b/internal/deployer/ssh.go index c7a03d4c..a534b5f6 100644 --- a/internal/deployer/ssh.go +++ b/internal/deployer/ssh.go @@ -103,7 +103,6 @@ func (s *ssh) sshExecCommand(client *sshPkg.Client, command string) (error, stri } func (s *ssh) upload(client *sshPkg.Client, content, path string) error { - sftpCli, err := sftp.NewClient(client) if err != nil { return fmt.Errorf("failed to create sftp client: %w", err) @@ -129,7 +128,6 @@ func (s *ssh) upload(client *sshPkg.Client, content, path string) error { } func (s *ssh) getClient(access *sshAccess) (*sshPkg.Client, error) { - var authMethod sshPkg.AuthMethod if access.Key != "" { diff --git a/internal/deployer/ssh_test.go b/internal/deployer/ssh_test.go index 909b68e2..c9b1e85a 100644 --- a/internal/deployer/ssh_test.go +++ b/internal/deployer/ssh_test.go @@ -8,5 +8,5 @@ import ( func TestPath(t *testing.T) { dir := path.Dir("./a/b/c") - os.MkdirAll(dir, 0755) + os.MkdirAll(dir, 0o755) } diff --git a/internal/deployer/tencent_cdn.go b/internal/deployer/tencent_cdn.go index f7a5f63b..cdb185ad 100644 --- a/internal/deployer/tencent_cdn.go +++ b/internal/deployer/tencent_cdn.go @@ -1,18 +1,19 @@ package deployer import ( - "certimate/internal/domain" - "certimate/internal/utils/rand" "context" - "encoding/json" "encoding/base64" + "encoding/json" "fmt" "strings" + cdn "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn/v20180606" "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile" ssl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205" - cdn "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn/v20180606" + + "certimate/internal/domain" + "certimate/internal/utils/rand" ) type tencentCdn struct { @@ -22,7 +23,6 @@ type tencentCdn struct { } func NewTencentCdn(option *DeployerOption) (Deployer, error) { - access := &domain.TencentAccess{} if err := json.Unmarshal([]byte(option.Access), access); err != nil { return nil, fmt.Errorf("failed to unmarshal tencent access: %w", err) @@ -49,7 +49,6 @@ func (t *tencentCdn) GetInfo() []string { } func (t *tencentCdn) Deploy(ctx context.Context) error { - // 上传证书 certId, err := t.uploadCert() if err != nil { @@ -65,7 +64,6 @@ func (t *tencentCdn) Deploy(ctx context.Context) error { } func (t *tencentCdn) uploadCert() (string, error) { - cpf := profile.NewClientProfile() cpf.HttpProfile.Endpoint = "ssl.tencentcloudapi.com" @@ -92,8 +90,6 @@ func (t *tencentCdn) deploy(certId string) error { // 实例化要请求产品的client对象,clientProfile是可选的 client, _ := ssl.NewClient(t.credential, "", cpf) - - // 实例化一个请求对象,每个接口都会对应一个request对象 request := ssl.NewDeployCertificateInstanceRequest() @@ -102,7 +98,7 @@ func (t *tencentCdn) deploy(certId string) error { request.Status = common.Int64Ptr(1) // 如果是泛域名就从cdn列表下获取SSL证书中的可用域名 - if(strings.Contains(t.option.Domain, "*")){ + if strings.Contains(t.option.Domain, "*") { list, errGetList := t.getDomainList() if errGetList != nil { return fmt.Errorf("failed to get certificate domain list: %w", errGetList) @@ -111,13 +107,12 @@ func (t *tencentCdn) deploy(certId string) error { return fmt.Errorf("failed to get certificate domain list: empty list.") } request.InstanceIdList = common.StringPtrs(list) - }else{ // 否则直接使用传入的域名 + } else { // 否则直接使用传入的域名 request.InstanceIdList = common.StringPtrs([]string{t.option.Domain}) } // 返回的resp是一个DeployCertificateInstanceResponse的实例,与请求对象对应 resp, err := client.DeployCertificateInstance(request) - if err != nil { return fmt.Errorf("failed to deploy certificate: %w", err) } @@ -134,7 +129,6 @@ func (t *tencentCdn) getDomainList() ([]string, error) { cert := base64.StdEncoding.EncodeToString([]byte(t.option.Certificate.Certificate)) request.Cert = &cert - response, err := client.DescribeCertDomains(request) if err != nil { diff --git a/internal/deployer/webhook.go b/internal/deployer/webhook.go index 56486585..ce84f312 100644 --- a/internal/deployer/webhook.go +++ b/internal/deployer/webhook.go @@ -2,11 +2,12 @@ package deployer import ( "bytes" - xhttp "certimate/internal/utils/http" "context" "encoding/json" "fmt" "net/http" + + xhttp "certimate/internal/utils/http" ) type webhookAccess struct { @@ -26,7 +27,6 @@ type webhook struct { } func NewWebhook(option *DeployerOption) (Deployer, error) { - return &webhook{ option: option, infos: make([]string, 0), diff --git a/internal/domain/access.go b/internal/domain/access.go index 80cdee59..ca1df988 100644 --- a/internal/domain/access.go +++ b/internal/domain/access.go @@ -33,4 +33,3 @@ type GodaddyAccess struct { ApiKey string `json:"apiKey"` ApiSecret string `json:"apiSecret"` } - diff --git a/internal/domains/deploy.go b/internal/domains/deploy.go index 2f48434b..0f6776c6 100644 --- a/internal/domains/deploy.go +++ b/internal/domains/deploy.go @@ -1,14 +1,15 @@ package domains import ( - "certimate/internal/applicant" - "certimate/internal/deployer" - "certimate/internal/utils/app" "context" "fmt" "time" "github.com/pocketbase/pocketbase/models" + + "certimate/internal/applicant" + "certimate/internal/deployer" + "certimate/internal/utils/app" ) type Phase string diff --git a/internal/domains/domains.go b/internal/domains/domains.go index 17d59ee9..03fc24f1 100644 --- a/internal/domains/domains.go +++ b/internal/domains/domains.go @@ -1,11 +1,12 @@ package domains import ( - "certimate/internal/utils/app" "context" "fmt" "github.com/pocketbase/pocketbase/models" + + "certimate/internal/utils/app" ) func create(ctx context.Context, record *models.Record) error { @@ -19,7 +20,6 @@ func create(ctx context.Context, record *models.Record) error { app.GetApp().Logger().Error("deploy failed", "err", err) } }() - } scheduler := app.GetScheduler() @@ -27,7 +27,6 @@ func create(ctx context.Context, record *models.Record) error { err := scheduler.Add(record.Id, record.GetString("crontab"), func() { deploy(ctx, record) }) - if err != nil { app.GetApp().Logger().Error("add cron job failed", "err", err) return fmt.Errorf("add cron job failed: %w", err) @@ -46,7 +45,6 @@ func update(ctx context.Context, record *models.Record) error { } if record.GetBool("rightnow") { - go func() { if err := deploy(ctx, record); err != nil { app.GetApp().Logger().Error("deploy failed", "err", err) @@ -57,7 +55,6 @@ func update(ctx context.Context, record *models.Record) error { err := scheduler.Add(record.Id, record.GetString("crontab"), func() { deploy(ctx, record) }) - if err != nil { app.GetApp().Logger().Error("update cron job failed", "err", err) return fmt.Errorf("update cron job failed: %w", err) diff --git a/internal/domains/event.go b/internal/domains/event.go index 33d1a571..5ad38ad1 100644 --- a/internal/domains/event.go +++ b/internal/domains/event.go @@ -1,9 +1,9 @@ package domains import ( - "certimate/internal/utils/app" - "github.com/pocketbase/pocketbase/core" + + "certimate/internal/utils/app" ) const tableName = "domains" diff --git a/internal/domains/history.go b/internal/domains/history.go index 8850b37b..616c7c8c 100644 --- a/internal/domains/history.go +++ b/internal/domains/history.go @@ -1,12 +1,13 @@ package domains import ( - "certimate/internal/applicant" - "certimate/internal/utils/app" - "certimate/internal/utils/xtime" "time" "github.com/pocketbase/pocketbase/models" + + "certimate/internal/applicant" + "certimate/internal/utils/app" + "certimate/internal/utils/xtime" ) type historyItem struct { @@ -62,7 +63,6 @@ func (a *history) record(phase Phase, msg string, info *RecordInfo, pass ...bool Info: info.Info, Time: xtime.BeijingTimeStr(), }) - } func (a *history) setCert(cert *applicant.Certificate) { diff --git a/internal/domains/init.go b/internal/domains/init.go index 46f1dd5d..69de4018 100644 --- a/internal/domains/init.go +++ b/internal/domains/init.go @@ -1,9 +1,10 @@ package domains import ( + "context" + "certimate/internal/notify" "certimate/internal/utils/app" - "context" ) func InitSchedule() { @@ -34,5 +35,4 @@ func InitSchedule() { // 启动定时任务 app.GetScheduler().Start() app.GetApp().Logger().Info("定时任务启动成功", "total", app.GetScheduler().Total()) - } diff --git a/internal/notify/expire.go b/internal/notify/expire.go index c5a546ec..985d7491 100644 --- a/internal/notify/expire.go +++ b/internal/notify/expire.go @@ -1,14 +1,15 @@ package notify import ( - "certimate/internal/utils/app" - "certimate/internal/utils/xtime" "strconv" "strings" "time" "github.com/pocketbase/dbx" "github.com/pocketbase/pocketbase/models" + + "certimate/internal/utils/app" + "certimate/internal/utils/xtime" ) type msg struct { @@ -41,7 +42,6 @@ func PushExpireMsg() { if err := Send(msg.subject, msg.message); err != nil { app.GetApp().Logger().Error("send expire msg", "error", err) } - } type notifyTemplates struct { @@ -94,5 +94,4 @@ func buildMsg(records []*models.Record) *msg { subject: title, message: content, } - } diff --git a/internal/notify/notify.go b/internal/notify/notify.go index 3b238d52..3334fa67 100644 --- a/internal/notify/notify.go +++ b/internal/notify/notify.go @@ -1,18 +1,16 @@ package notify import ( - "certimate/internal/utils/app" "context" "fmt" "strconv" notifyPackage "github.com/nikoksr/notify" - "github.com/nikoksr/notify/service/dingding" - + "github.com/nikoksr/notify/service/http" "github.com/nikoksr/notify/service/telegram" - "github.com/nikoksr/notify/service/http" + "certimate/internal/utils/app" ) const ( @@ -40,7 +38,6 @@ func Send(title, content string) error { } func getNotifiers() ([]notifyPackage.Notifier, error) { - resp, err := app.GetApp().Dao().FindFirstRecordByFilter("settings", "name='notifyChannels'") if err != nil { return nil, fmt.Errorf("find notifyChannels error: %w", err) @@ -77,7 +74,6 @@ func getNotifiers() ([]notifyPackage.Notifier, error) { } return notifiers, nil - } func getWebhookNotifier(conf map[string]any) notifyPackage.Notifier { @@ -110,7 +106,6 @@ func getDingTalkNotifier(conf map[string]any) notifyPackage.Notifier { Token: getString(conf, "accessToken"), Secret: getString(conf, "secret"), }) - } func getString(conf map[string]any, key string) string { diff --git a/internal/utils/http/http.go b/internal/utils/http/http.go index 743fa015..6269ea98 100644 --- a/internal/utils/http/http.go +++ b/internal/utils/http/http.go @@ -35,11 +35,9 @@ func Req2GetReader(url string, method string, body io.Reader, head map[string]st req := BuildReq(url, method, body, head) return ToRequest(req, opts...) - } func BuildReq(url string, method string, body io.Reader, head map[string]string) *http.Request { - // Create an http.Request instance req, _ := http.NewRequest(method, url, body) for k, v := range head { diff --git a/internal/utils/variables/variables.go b/internal/utils/variables/variables.go index 626d513b..74a7b22d 100644 --- a/internal/utils/variables/variables.go +++ b/internal/utils/variables/variables.go @@ -4,7 +4,6 @@ import "strings" // Parse2Map 将变量赋值字符串解析为map func Parse2Map(str string) map[string]string { - m := make(map[string]string) lines := strings.Split(str, ";") diff --git a/internal/utils/xtime/time.go b/internal/utils/xtime/time.go index 745ec45b..2c074e6c 100644 --- a/internal/utils/xtime/time.go +++ b/internal/utils/xtime/time.go @@ -15,7 +15,6 @@ func BeijingTimeStr() string { } func GetTimeAfter(d time.Duration) string { - t := time.Now().UTC() return t.Add(d).Format("2006-01-02 15:04:05")