Oleku Konko
2014-01-20 17:59:27 UTC
*Introduction*
Am fairly new to golang and i really appreciate the work that has gone to
the project so far.(Well done guys) I would like to make simple
contributions `os` & `os.FileMode` if it would be permitted
*Case 1 : os.FileMode*
`FileMode.Mode()` already returns the file mode but checking if a file
readable or writable can be simpler rather than parsing the mode
*Case 2 : os*
I would like to add the similar function like unix touch<http://en.wikipedia.org/wiki/Touch_(Unix)>.
This is used to change a file's access, modification timestamps and also
used to create a new empty file if it does not exist.
*Functions / Method *
func Touch(name string) (file *File, err error)
*func *(m FileMode) IsReadable() bool {
*func *(m FileMode) IsWritable() bool {
*func *(m FileMode) IsFile() bool {
*Example *
path , _ := os.Getwd()
location, err := os.Stat(path)
if err != nil {
fmt.Println(err)
}
// Cool but we can make checking more explicit
// Returns drwxrwxrwx - 2147484159
fmt.Printf("%s - %d", location.Mode(),location.Mode())
// Simple check if file is readable
if os.IsReadable() {
// File / Dir Is Readable
}
// Simple check if file is writeable
if os.IsWritable() {
// File / Dir Writable
}
// Preferred Instead of !os.IsDir()
if os.IsFile() {
// X is File
}
// Touch doesn't modify the contents of myfile.txt; it just updates the timestamp
// of the file to the computer's current date and time, whatever that happens to be
// Or, if path does not exist it is created, with zero length.
os.Touch(path) // Touch the file
*Conclusion*
I know this are basic synthetic sugar but it might make it easy for new
developers and i would like to continue in my own little way
*What do you guys think ? *
Am fairly new to golang and i really appreciate the work that has gone to
the project so far.(Well done guys) I would like to make simple
contributions `os` & `os.FileMode` if it would be permitted
*Case 1 : os.FileMode*
`FileMode.Mode()` already returns the file mode but checking if a file
readable or writable can be simpler rather than parsing the mode
*Case 2 : os*
I would like to add the similar function like unix touch<http://en.wikipedia.org/wiki/Touch_(Unix)>.
This is used to change a file's access, modification timestamps and also
used to create a new empty file if it does not exist.
*Functions / Method *
func Touch(name string) (file *File, err error)
*func *(m FileMode) IsReadable() bool {
*func *(m FileMode) IsWritable() bool {
*func *(m FileMode) IsFile() bool {
*Example *
path , _ := os.Getwd()
location, err := os.Stat(path)
if err != nil {
fmt.Println(err)
}
// Cool but we can make checking more explicit
// Returns drwxrwxrwx - 2147484159
fmt.Printf("%s - %d", location.Mode(),location.Mode())
// Simple check if file is readable
if os.IsReadable() {
// File / Dir Is Readable
}
// Simple check if file is writeable
if os.IsWritable() {
// File / Dir Writable
}
// Preferred Instead of !os.IsDir()
if os.IsFile() {
// X is File
}
// Touch doesn't modify the contents of myfile.txt; it just updates the timestamp
// of the file to the computer's current date and time, whatever that happens to be
// Or, if path does not exist it is created, with zero length.
os.Touch(path) // Touch the file
*Conclusion*
I know this are basic synthetic sugar but it might make it easy for new
developers and i would like to continue in my own little way
*What do you guys think ? *
--
---
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
---
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.