Created
November 24, 2021 11:22
-
-
Save RicardoLinck/ab7bd3c3a1eabe567eecb3b255233d11 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package cmd | |
import ( | |
"log" | |
"os" | |
"github.com/RicardoLinck/decorators/cache" | |
"github.com/RicardoLinck/decorators/service" | |
) | |
type runner interface { | |
GetData(keys ...string) error | |
} | |
type defaultRunner struct { | |
url string | |
} | |
func (d *defaultRunner) GetData(keys ...string) error { | |
c := service.NewClient(d.url) | |
cc := cache.NewCachedDataGetter(c) | |
for _, k := range keys { | |
log.Print(cc.GetData(k)) | |
} | |
return nil | |
} | |
type dryRunner struct { | |
runner | |
} | |
func (d *dryRunner) GetData(keys ...string) error { | |
log.Default().SetOutput(os.Stdout) | |
return d.runner.GetData(keys...) | |
} | |
type fileRunner struct { | |
runner | |
filePath string | |
} | |
func (f *fileRunner) GetData(keys ...string) error { | |
file, err := os.Create(f.filePath) | |
if err != nil { | |
return err | |
} | |
log.Default().SetOutput(file) | |
return f.runner.GetData(keys...) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment