[go: up one dir, main page]

Skip to content
/ gfu Public

gfu is a Go File Utils , i.e. to read slice of file lines, to write and append lines to sclice

License

Notifications You must be signed in to change notification settings

Wissance/gfu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gfu is go file utils

GFU contains following functions:

GFU

  1. 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 {
	
}
// 
  1. 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")
  1. Write slice of strings in file via WriteAllLines This Write overwrites existing file, to add some lines without file erasing use AppendAllLines
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")
  1. Write text in file via WriteAllText, this is boring wrap around os.WriteFile
import (
	"github.com/wissance/gfu"
	// other imports
)

text := "some text"
var err error

// some operations ...

err = gfu.WriteAllText("my_file.txt", text)
  1. 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")

About

gfu is a Go File Utils , i.e. to read slice of file lines, to write and append lines to sclice

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages