Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
ddkwork committed Mar 12, 2024
1 parent 24e9fd9 commit a4fe419
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
6 changes: 3 additions & 3 deletions gen/fileAction_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
6 changes: 3 additions & 3 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {")
Expand Down
Binary file removed safeType/bytes.tar
Binary file not shown.
14 changes: 14 additions & 0 deletions safeType/go.mod
Original file line number Diff line number Diff line change
@@ -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
)
17 changes: 17 additions & 0 deletions safeType/go.sum
Original file line number Diff line number Diff line change
@@ -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=
5 changes: 0 additions & 5 deletions safeType/safeType.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package safeType

import (
"bytes"
"sync"
)

type (
Expand All @@ -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)}
Expand Down

0 comments on commit a4fe419

Please sign in to comment.