chore: infrastructure alignment and doc sync (by AICoder)
This commit is contained in:
parent
8bb1b905b3
commit
1c0612ab08
@ -1,4 +0,0 @@
|
||||
## [1.0.7] - 2026-05-06
|
||||
- **设计哲学对齐**:全面废除 `Must` 前缀函数(`MustRead`, `MustReadBytes`, `MustReadLines`, `MustReadDir`, `MustGzip`, `MustGunzip`, `MustZip`, `MustUnzip`),改为配合 `go/cast` 的 `As` 函数消除摩擦。
|
||||
- **内部优化**:重构 `memory.go` 以移除对废弃 `Must` 函数的内部依赖。
|
||||
|
||||
206
CODE-SUMMARY.md
206
CODE-SUMMARY.md
@ -1,206 +0,0 @@
|
||||
### file > object.go
|
||||
```go
|
||||
|
||||
|
||||
|
||||
var fileLocksLock = sync.Mutex{}
|
||||
var fileLocks = map[string]*sync.Mutex{}
|
||||
|
||||
func getLock(filename string) *sync.Mutex
|
||||
|
||||
|
||||
// UnmarshalFile 从文件读取数据并映射到 to,自动处理 YAML/JSON 格式判别及智能字段映射。
|
||||
func UnmarshalFile(filename string, to any) error
|
||||
|
||||
|
||||
// MarshalFile 将数据序列化并写入文件,支持 YAML/JSON 自动判别。
|
||||
func MarshalFile(filename string, data any) error
|
||||
|
||||
|
||||
// MarshalFilePretty 类似 MarshalFile,但会输出带缩进的格式化内容。
|
||||
func MarshalFilePretty(filename string, data any) error
|
||||
|
||||
|
||||
func marshalFile(filename string, data any, indent bool) error
|
||||
|
||||
|
||||
func PatchFile(filename string, patch any) error
|
||||
|
||||
```
|
||||
|
||||
### file > memory.go
|
||||
```go
|
||||
|
||||
|
||||
|
||||
type MemFile struct {
|
||||
Name string
|
||||
AbsName string
|
||||
ModTime time.Time
|
||||
IsDir bool
|
||||
Compressed bool
|
||||
Size int64
|
||||
Data []byte
|
||||
SafeData *safe.SafeBuf
|
||||
}
|
||||
|
||||
type MemFileB64 struct {
|
||||
Name string
|
||||
ModTime time.Time
|
||||
IsDir bool
|
||||
DataB64 []byte
|
||||
Compressed bool
|
||||
Size int64
|
||||
Children []MemFileB64
|
||||
}
|
||||
|
||||
var (
|
||||
memFiles = make(map[string]*MemFile)
|
||||
memFilesByDir = make(map[string][]MemFile)
|
||||
memFilesLock sync.RWMutex
|
||||
)
|
||||
|
||||
func (mf *MemFile) GetData() []byte
|
||||
|
||||
|
||||
func (mf *MemFile) GetSafeData() *safe.SecretPlaintext
|
||||
|
||||
|
||||
func GetAbsFilename(filename string) string
|
||||
|
||||
|
||||
func AddFileToMemory(mf MemFile)
|
||||
|
||||
|
||||
func ReadFileFromMemory(name string) *MemFile
|
||||
|
||||
|
||||
func ReadDirFromMemory(name string) []MemFile
|
||||
|
||||
|
||||
func LoadFileToMemory(filename string)
|
||||
|
||||
|
||||
func SafeLoadFileToMemory(filename string)
|
||||
|
||||
|
||||
func LoadFileToMemoryWithCompress(filename string)
|
||||
|
||||
|
||||
func SafeLoadFileToMemoryWithCompress(filename string)
|
||||
|
||||
|
||||
func loadFileToMemory(filename string, compress bool, isSafe bool)
|
||||
|
||||
|
||||
func LoadFileToB64(filename string) *MemFileB64
|
||||
|
||||
|
||||
func LoadFilesToMemoryFromB64(b64File *MemFileB64)
|
||||
|
||||
|
||||
func LoadFilesToMemoryFromB64KeepGzip(b64File *MemFileB64)
|
||||
|
||||
|
||||
func LoadFilesToMemoryFromJson(jsonFiles string)
|
||||
|
||||
```
|
||||
|
||||
### file > archive.go
|
||||
```go
|
||||
|
||||
|
||||
|
||||
func Compress(data []byte, cType string) ([]byte, error)
|
||||
|
||||
|
||||
func Decompress(data []byte, cType string) ([]byte, error)
|
||||
|
||||
|
||||
func Extract(srcFile, destDir string, stripRoot bool) error
|
||||
|
||||
|
||||
func extractTar(r io.Reader, dest string, strip bool) error
|
||||
|
||||
|
||||
func extractZip(src, dest string, strip bool) error
|
||||
|
||||
|
||||
func extractSingleFile(r io.Reader, destDir, fileName string) error
|
||||
|
||||
|
||||
func writeEntry(destDir, name string, mode os.FileMode, isDir bool, linkPath string, r io.Reader, strip bool) error
|
||||
|
||||
|
||||
func Archive(srcPath, destFile string) error
|
||||
|
||||
|
||||
func walkAndAdd(srcPath string, addFn func(string, os.FileInfo, io.Reader) error) error
|
||||
|
||||
```
|
||||
|
||||
### file > file.go
|
||||
```go
|
||||
|
||||
|
||||
|
||||
type FileInfo struct {
|
||||
Name string
|
||||
FullName string
|
||||
IsDir bool
|
||||
Size int64
|
||||
ModTime int64
|
||||
}
|
||||
|
||||
func EnsureParentDir(filename string)
|
||||
|
||||
|
||||
func EnsureDirSuffix(path string) string
|
||||
|
||||
|
||||
func Exists(filename string) bool
|
||||
|
||||
|
||||
func GetFileInfo(filename string) *FileInfo
|
||||
|
||||
|
||||
func ReadBytes(filename string) ([]byte, error)
|
||||
|
||||
|
||||
func Read(filename string) (string, error)
|
||||
|
||||
|
||||
func ReadLines(filename string) ([]string, error)
|
||||
|
||||
|
||||
func WriteBytes(filename string, content []byte) error
|
||||
|
||||
|
||||
func Write(filename string, content string) error
|
||||
|
||||
|
||||
func Copy(from, to string) error
|
||||
|
||||
|
||||
func CopyToFile(from io.Reader, to string) error
|
||||
|
||||
|
||||
func Remove(path string) error
|
||||
|
||||
|
||||
func Move(src, dst string) error
|
||||
|
||||
|
||||
func Replace(filename, old, new string) error
|
||||
|
||||
|
||||
func Search(dir, pattern string) []string
|
||||
|
||||
|
||||
func ReadDir(filename string) ([]FileInfo, error)
|
||||
|
||||
|
||||
func RunCommand(command string, args ...string) ([]string, error)
|
||||
|
||||
```
|
||||
|
||||
8
go.mod
8
go.mod
@ -3,14 +3,14 @@ module apigo.cc/go/file
|
||||
go 1.25.0
|
||||
|
||||
require (
|
||||
apigo.cc/go/cast v1.3.0
|
||||
apigo.cc/go/encoding v1.3.0
|
||||
apigo.cc/go/safe v1.3.0
|
||||
apigo.cc/go/cast v1.3.3
|
||||
apigo.cc/go/encoding v1.3.1
|
||||
apigo.cc/go/safe v1.3.1
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
require (
|
||||
apigo.cc/go/rand v1.3.0 // indirect
|
||||
apigo.cc/go/rand v1.3.1 // indirect
|
||||
github.com/kr/pretty v0.3.0 // indirect
|
||||
github.com/rogpeppe/go-internal v1.14.1 // indirect
|
||||
golang.org/x/crypto v0.51.0 // indirect
|
||||
|
||||
12
go.sum
12
go.sum
@ -1,7 +1,11 @@
|
||||
apigo.cc/go/cast v1.3.0 h1:ZTcLYijkqZjSWSCSpJUWMfzJYeJKbwKxquKkPrFsROQ=
|
||||
apigo.cc/go/encoding v1.3.0 h1:8jqNHoZBR8vOU/BGsLFebfp1Txa1UxDRpd7YwzIFLJs=
|
||||
apigo.cc/go/rand v1.3.0 h1:k+UFAhMySwXf+dq8Om9TniZV6fm6gAE0evbrqMEdwQU=
|
||||
apigo.cc/go/safe v1.3.0 h1:uctdAUsphT9p60Tk4oS5xPCe0NoIdOHfsYv4PNS0Rok=
|
||||
apigo.cc/go/cast v1.3.3 h1:aln5eDR5DZVWVzZ/y5SJh1gQNgWv2sT82I25NaO9g34=
|
||||
apigo.cc/go/cast v1.3.3/go.mod h1:lGlwImiOvHxG7buyMWhFzcdvQzmSaoKbmr7bcDfUpHk=
|
||||
apigo.cc/go/encoding v1.3.1 h1:y8O58KYAyulkThg1O2ji2BqjnFoSvk42sit9I3z+K7Y=
|
||||
apigo.cc/go/encoding v1.3.1/go.mod h1:xAJk5b83VZ31mXMTnyp0dfMoBKfT/AHDn0u+cQfojgY=
|
||||
apigo.cc/go/rand v1.3.1 h1:7FvsI6PtQ5XrWER0dTiLVo0p7GIxRidT/TBKhVy93j8=
|
||||
apigo.cc/go/rand v1.3.1/go.mod h1:mZ/4Soa3bk+XvDaqPWJuUe1bfEi4eThBj1XmEAuYxsk=
|
||||
apigo.cc/go/safe v1.3.1 h1:irTCqPAC97gGsX/Lw5AzLelDt1xXLEZIAaVhLELWe9Q=
|
||||
apigo.cc/go/safe v1.3.1/go.mod h1:XdOpBhN2vkImalaykYXXmEpczqWa1y3ah6/Q72cdRqE=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user