-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from lucasres/feature/output-file
Add output base e output file
- Loading branch information
Showing
6 changed files
with
86 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package file | ||
|
||
import "io/ioutil" | ||
|
||
type Writer interface { | ||
Write(path, content string) error | ||
} | ||
|
||
type LocalWriter struct{} | ||
|
||
func (w *LocalWriter) Write(path, content string) error { | ||
err := ioutil.WriteFile(path, []byte(content), 0644) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func NewLocalWrite() *LocalWriter { | ||
return &LocalWriter{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package output | ||
|
||
import "github.com/lucasres/adr-gen/internal/engine" | ||
|
||
type OutputBase interface { | ||
Write(path string, hits map[string]engine.ADRHit) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package output | ||
|
||
import ( | ||
"github.com/lucasres/adr-gen/internal/engine" | ||
"github.com/lucasres/adr-gen/internal/file" | ||
) | ||
|
||
type FileOutput struct{} | ||
|
||
func (o *FileOutput) Write(path string, hits map[string]engine.ADRHit) error { | ||
w := file.NewLocalWrite() | ||
|
||
for _, hit := range hits { | ||
err := w.Write(path+hit.ID, hit.Description) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func NewFileOutput() *FileOutput { | ||
return &FileOutput{} | ||
} |