34 lines
382 B
Go
34 lines
382 B
Go
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
|
|
}
|