diff options
| author | Mitch Riedstra <mitch@riedstra.us> | 2017-02-06 09:06:37 -0500 |
|---|---|---|
| committer | Mitch Riedstra <mitch@riedstra.us> | 2017-02-06 09:06:37 -0500 |
| commit | 0dc6e92cd018aa0ecea5349a14599279e1a2a574 (patch) | |
| tree | 81e071239c7a0c5bd9e7d1edbcf25bd9913f656e | |
| parent | c7ab6d7782486fda6d6327ba8306e474daef677a (diff) | |
| download | steam-export-old_dev.tar.gz steam-export-old_dev.tar.xz | |
Simplified the Archive library. Added a way to pull the config from the web applicationold_dev
| -rw-r--r-- | lib/archive/archive.go | 27 | ||||
| -rw-r--r-- | lib/archive/unarchive.go | 19 | ||||
| -rw-r--r-- | lib/config/config.go | 4 | ||||
| -rw-r--r-- | lib/steam/package.go | 9 | ||||
| -rw-r--r-- | web.go | 8 |
5 files changed, 35 insertions, 32 deletions
diff --git a/lib/archive/archive.go b/lib/archive/archive.go index 639a864..2d0f4fd 100644 --- a/lib/archive/archive.go +++ b/lib/archive/archive.go @@ -12,26 +12,26 @@ import ( "strings" ) -type Archive struct { - Output string - Input []string - file *os.File -} - -func (a *Archive) Tar(compressionType string) error { +func TarToFile(Output string, Input []string, compressionType string) error { var err error - if a.file, err = os.Create(a.Output); err != nil { + file, err := os.Create(Output) + if err != nil { return err } - defer a.file.Close() + defer file.Close() + + return Tar(file, Input, compressionType) +} + +func Tar(writer io.Writer, Input []string, compressionType string) error { var twriter *tar.Writer // Set the compression type... if any switch compressionType { case "gz": - gzwriter, err := gzip.NewWriterLevel(a.file, gzip.BestSpeed) + gzwriter, err := gzip.NewWriterLevel(writer, gzip.BestSpeed) if err != nil { return err } @@ -39,21 +39,20 @@ func (a *Archive) Tar(compressionType string) error { // Write to the gzip writer twriter = tar.NewWriter(gzwriter) default: - // Write directly to the file - twriter = tar.NewWriter(a.file) + // Write directly to the io.Writer + twriter = tar.NewWriter(writer) } // Close off the tar writer when we're done defer twriter.Close() - for _, v := range a.Input { + for _, v := range Input { if err := filepath.Walk(v, tarWalkfn(twriter)); err != nil { return err } } return nil - } func tarWalkfn(writer *tar.Writer) filepath.WalkFunc { diff --git a/lib/archive/unarchive.go b/lib/archive/unarchive.go index 8a5617e..463216f 100644 --- a/lib/archive/unarchive.go +++ b/lib/archive/unarchive.go @@ -12,25 +12,24 @@ import ( "strings" ) -type Unarchive struct { - Input string - tarReader *tar.Reader -} - // Extracts a tar arcive to the current working directory // This will overwrite everything. So be careful -func (u *Unarchive) UnTar(compressionType string) error { - f, err := os.Open(u.Input) +func UnTarFromFile(InputFile, compressionType string) error { + r, err := os.Open(InputFile) if err != nil { return err } - defer f.Close() + defer r.Close() + + return UnTar(r, compressionType) +} +func UnTar(r io.Reader, compressionType string) error { var treader *tar.Reader switch compressionType { case "gz": - gzreader, err := gzip.NewReader(f) + gzreader, err := gzip.NewReader(r) if err != nil { return err } @@ -38,7 +37,7 @@ func (u *Unarchive) UnTar(compressionType string) error { treader = tar.NewReader(gzreader) default: // Read from the file directly - treader = tar.NewReader(f) + treader = tar.NewReader(r) } for { diff --git a/lib/config/config.go b/lib/config/config.go index 839acbf..ab003cb 100644 --- a/lib/config/config.go +++ b/lib/config/config.go @@ -9,8 +9,8 @@ import ( ) type Config struct { - SteamRepositories []string `yaml:"SteamRepositories"` - DefaultRepository string `yaml:"DefaultRepository"` + SteamRepositories []string `yaml:"SteamRepositories" json:"SteamRepositories"` + DefaultRepository string `yaml:"DefaultRepository" json:"DefaultRepository"` Listen string } diff --git a/lib/steam/package.go b/lib/steam/package.go index 2e25994..7a0c6a5 100644 --- a/lib/steam/package.go +++ b/lib/steam/package.go @@ -26,8 +26,7 @@ func (l *Library) PackageGameToFile(index int, file, compress string) error { return err } input := []string{"common/" + g, acf} - a := archive.Archive{Output: output, Input: input} - err = a.Tar(compress) + err = archive.TarToFile(output, input, "gz") if err != nil { return err } @@ -51,10 +50,8 @@ func (l *Library) ExtractGameFromFile(f, compress string) error { if err = os.Chdir(l.Folder); err != nil { return err } - u := &archive.Unarchive{ - Input: f, - } - if err := u.UnTar(compress); err != nil { + + if err := archive.UnTarFromFile(f, compress); err != nil { return err } @@ -20,6 +20,8 @@ func main() { api.Get("/api/libraries/", listLibraries(config)) api.Get("/api/libraries/:id", listLibrary(config)) + api.Get("/api/Config", getConfig(config)) + api.Get("/data/:value/:and/:some/:giggles", dataTest()) api.Get("/data/:value/:and", dataTest()) api.Get("/data/:value", dataTest()) @@ -33,6 +35,12 @@ func dataTest() iris.HandlerFunc { } } +func getConfig(c *config.Config) iris.HandlerFunc { + return func(ctx *iris.Context) { + ctx.JSON(200, c) + } +} + func listLibraries(c *config.Config) iris.HandlerFunc { return func(ctx *iris.Context) { libs, err := steam.ProcessMultipleLibraries(c.SteamRepositories) |
