Start refactor of code into what I think is a more modular way of working
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package evelogs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
type LogFile struct {
|
||||
Path string
|
||||
}
|
||||
|
||||
// create a lofFile instance, if it's a file.
|
||||
func NewLogFile(path string) (*LogFile, error) {
|
||||
lf := &LogFile{Path: path}
|
||||
exists := lf.FileExists()
|
||||
if !exists {
|
||||
return nil, fmt.Errorf("File %s not found or is directory", lf.Path)
|
||||
}
|
||||
return lf, nil
|
||||
}
|
||||
|
||||
func (lf *LogFile) FileExists() bool {
|
||||
info, err := os.Stat(lf.Path)
|
||||
if os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
return !info.IsDir()
|
||||
}
|
||||
|
||||
func (lf *LogFile) TailFile() error {
|
||||
//lets start a goroutine to tail the file here
|
||||
return nil
|
||||
}
|
||||
|
||||
//create logFile instances from a list of paths
|
||||
func PathsToLogFiles(paths []string) ([]*LogFile, error) {
|
||||
var logFiles []*LogFile
|
||||
for _, f := range paths {
|
||||
nLogFile, err := NewLogFile(f)
|
||||
if err != nil {
|
||||
log.Printf("Error with %s: %s", f, err)
|
||||
return nil, err
|
||||
}
|
||||
logFiles = append(logFiles, nLogFile)
|
||||
}
|
||||
return logFiles, nil
|
||||
}
|
||||
Reference in New Issue
Block a user