Skip to content

Instantly share code, notes, and snippets.

@SirmaXX
Created March 31, 2019 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SirmaXX/2532492084f0a46ffe6c03c84c552783 to your computer and use it in GitHub Desktop.
Save SirmaXX/2532492084f0a46ffe6c03c84c552783 to your computer and use it in GitHub Desktop.
create and check file
package main
import (
"os"
"fmt"
)
func main() {
var fileName string
fileName ="asshole.txt"
createFile(fileName)
file, err := os.Open(fileName)
if err != nil {
fmt.Println("Error while creating")// Do Something
}
fInfo, err := file.Stat()
if err != nil {
// Do Something
fmt.Println("Error while creating")
}
if fInfo.Size() <100{
fmt.Println("i want to this");
}else{
fmt.Println("create second txt");
}
fmt.Println(fInfo.Size())
}
func createFile(p string)*os.File {
fmt.Println("creating")
output, err := os.Create(p)
if err != nil {
fmt.Println("Error while creating", p, "-", err)
}
return output
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment