diff --git a/gen/fileAction_gen.go b/gen/fileAction_gen.go index 1bfc457b..af9277eb 100644 --- a/gen/fileAction_gen.go +++ b/gen/fileAction_gen.go @@ -17,9 +17,9 @@ func WriteGoFile[T safeType.Type](name string, data T) (ok bool) { return write(name, false, source) } -func WriteAppend[T safeType.Type](name string, data T) (ok bool) { return write(name, true, data) } -func WriteTruncate[T safeType.Type](name string, data T) (ok bool) { return write(name, false, data) } -func WriteBinaryFile[T safeType.Type](name string, data T) (ok bool) { return write(name, false, data) } +func WriteAppend[T safeType.Type](name string, data T) bool { return write(name, true, data) } +func WriteTruncate[T safeType.Type](name string, data T) bool { return write(name, false, data) } +func WriteBinaryFile[T safeType.Type](name string, data T) bool { return write(name, false, data) } func write[T safeType.Type](name string, isAppend bool, data T) (ok bool) { if !CreatDirectory(filepath.Dir(name)) { diff --git a/gen/gen.go b/gen/gen.go index 50acb5f8..25f28e50 100644 --- a/gen/gen.go +++ b/gen/gen.go @@ -165,9 +165,9 @@ func (g *GeneratedFile) FileAction() { g.P("}") g.P("") - g.P("func WriteAppend[T safeType.Type](name string, data T) (ok bool) { return write(name, true, data) }") - g.P("func WriteTruncate[T safeType.Type](name string, data T) (ok bool) { return write(name, false, data) }") - g.P("func WriteBinaryFile[T safeType.Type](name string, data T) (ok bool) { return write(name, false, data) }") + g.P("func WriteAppend[T safeType.Type](name string, data T) bool { return write(name, true, data) }") + g.P("func WriteTruncate[T safeType.Type](name string, data T) bool { return write(name, false, data) }") + g.P("func WriteBinaryFile[T safeType.Type](name string, data T) bool{ return write(name, false, data) }") g.P("") g.P("func write[T safeType.Type](name string, isAppend bool, data T) (ok bool) {") diff --git a/safeType/bytes.tar b/safeType/bytes.tar deleted file mode 100644 index 91c19e3d..00000000 Binary files a/safeType/bytes.tar and /dev/null differ diff --git a/safeType/go.mod b/safeType/go.mod new file mode 100644 index 00000000..29a4cb5f --- /dev/null +++ b/safeType/go.mod @@ -0,0 +1,14 @@ +module github.com/ddkwork/golibrary/safeType + +go 1.22 + +require github.com/ddkwork/golibrary/mylog v0.0.0-20240312053312-24e9fd979e5f + +require ( + github.com/fatih/color v1.16.0 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect + golang.org/x/sys v0.18.0 // indirect + golang.org/x/text v0.14.0 // indirect +) diff --git a/safeType/go.sum b/safeType/go.sum new file mode 100644 index 00000000..d5a81d59 --- /dev/null +++ b/safeType/go.sum @@ -0,0 +1,17 @@ +github.com/ddkwork/golibrary/mylog v0.0.0-20240312053312-24e9fd979e5f h1:q9Kf+L8qgf3AS1Vv6BuQ8o+w5mBpWwAEHmRlh7u596A= +github.com/ddkwork/golibrary/mylog v0.0.0-20240312053312-24e9fd979e5f/go.mod h1:+npHC7A5w2HaMQTHEAt8UvFaRMwTHDIlCOSFhGOrrno= +github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= +github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ= +golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= diff --git a/safeType/safeType.go b/safeType/safeType.go index 7b889df6..3ff9671b 100644 --- a/safeType/safeType.go +++ b/safeType/safeType.go @@ -2,7 +2,6 @@ package safeType import ( "bytes" - "sync" ) type ( @@ -16,11 +15,7 @@ type ( type Data struct{ *bytes.Buffer } -var mu sync.RWMutex - func New[T Type](s T) *Data { - // mu.RLock() - // defer mu.RUnlock() switch s := any(s).(type) { case []byte: return &Data{bytes.NewBuffer(s)}