Skip to content

Commit d8e646b

Browse files
committed
use try.T functions this time in default sample
1 parent c29b230 commit d8e646b

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

samples/main-play.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,23 @@ func TryCopyFile(src, dst string) {
8888
try.To1(io.Copy(w, r))
8989
}
9090

91+
func AnnotativeCopyFile(src, dst string) (err error) {
92+
defer err2.Handle(&err)
93+
94+
r := try.T1(os.Open(src))("failed")
95+
defer r.Close()
96+
97+
w := try.T1(os.Create(dst))("failed")
98+
defer err2.Handle(&err, func(err error) error {
99+
try.Out(os.Remove(dst)).Logf()
100+
return err
101+
})
102+
defer w.Close()
103+
104+
try.T1(io.Copy(w, r))("failed")
105+
return nil
106+
}
107+
91108
func CallRecur(d int) (ret int, err error) {
92109
defer err2.Handle(&err)
93110

@@ -191,8 +208,10 @@ func doMain() (err error) {
191208
}
192209
} else {
193210
// 2nd argument is empty to assert
194-
TryCopyFile("main.go", "")
195-
//try.To(CopyFile("main.go", ""))
211+
//TryCopyFile("main.go", "")
212+
213+
// testing try.T function removal from annotation
214+
try.To(AnnotativeCopyFile("main.go", ""))
196215
}
197216

198217
fmt.Println("=== you cannot see this ===")

0 commit comments

Comments
 (0)