Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyiming748 committed Dec 14, 2023
0 parents commit 46b314d
Show file tree
Hide file tree
Showing 129 changed files with 9,860 additions and 0 deletions.
Empty file added .github/RELEASE-TEMPLATE.md
Empty file.
44 changes: 44 additions & 0 deletions .github/workflows/basic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: go

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: root
run: pwd
- name: ls1
run: ls -R /home/runner/work/processAll
- name: Save Build
run: mkdir -p /home/runner/work/processAll/exec
- name: Build for linux/amd64
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -o /home/runner/work/processAll/exec/process4LinuxAmd64 /home/runner/work/processAll/processAll/main.go
- name: Build for linux/arm64
run: CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -v -o /home/runner/work/processAll/exec/process4LinuxAmd64 /home/runner/work/processAll/processAll/main.go
- name: Build for windows/amd64
run: CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -v -o /home/runner/work/processAll/exec/process4Win64.exe /home/runner/work/processAll/processAll/main.go
- name: Build for darwin/amd64
run: CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -v -o /home/runner/work/processAll/exec/process4Mac /home/runner/work/processAll/processAll/main.go
- name: Build for darwin/arm64
run: CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -v -o /home/runner/work/processAll/exec/process4M1 /home/runner/work/processAll/processAll/main.go
- name: Build for android/arm64
run: CGO_ENABLED=0 GOOS=android GOARCH=arm64 go build -v -o /home/runner/work/processAll/exec/process4android /home/runner/work/processAll/processAll/main.go
- name: show build file
run: ls -alhtSF /home/runner/work/processAll/exec
# - name: Test
# run: go test -v ./...
41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
#on:
# push:
# branches: [ "master" ]
# pull_request:
# branches: [ "master" ]
name: Latest Release

jobs:
build:
name: GoReleaser build
runs-on: ubuntu-latest

steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 0 # See: https://goreleaser.com/ci/actions/

- name: Set up Go 1.21.4
uses: actions/setup-go@v2
with:
go-version: 1.21.4
id: go

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --clean
# env:
# GITHUB_TOKEN: ${{ secrets.GO_RELEASER_GITHUB_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GO_RELEASER_GITHUB_TOKEN }}
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
*.exe
*.exe~
*.dll
*.so
*.dylib
vendor
.DS_Store
.idea
*.log
process4Linux32
process4Linux64
process4Raspi
process4Raspi64
process4Win32.exe
process4Win64.exe
process4Mac
process4M1
process4Android
/soup/exam.txt
/trans.db
lines.txt
*.db
lines.txt
97 changes: 97 additions & 0 deletions GBK2UTF8/GBK2UTF8.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package GBK2UTF8

import (
"github.com/zhangyiming748/mahonia"
"log/slog"
"os"
"path"
"processAll/GetFileInfo"
"strings"
"unicode/utf8"
)

func AllGBKs2UTF8(root, pattern string) {
infos := GetFileInfo.GetAllFilesInfo(root, pattern)
for _, in := range infos {
GBK2UTF8(in)
}
}
func GBKs2UTF8(dir, pattern string) {
infos := GetFileInfo.GetAllFileInfo(dir, pattern)
for _, in := range infos {
GBK2UTF8(in)
}
}

func GBK2UTF8(info GetFileInfo.BasicInfo) {
fp := info.FullPath
prefix := path.Dir(fp)
newFp := strings.Join([]string{prefix, "utf8", info.FullName}, string(os.PathSeparator))
base := path.Dir(newFp)
os.MkdirAll(base, 0777)
slog.Debug("执行前的文件基本信息", slog.String("输入", fp), slog.String("输出", newFp), slog.String("前缀", prefix), slog.String("新前缀", base))
if isUTF8(fp) {
writeUTF8(newFp, readUTF8(fp))
slog.Debug("skip", slog.String("编码已经是UTF8,直接复制", info.FullName))
} else {
u8 := readGB18030(fp)
nums := writeUTF8(newFp, u8)
slog.Debug("文件写入", slog.String("文件名", newFp), slog.Int("字符数", nums))
}
if err := os.Remove(fp); err != nil {
slog.Error("删除源文件出错", slog.Any("错误文本", err), slog.String("文件名", fp))
} else {
slog.Debug("删除源文件", slog.String("文件名", fp))
}
}

func isUTF8(src string) bool {
defer func() {
if err := recover(); err != nil {
slog.Error("查询是否为UTF8时产生错误", slog.Any("错误文本", err))
}
}()
file, err := os.ReadFile(src)
if err != nil {
panic(err)
}
return utf8.Valid(file)
}

func readGB18030(src string) string {
file, err := os.ReadFile(src)
if err != nil {
panic(err)
}
decoder := mahonia.NewDecoder("gb18030")
if decoder == nil {
slog.Error("编码不存在", slog.Any("错误文本", err))
}
return decoder.ConvertString(string(file))
}

func readUTF8(src string) string {
file, err := os.ReadFile(src)
if err != nil {
slog.Error("读取utf8产生错误", slog.Any("错误文本", err))
}
return string(file)
}

func writeUTF8(dst, s string) int {
defer func() {
if err := recover(); err != nil {
slog.Error("转写utf8产生错误", slog.Any("错误文本", err))
}
}()
f, err := os.OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0777)
if err != nil {
slog.Error("打开目标文件产生错误", slog.Any("错误文本", err))
}

writeString, err := f.WriteString(s)
if err != nil {
slog.Error("写文件产生错误", slog.Any("错误文本", err))
}
return writeString
}
34 changes: 34 additions & 0 deletions GetAllFolder/GetAllFolder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package GetAllFolder

import (
"log/slog"
"os"
"strings"
)

var (
all []string
)

/*
递归获取文件夹和全部子文件夹
不包括文件夹本身
*/
func List(dirname string) []string {
fileInfos, _ := os.ReadDir(dirname)
var folders []string
for _, fi := range fileInfos {
filename := strings.Join([]string{dirname, fi.Name()}, string(os.PathSeparator)) //拼写当前文件夹中所有的文件地址
if fi.IsDir() { //判断是否是文件夹 如果是继续调用把自己的地址作为参数继续调用
if strings.Contains(filename, "/.") {
slog.Debug("跳过隐藏文件夹", slog.Any("文件夹名", fi.Name()))
continue
}
slog.Debug("获取到文件夹", slog.String("文件夹名", filename))
all = append(all, filename)
folders = append(folders, filename)
List(filename) //递归调用
}
}
return all
}
13 changes: 13 additions & 0 deletions GetAllFolder/unit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package GetAllFolder

import "testing"

/*
go test -run TestListFolders -v
*/
func TestListFolders(t *testing.T) {
ret := List("/home/zen/Downloads")
for _, d := range ret {
t.Log(d)
}
}
Loading

0 comments on commit 46b314d

Please sign in to comment.