Skip to content

Commit

Permalink
feat: refine structure
Browse files Browse the repository at this point in the history
  • Loading branch information
alomerry committed Mar 18, 2024
1 parent 8c38ebc commit 71ef5bd
Show file tree
Hide file tree
Showing 50 changed files with 96 additions and 173 deletions.
18 changes: 0 additions & 18 deletions .githooks/install-git-hooks.sh

This file was deleted.

23 changes: 0 additions & 23 deletions .githooks/pre-push

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 0 additions & 16 deletions cmd/cmd.go

This file was deleted.

24 changes: 0 additions & 24 deletions cmd/dns.go

This file was deleted.

31 changes: 0 additions & 31 deletions cmd/pusher.go

This file was deleted.

37 changes: 0 additions & 37 deletions cmd/sgs.go

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions dns/client.go → modules/dns/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -60,15 +60,15 @@ 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"),
NewAddr: utils.GetIpv4AddrFromUrl(),
}
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"),
Expand Down
2 changes: 1 addition & 1 deletion dns/impl/alidns.go → modules/dns/impl/alidns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion dns/impl/cloudflare.go → modules/dns/impl/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion dns/utils/utils.go → modules/dns/utils/utils.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package oss
import (
"sync"

"github.com/alomerry/go-tools/pusher/component/oss/kodo"
"github.com/alomerry/go-tools/pusher/share"
"github.com/alomerry/go-tools/modules/pusher/component/oss/kodo"
"github.com/alomerry/go-tools/modules/pusher/share"
"github.com/spf13/cast"
"github.com/spf13/viper"
)
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions pusher/main.go → modules/pusher/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/alomerry/go-tools/pusher/modes"
"github.com/alomerry/go-tools/modules/pusher/modes"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"golang.org/x/net/context"
Expand All @@ -17,7 +17,7 @@ func main() {
ctx := context.Background()

// TODO add config validate before run
err := modes.IClient.Init(ctx).Run(ctx)
err := modes.IClient.Init(ctx, "TODO").Run(ctx)

if err != nil {
panic(err)
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions pusher/modes/config.go → modules/pusher/modes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"strings"

"github.com/alomerry/go-tools/pusher/component/oss"
"github.com/alomerry/go-tools/pusher/modes/pusher"
"github.com/alomerry/go-tools/pusher/share"
"github.com/alomerry/go-tools/modules/pusher/component/oss"
"github.com/alomerry/go-tools/modules/pusher/modes/pusher"
"github.com/alomerry/go-tools/modules/pusher/share"
"github.com/spf13/viper"
"golang.org/x/net/context"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"sync"
"time"

"github.com/alomerry/go-tools/pusher/component/oss"
"github.com/alomerry/go-tools/pusher/share"
"github.com/alomerry/go-tools/pusher/utils"
"github.com/alomerry/go-tools/modules/pusher/component/oss"
"github.com/alomerry/go-tools/modules/pusher/share"
"github.com/alomerry/go-tools/modules/pusher/utils"
"github.com/spf13/cast"
"github.com/spf13/viper"
"golang.org/x/net/context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package syncer
import (
"time"

"github.com/alomerry/go-tools/pusher/utils"
"github.com/alomerry/go-tools/modules/pusher/utils"
"github.com/spf13/cast"
"github.com/spf13/viper"
"golang.org/x/net/context"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"time"

"github.com/alomerry/go-tools/pusher/share"
"github.com/alomerry/go-tools/modules/pusher/share"
)

type Watcher struct {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tools
import (
"encoding/csv"
"fmt"
"github.com/alomerry/go-tools/sgs/utils"
"github.com/alomerry/go-tools/modules/sgs/utils"
"github.com/tealeg/xlsx/v3"
"io"
"log"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions utils/array/array.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package array

func Contains[T comparable](arr []T, i T) bool {
for _, item := range arr {
if item == i {
return true
}
}

return false
}

func ContainsByJudge[T any](arr []T, i T, f func(a, b T) bool) bool {
for _, item := range arr {
if f(item, i) {
return true
}
}

return false
}
7 changes: 7 additions & 0 deletions utils/string/string.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package string

const (
Space = " "
Tab = "\t"
NewLine = "\n"
)
44 changes: 44 additions & 0 deletions utils/time/time.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package time

import (
"fmt"
"time"
)

const (
RFC3339utc0 = "2006-01-02T15:04:05.999+00:00"
RFC3339utc8 = "2006-01-02T15:04:05.999+08:00"
RFC3339mini = "2006-01-02T15:04:05.999Z"
)

var (
EmptyTime = time.Unix(0, 0)
)

func ConvString2Time(dateString string) time.Time {
res, err := time.Parse(RFC3339utc0, dateString)
if err == nil {
return res
}
res, err = time.Parse(RFC3339utc8, dateString)
if err == nil {
return res
}
res, err = time.Parse(RFC3339mini, dateString)
if err == nil {
return res
}

res, err = time.Parse(time.DateOnly, dateString)
if err == nil {
return res
}

if dateString == "now" {
return time.Now()
}

fmt.Println(err)

return EmptyTime
}

0 comments on commit 71ef5bd

Please sign in to comment.