Feat : add writer example
This commit is contained in:
parent
579ac0d2f3
commit
076238e196
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
bin/
|
||||
!bin/.gitkeep
|
||||
./notes.txt
|
||||
|
2
go.mod
2
go.mod
@ -2,6 +2,6 @@ module antoine-roux.ml/projects/go/test
|
||||
|
||||
go 1.15
|
||||
|
||||
require github.com/docker/docker-credential-helpers v0.6.3 // indirect
|
||||
require github.com/docker/docker-credential-helpers v0.6.3
|
||||
|
||||
replace antoine-roux.ml/projects/go/test/employee => ./employee
|
||||
|
33
writer.go
Normal file
33
writer.go
Normal file
@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
err := WriteString("hello world")
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
||||
|
||||
func WriteString(str string) (err error) {
|
||||
var f *os.File
|
||||
f, err = os.Create("./notes.txt")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
defer func() {
|
||||
cerr := f.Close()
|
||||
if err == nil {
|
||||
err = cerr
|
||||
}
|
||||
}()
|
||||
|
||||
_, err = io.WriteString(f, str)
|
||||
return
|
||||
}
|
Loading…
Reference in New Issue
Block a user