From 89f8b90127c95c0f5ab9244295335dc0ccdebb82 Mon Sep 17 00:00:00 2001 From: Alomerry Wu Date: Tue, 19 Mar 2024 02:24:33 +0800 Subject: [PATCH] feat: refine structure --- .githooks/install-git-hooks.sh | 18 --------- .githooks/pre-push | 23 ------------ README.md | 4 +- cmd/cmd.go | 16 -------- cmd/dns.go | 24 ------------ cmd/pusher.go | 31 ---------------- cmd/sgs.go | 37 ------------------- {copier => modules/copier}/convertor.go | 0 {copier => modules/copier}/copier.go | 0 {copier => modules/copier}/example_test.go | 0 {copier => modules/copier}/mapper.go | 0 {dns => modules/dns}/README.md | 0 {dns => modules/dns}/client.go | 8 ++-- {dns => modules/dns}/impl/alidns.go | 2 +- {dns => modules/dns}/impl/cloudflare.go | 2 +- {dns => modules/dns}/impl/config.go | 0 {dns => modules/dns}/internal/core.go | 0 {dns => modules/dns}/utils/utils.go | 2 +- {pusher => modules/pusher}/README_ZH.md | 0 .../pusher}/component/oss/kodo/kodo.go | 0 .../pusher}/component/oss/kodo/request.go | 0 .../pusher}/component/oss/oss.go | 0 .../pusher}/config/example.toml | 0 {pusher => modules/pusher}/main.go | 0 {pusher => modules/pusher}/modes/client.go | 0 {pusher => modules/pusher}/modes/config.go | 0 .../pusher}/modes/pusher/pusher.go | 0 .../pusher}/modes/syncer/syncer.go | 0 {pusher => modules/pusher}/modes/task.go | 0 {pusher => modules/pusher}/share/errors.go | 0 {pusher => modules/pusher}/share/interface.go | 0 {pusher => modules/pusher}/share/share.go | 0 {pusher => modules/pusher}/utils/utils.go | 0 {pusher => modules/pusher}/utils/watcher.go | 0 {sgs => modules/sgs}/.gitignore | 0 {sgs => modules/sgs}/README.md | 0 {sgs => modules/sgs}/delay/delay_reason.go | 0 {sgs => modules/sgs}/delay/delay_summary.go | 4 +- {sgs => modules/sgs}/tools/merge_excel.go | 0 {sgs => modules/sgs}/utils/sort.go | 0 {sgs => modules/sgs}/utils/utils.go | 0 {sgs => modules/sgs}/utils/utils_test.go | 0 {sgs => modules/sgs}/utils/xlsx.go | 0 43 files changed, 11 insertions(+), 160 deletions(-) delete mode 100755 .githooks/install-git-hooks.sh delete mode 100755 .githooks/pre-push delete mode 100644 cmd/cmd.go delete mode 100644 cmd/dns.go delete mode 100644 cmd/pusher.go delete mode 100644 cmd/sgs.go rename {copier => modules/copier}/convertor.go (100%) rename {copier => modules/copier}/copier.go (100%) rename {copier => modules/copier}/example_test.go (100%) rename {copier => modules/copier}/mapper.go (100%) rename {dns => modules/dns}/README.md (100%) rename {dns => modules/dns}/client.go (89%) rename {dns => modules/dns}/impl/alidns.go (99%) rename {dns => modules/dns}/impl/cloudflare.go (98%) rename {dns => modules/dns}/impl/config.go (100%) rename {dns => modules/dns}/internal/core.go (100%) rename {dns => modules/dns}/utils/utils.go (92%) rename {pusher => modules/pusher}/README_ZH.md (100%) rename {pusher => modules/pusher}/component/oss/kodo/kodo.go (100%) rename {pusher => modules/pusher}/component/oss/kodo/request.go (100%) rename {pusher => modules/pusher}/component/oss/oss.go (100%) rename {pusher => modules/pusher}/config/example.toml (100%) rename {pusher => modules/pusher}/main.go (100%) rename {pusher => modules/pusher}/modes/client.go (100%) rename {pusher => modules/pusher}/modes/config.go (100%) rename {pusher => modules/pusher}/modes/pusher/pusher.go (100%) rename {pusher => modules/pusher}/modes/syncer/syncer.go (100%) rename {pusher => modules/pusher}/modes/task.go (100%) rename {pusher => modules/pusher}/share/errors.go (100%) rename {pusher => modules/pusher}/share/interface.go (100%) rename {pusher => modules/pusher}/share/share.go (100%) rename {pusher => modules/pusher}/utils/utils.go (100%) rename {pusher => modules/pusher}/utils/watcher.go (100%) rename {sgs => modules/sgs}/.gitignore (100%) rename {sgs => modules/sgs}/README.md (100%) rename {sgs => modules/sgs}/delay/delay_reason.go (100%) rename {sgs => modules/sgs}/delay/delay_summary.go (99%) rename {sgs => modules/sgs}/tools/merge_excel.go (100%) rename {sgs => modules/sgs}/utils/sort.go (100%) rename {sgs => modules/sgs}/utils/utils.go (100%) rename {sgs => modules/sgs}/utils/utils_test.go (100%) rename {sgs => modules/sgs}/utils/xlsx.go (100%) diff --git a/.githooks/install-git-hooks.sh b/.githooks/install-git-hooks.sh deleted file mode 100755 index ada6764..0000000 --- a/.githooks/install-git-hooks.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -# Define the source and destination paths -source_path=".githooks/pre-push" -destination_path=".git/hooks/pre-push" - -# Check if the source script exists -if [ -e "$source_path" ]; then - # Copy the source script to the hooks directory - cp "$source_path" "$destination_path" - - # Grant execution permission to the copied script - chmod +x "$destination_path" - - echo "pre-push hook script has been successfully installed in .git/hooks/" -else - echo "Error: The source pre-push script ('$source_path') does not exist. Please make sure it's in the correct location." -fi diff --git a/.githooks/pre-push b/.githooks/pre-push deleted file mode 100755 index bd87193..0000000 --- a/.githooks/pre-push +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh - -# TODO push 前自动将文件 push 到 oss -# PROJECT_PATH=$(cd `dirname ${0}`; cd ../; pwd) -# COMMAND="${PROJECT_PATH}/blog/.vuepress/ossPusher --configPath ${PROJECT_PATH}/blog/.vuepress/core.toml" -# ${COMMAND} -# exit 0 - -local_branch=$(git rev-parse --abbrev-ref HEAD) -remote_branch="origin/master" - -# Fetch the latest changes from the remote repository -git fetch - -# Check if there are any changes in the remote "develop" branch -if [[ $(git log HEAD..$remote_branch --oneline) ]]; then - echo "Error: There are new commits in the remote 'develop' branch. Please rebase before pushing." - exit 1 -else - echo "Your are at latest!" -fi - -exit 0 diff --git a/README.md b/README.md index c5b3b4e..983af08 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,10 @@ go-tools contains several tools ## Usage -- [DNS](./dns/README.md) +- [DNS](modules/dns/README.md) - [pusher](./pusher/README.md) - [sgs delay](./sgs/README.md) -- [copier](./copier/README.md) +- [copier](modules/copier/README.md) - algorithm ## Copier diff --git a/cmd/cmd.go b/cmd/cmd.go deleted file mode 100644 index f3afc43..0000000 --- a/cmd/cmd.go +++ /dev/null @@ -1,16 +0,0 @@ -package cmd - -import ( - "github.com/spf13/cobra" -) - -var RootCmd = &cobra.Command{ - Use: "go-tools", - Short: "go tools help your do several things.", -} - -func Execute() { - if err := RootCmd.Execute(); err != nil { - panic(err) - } -} diff --git a/cmd/dns.go b/cmd/dns.go deleted file mode 100644 index 5356cf7..0000000 --- a/cmd/dns.go +++ /dev/null @@ -1,24 +0,0 @@ -package cmd - -import ( - gdns "github.com/alomerry/go-tools/dns" - "github.com/spf13/cobra" -) - -var ( - domainsFile string -) - -var dns = &cobra.Command{ - Use: "dns", - Short: "dns tools help your to set domain A dns", - Run: func(cmd *cobra.Command, args []string) { - client := gdns.GenClient(domainsFile) - client.SetDomainA() - }, -} - -func init() { - dns.Flags().StringVarP(&domainsFile, "config", "f", "./domains.toml", "domains list file") - RootCmd.AddCommand(dns) -} diff --git a/cmd/pusher.go b/cmd/pusher.go deleted file mode 100644 index 963e601..0000000 --- a/cmd/pusher.go +++ /dev/null @@ -1,31 +0,0 @@ -package cmd - -import ( - "context" - ppusher "github.com/alomerry/go-tools/pusher/modes" - "github.com/spf13/cobra" -) - -var ( - configPath string -) - -var pusher = &cobra.Command{ - Use: "pusher", - Short: "TODO", - Run: func(cmd *cobra.Command, args []string) { - ctx := context.Background() - - // TODO add config validate before run - err := ppusher.IClient.Init(ctx, configPath).Run(ctx) - - if err != nil { - panic(err) - } - }, -} - -func init() { - pusher.Flags().StringVarP(&configPath, "config", "f", "./core.toml", "set the config abstract path") - RootCmd.AddCommand(pusher) -} diff --git a/cmd/sgs.go b/cmd/sgs.go deleted file mode 100644 index 636892b..0000000 --- a/cmd/sgs.go +++ /dev/null @@ -1,37 +0,0 @@ -package cmd - -import ( - "github.com/alomerry/go-tools/sgs/delay" - "github.com/alomerry/go-tools/sgs/tools" - "github.com/spf13/cast" - "github.com/spf13/cobra" -) - -const ( - MERGE_EXCEL = iota + 1 - DELAY_SUMMARY - DELAY_REASON -) - -var module string - -var sgs = &cobra.Command{ - Use: "sgs", - Short: "sgs tools help your do something", - Run: func(cmd *cobra.Command, args []string) { - switch cast.ToInt(module) { - case MERGE_EXCEL: - tools.DoMergeExcelSheets("", nil) - case DELAY_SUMMARY: - delay.DoDelaySummaryMulti("") - case DELAY_REASON: - delay.DoDelayReason() - } - }, -} - -func init() { - sgs.Flags().StringVarP(&module, "module", "m", "", "sgs 模块包含三个功能,请使用 sgs -m <数字> 来选择执行的任务:\n1. 合并表格\n2. delay 月报\n3. 广州 delay") - sgs.MarkFlagRequired("module") - RootCmd.AddCommand(sgs) -} diff --git a/copier/convertor.go b/modules/copier/convertor.go similarity index 100% rename from copier/convertor.go rename to modules/copier/convertor.go diff --git a/copier/copier.go b/modules/copier/copier.go similarity index 100% rename from copier/copier.go rename to modules/copier/copier.go diff --git a/copier/example_test.go b/modules/copier/example_test.go similarity index 100% rename from copier/example_test.go rename to modules/copier/example_test.go diff --git a/copier/mapper.go b/modules/copier/mapper.go similarity index 100% rename from copier/mapper.go rename to modules/copier/mapper.go diff --git a/dns/README.md b/modules/dns/README.md similarity index 100% rename from dns/README.md rename to modules/dns/README.md diff --git a/dns/client.go b/modules/dns/client.go similarity index 89% rename from dns/client.go rename to modules/dns/client.go index 3cb9b54..c0d9d79 100644 --- a/dns/client.go +++ b/modules/dns/client.go @@ -2,8 +2,8 @@ package dns import ( "fmt" - dnsImpl "github.com/alomerry/go-tools/dns/impl" - "github.com/alomerry/go-tools/dns/utils" + impl2 "github.com/alomerry/go-tools/modules/dns/impl" + "github.com/alomerry/go-tools/modules/dns/utils" "github.com/spf13/viper" "os" ) @@ -60,7 +60,7 @@ func (c *client) SetDomainA() { // TODO 抽出循环中 switch impl { case IMPL_CF: - cf := &dnsImpl.Cloudflare{ + cf := &impl2.Cloudflare{ Secret: os.Getenv(CF_SK), ZoneId: os.Getenv(CF_ZONE), Domains: viper.GetStringSlice("domains"), @@ -68,7 +68,7 @@ func (c *client) SetDomainA() { } cf.UpsertDomainRecords() case IMPL_ALI: - ali := &dnsImpl.Alidns{ + ali := &impl2.Alidns{ AK: os.Getenv(ALI_AK), SK: os.Getenv(ALI_SK), Domains: viper.GetStringSlice("domains"), diff --git a/dns/impl/alidns.go b/modules/dns/impl/alidns.go similarity index 99% rename from dns/impl/alidns.go rename to modules/dns/impl/alidns.go index 34f5c01..37b05e5 100644 --- a/dns/impl/alidns.go +++ b/modules/dns/impl/alidns.go @@ -8,7 +8,7 @@ import ( "crypto/sha256" "encoding/base64" "fmt" - "github.com/alomerry/go-tools/dns/internal" + "github.com/alomerry/go-tools/modules/dns/internal" "hash" "io" "log" diff --git a/dns/impl/cloudflare.go b/modules/dns/impl/cloudflare.go similarity index 98% rename from dns/impl/cloudflare.go rename to modules/dns/impl/cloudflare.go index df74ddc..f2c58a6 100644 --- a/dns/impl/cloudflare.go +++ b/modules/dns/impl/cloudflare.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "github.com/alomerry/go-tools/dns/internal" + "github.com/alomerry/go-tools/modules/dns/internal" "log" "net/http" ) diff --git a/dns/impl/config.go b/modules/dns/impl/config.go similarity index 100% rename from dns/impl/config.go rename to modules/dns/impl/config.go diff --git a/dns/internal/core.go b/modules/dns/internal/core.go similarity index 100% rename from dns/internal/core.go rename to modules/dns/internal/core.go diff --git a/dns/utils/utils.go b/modules/dns/utils/utils.go similarity index 92% rename from dns/utils/utils.go rename to modules/dns/utils/utils.go index 1024d1d..2d3edb3 100644 --- a/dns/utils/utils.go +++ b/modules/dns/utils/utils.go @@ -1,7 +1,7 @@ package utils import ( - "github.com/alomerry/go-tools/dns/internal" + "github.com/alomerry/go-tools/modules/dns/internal" "io" "log" "net/http" diff --git a/pusher/README_ZH.md b/modules/pusher/README_ZH.md similarity index 100% rename from pusher/README_ZH.md rename to modules/pusher/README_ZH.md diff --git a/pusher/component/oss/kodo/kodo.go b/modules/pusher/component/oss/kodo/kodo.go similarity index 100% rename from pusher/component/oss/kodo/kodo.go rename to modules/pusher/component/oss/kodo/kodo.go diff --git a/pusher/component/oss/kodo/request.go b/modules/pusher/component/oss/kodo/request.go similarity index 100% rename from pusher/component/oss/kodo/request.go rename to modules/pusher/component/oss/kodo/request.go diff --git a/pusher/component/oss/oss.go b/modules/pusher/component/oss/oss.go similarity index 100% rename from pusher/component/oss/oss.go rename to modules/pusher/component/oss/oss.go diff --git a/pusher/config/example.toml b/modules/pusher/config/example.toml similarity index 100% rename from pusher/config/example.toml rename to modules/pusher/config/example.toml diff --git a/pusher/main.go b/modules/pusher/main.go similarity index 100% rename from pusher/main.go rename to modules/pusher/main.go diff --git a/pusher/modes/client.go b/modules/pusher/modes/client.go similarity index 100% rename from pusher/modes/client.go rename to modules/pusher/modes/client.go diff --git a/pusher/modes/config.go b/modules/pusher/modes/config.go similarity index 100% rename from pusher/modes/config.go rename to modules/pusher/modes/config.go diff --git a/pusher/modes/pusher/pusher.go b/modules/pusher/modes/pusher/pusher.go similarity index 100% rename from pusher/modes/pusher/pusher.go rename to modules/pusher/modes/pusher/pusher.go diff --git a/pusher/modes/syncer/syncer.go b/modules/pusher/modes/syncer/syncer.go similarity index 100% rename from pusher/modes/syncer/syncer.go rename to modules/pusher/modes/syncer/syncer.go diff --git a/pusher/modes/task.go b/modules/pusher/modes/task.go similarity index 100% rename from pusher/modes/task.go rename to modules/pusher/modes/task.go diff --git a/pusher/share/errors.go b/modules/pusher/share/errors.go similarity index 100% rename from pusher/share/errors.go rename to modules/pusher/share/errors.go diff --git a/pusher/share/interface.go b/modules/pusher/share/interface.go similarity index 100% rename from pusher/share/interface.go rename to modules/pusher/share/interface.go diff --git a/pusher/share/share.go b/modules/pusher/share/share.go similarity index 100% rename from pusher/share/share.go rename to modules/pusher/share/share.go diff --git a/pusher/utils/utils.go b/modules/pusher/utils/utils.go similarity index 100% rename from pusher/utils/utils.go rename to modules/pusher/utils/utils.go diff --git a/pusher/utils/watcher.go b/modules/pusher/utils/watcher.go similarity index 100% rename from pusher/utils/watcher.go rename to modules/pusher/utils/watcher.go diff --git a/sgs/.gitignore b/modules/sgs/.gitignore similarity index 100% rename from sgs/.gitignore rename to modules/sgs/.gitignore diff --git a/sgs/README.md b/modules/sgs/README.md similarity index 100% rename from sgs/README.md rename to modules/sgs/README.md diff --git a/sgs/delay/delay_reason.go b/modules/sgs/delay/delay_reason.go similarity index 100% rename from sgs/delay/delay_reason.go rename to modules/sgs/delay/delay_reason.go diff --git a/sgs/delay/delay_summary.go b/modules/sgs/delay/delay_summary.go similarity index 99% rename from sgs/delay/delay_summary.go rename to modules/sgs/delay/delay_summary.go index 349b14a..2340522 100644 --- a/sgs/delay/delay_summary.go +++ b/modules/sgs/delay/delay_summary.go @@ -9,8 +9,8 @@ import ( "strings" "sync" - "github.com/alomerry/go-tools/sgs/tools" - "github.com/alomerry/go-tools/sgs/utils" + "github.com/alomerry/go-tools/modules/sgs/tools" + "github.com/alomerry/go-tools/modules/sgs/utils" "github.com/emirpasic/gods/stacks" "github.com/emirpasic/gods/stacks/arraystack" "github.com/spf13/cast" diff --git a/sgs/tools/merge_excel.go b/modules/sgs/tools/merge_excel.go similarity index 100% rename from sgs/tools/merge_excel.go rename to modules/sgs/tools/merge_excel.go diff --git a/sgs/utils/sort.go b/modules/sgs/utils/sort.go similarity index 100% rename from sgs/utils/sort.go rename to modules/sgs/utils/sort.go diff --git a/sgs/utils/utils.go b/modules/sgs/utils/utils.go similarity index 100% rename from sgs/utils/utils.go rename to modules/sgs/utils/utils.go diff --git a/sgs/utils/utils_test.go b/modules/sgs/utils/utils_test.go similarity index 100% rename from sgs/utils/utils_test.go rename to modules/sgs/utils/utils_test.go diff --git a/sgs/utils/xlsx.go b/modules/sgs/utils/xlsx.go similarity index 100% rename from sgs/utils/xlsx.go rename to modules/sgs/utils/xlsx.go