refactor: output browsing data package

This commit is contained in:
ᴍᴏᴏɴD4ʀᴋ
2022-04-18 00:47:39 +08:00
parent 13c92b0a2e
commit 04e620e54c
8 changed files with 58 additions and 35 deletions
+13 -5
View File
@@ -13,13 +13,13 @@ import (
"hack-browser-data/internal/browingdata"
)
type outPutter struct {
type OutPutter struct {
json bool
csv bool
}
func New(flag string) *outPutter {
o := &outPutter{}
func New(flag string) *OutPutter {
o := &OutPutter{}
if flag == "json" {
o.json = true
} else {
@@ -28,7 +28,7 @@ func New(flag string) *outPutter {
return o
}
func (o *outPutter) Write(data browingdata.Source, writer io.Writer) error {
func (o *OutPutter) Write(data browingdata.Source, writer io.Writer) error {
switch o.json {
case true:
encoder := jsoniter.NewEncoder(writer)
@@ -45,7 +45,7 @@ func (o *outPutter) Write(data browingdata.Source, writer io.Writer) error {
}
}
func (o *outPutter) CreateFile(dir, filename string) (*os.File, error) {
func (o *OutPutter) CreateFile(dir, filename string) (*os.File, error) {
if filename == "" {
return nil, errors.New("empty filename")
}
@@ -68,3 +68,11 @@ func (o *outPutter) CreateFile(dir, filename string) (*os.File, error) {
}
return file, nil
}
func (o *OutPutter) Ext() string {
if o.json {
return ".json"
} else {
return ".csv"
}
}