Skip to content

Commit

Permalink
demote LogHasErr PrintHasErr DiscardHasErr from method to package-lev…
Browse files Browse the repository at this point in the history
…el function
  • Loading branch information
kokizzu committed Oct 21, 2022
1 parent 24ec7cf commit 366081b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ A: Because channel requires a consumer, or it would stuck/block if channel is fu

Q: How to ignore error?

A: assign `goproc.HasErrFunc` with `goproc.DiscardHasErr`, other option are: `L.IsError` (default), `goproc.LogHasErr` (uses log), `goproc.PrintHasErr` (uses fmt)
A: assign `Goproc.HasErrFunc` with `goproc.DiscardHasErr`, other option are: `L.IsError` (default), `goproc.LogHasErr` (uses log), `goproc.PrintHasErr` (uses fmt)

## TODO

Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ module github.com/kokizzu/goproc

go 1.18

require github.com/kokizzu/gotro v1.2028.1837
require github.com/kokizzu/gotro v1.2221.2021

require (
github.com/fatih/color v1.13.0 // indirect
github.com/goccy/go-json v0.9.11 // indirect
github.com/klauspost/cpuid/v2 v2.1.2 // indirect
github.com/kokizzu/rand v0.0.0-20221021123447-6043c55a8bad // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand All @@ -17,5 +18,6 @@ require (
github.com/yosuke-furukawa/json5 v0.1.1 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/exp v0.0.0-20221019170559-20944726eadf // indirect
golang.org/x/sys v0.1.0 // indirect
)
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ github.com/goccy/go-json v0.9.11 h1:/pAaQDLHEoCq/5FFmSKBswWmK6H0e8g4159Kc/X/nqk=
github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/klauspost/cpuid/v2 v2.1.2 h1:XhdX4fqAJUA0yj+kUwMavO0hHrSPAecYdYf1ZmxHvak=
github.com/klauspost/cpuid/v2 v2.1.2/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
github.com/kokizzu/gotro v1.2028.1837 h1:1tEdEsPypQSHcpNllXRJBeygA81MM4+fgX/0z9O4pC4=
github.com/kokizzu/gotro v1.2028.1837/go.mod h1:vvqIJMgk9tP4bnZ23mJRvueiDRBPJmMdDZoPm28S98k=
github.com/kokizzu/gotro v1.2221.2021 h1:StOlzYk/lKARoJ4eofNhl6W69Rm0qOZHQiEB9IfKDmU=
github.com/kokizzu/gotro v1.2221.2021/go.mod h1:AHHFBb9ixZLUJnf6Tu1hpCidegVRSDjEuNPQqx52le4=
github.com/kokizzu/rand v0.0.0-20221021123447-6043c55a8bad h1:qWvljqz38n8hxJ3h3vXc571jWNQWEqwN4gwmu2anT3Y=
github.com/kokizzu/rand v0.0.0-20221021123447-6043c55a8bad/go.mod h1:FQuP+i28vq8vNBPWOuNriHLkC3khLXtLPw6rzWGyxZw=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand All @@ -23,17 +25,21 @@ github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWEr
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/valyala/fastrand v1.1.0 h1:f+5HkLW4rsgzdNoleUOB69hyT9IlD2ZQh9GyDMfb5G8=
github.com/yosuke-furukawa/json5 v0.1.1 h1:0F9mNwTvOuDNH243hoPqvf+dxa5QsKnZzU20uNsh3ZI=
github.com/yosuke-furukawa/json5 v0.1.1/go.mod h1:sw49aWDqNdRJ6DYUtIQiaA3xyj2IL9tjeNYmX2ixwcU=
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/exp v0.0.0-20221019170559-20944726eadf h1:nFVjjKDgNY37+ZSYCJmtYf7tOlfQswHqplG2eosjOMg=
golang.org/x/exp v0.0.0-20221019170559-20944726eadf/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
pgregory.net/rapid v0.4.8 h1:d+5SGZWUbJPbl3ss6tmPFqnNeQR6VDOFly+eTjwPiEw=
9 changes: 6 additions & 3 deletions goproc.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,26 @@ type Goproc struct {
HasErrFunc func(err error, fmt string, args ...any) bool
}

func (q *Goproc) LogHasErr(err error, fmt string, args ...any) bool {
// LogHasErr to log if error occurred, must return true if err not nil
func LogHasErr(err error, fmt string, args ...any) bool {
if err != nil {
log.Printf(fmt, args...)
return true
}
return false
}

func (q *Goproc) PrintHasErr(err error, msg string, args ...any) bool {
// PrintHasErr to log using fmt if error occurred, must return true if err not nil
func PrintHasErr(err error, msg string, args ...any) bool {
if err != nil {
fmt.Printf(msg+"\n", args...)
return true
}
return false
}

func (g *Goproc) DiscardHasErr(err error, _ string, _ ...any) bool {
// DiscardHasErr to ignore if error occurred, must return true if err not nil
func DiscardHasErr(err error, _ string, _ ...any) bool {
return err != nil
}

Expand Down

0 comments on commit 366081b

Please sign in to comment.