mirror of
https://github.com/jimeh/rbheap.git
synced 2026-02-19 12:56:46 +00:00
Initial hacky version of inspect source command
This commit is contained in:
52
inspect/base_inspector.go
Normal file
52
inspect/base_inspector.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package inspect
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
type BaseInspector struct {
|
||||
FilePath string
|
||||
Dump *Dump
|
||||
Verbose bool
|
||||
VerboseWriter io.Writer
|
||||
}
|
||||
|
||||
func (s *SourceInspector) Load() error {
|
||||
start := time.Now()
|
||||
s.verbose(fmt.Sprintf("Loading %s...", s.FilePath))
|
||||
|
||||
err := s.Dump.Load()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
elapsed := time.Now().Sub(start)
|
||||
s.verbose(fmt.Sprintf(
|
||||
"Loaded %d objects in %.6f seconds",
|
||||
len(s.Dump.Objects),
|
||||
elapsed.Seconds(),
|
||||
))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *BaseInspector) log(msg string) {
|
||||
if s.Verbose {
|
||||
fmt.Println(msg)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *BaseInspector) verbose(msg string) {
|
||||
if s.Verbose {
|
||||
w := s.VerboseWriter
|
||||
|
||||
if w == nil {
|
||||
w = os.Stderr
|
||||
}
|
||||
|
||||
fmt.Fprintln(w, msg)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user