File is now capable of printing errors
This commit is contained in:
parent
4d94e5738d
commit
64a8a2445a
56
file/file.go
56
file/file.go
@ -1,23 +1,23 @@
|
|||||||
package file
|
package file
|
||||||
|
|
||||||
import "os"
|
import "os"
|
||||||
import "path/filepath"
|
import "log"
|
||||||
|
|
||||||
|
var logger = log.New(os.Stderr, "", 0)
|
||||||
|
|
||||||
|
// File represents a read only file that can print out formatted errors.
|
||||||
type File struct {
|
type File struct {
|
||||||
path string
|
path string
|
||||||
moduleName string
|
|
||||||
file *os.File
|
file *os.File
|
||||||
currentLine int
|
currentLine int
|
||||||
lines [][]byte
|
lines [][]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open opens the file specified by path and returns a new File struct. The
|
// Open opens the file specified by path and returns a new File struct.
|
||||||
// module name is automatically inferred through hte file's parent directory.
|
|
||||||
func Open (path string) (file *File, err error) {
|
func Open (path string) (file *File, err error) {
|
||||||
file = &File {
|
file = &File {
|
||||||
path: path,
|
path: path,
|
||||||
moduleName: filepath.Dir(path),
|
lines: [][]byte { []byte { } },
|
||||||
lines: [][]byte { []byte { } },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
file.file, err = os.OpenFile(path, os.O_RDONLY, 0660)
|
file.file, err = os.OpenFile(path, os.O_RDONLY, 0660)
|
||||||