Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
EvilLord666 committed Nov 7, 2024
1 parent 1c1dad1 commit 58bb03c
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,50 @@ var err error
text, err = gfu.ReadAllText("my_file.txt")
```
3. Write slice of strings in file via `WriteAllLines`
This Write overwrites existing file, to add some lines **_without file erasing_** use `AppendAllLines`
```go
import (
"github.com/wissance/gfu"
// other imports
)

lines := []string{
"{",
" \"id\": 1,",
" \"name\": \"Michael Ushakov\"",
"}",
}
file := "write_all_lines_test.txt"
err := gfu.WriteAllLines(file, lines, "\n")
```
4. Write text in file via `WriteAllText`, this is _boring_ wrap around `os.WriteFile`
```go
import (
"github.com/wissance/gfu"
// other imports
)

text := "some text"
var err error

// some operations ...

err = gfu.WriteAllText("my_file.txt", text)
```
4. Write text in file via `WriteAllText`:

5. Append lines to existing file `AppendAllText`, if file doesn't exist this function create it
```go
import (
"github.com/wissance/gfu"
// other imports
)

lines := []string{
"{",
" \"id\": 2,",
" \"name\": \"Alex Petrov\"",
"}",
}
file := "write_all_lines_test.txt"
err := gfu.AppendAllLines(file, lines, "\n")
```

0 comments on commit 58bb03c

Please sign in to comment.