GFU
contains following functions:
- Read file content as slice of strings via
ReadAllLines
import (
"github.com/wissance/gfu"
// other imports
)
var lines []string
var err error
// some operations ...
lines, err = gfu.ReadAllLines("my_file.txt", false)
if len(lines) > 0 {
}
//
- Read file content as a string via
ReadAllText
:
import (
"github.com/wissance/gfu"
// other imports
)
var text string
var err error
// some operations ...
text, err = gfu.ReadAllText("my_file.txt")
- Write slice of strings in file via
WriteAllLines
This Write overwrites existing file, to add some lines without file erasing useAppendAllLines
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")
- Write text in file via
WriteAllText
, this is boring wrap aroundos.WriteFile
import (
"github.com/wissance/gfu"
// other imports
)
text := "some text"
var err error
// some operations ...
err = gfu.WriteAllText("my_file.txt", text)
- Append lines to existing file
AppendAllText
, if file doesn't exist this function create it
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")