-
Notifications
You must be signed in to change notification settings - Fork 11
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 #48 from vladimirvivien/docs-examples
Add missing top-level functions; new examples added
- Loading branch information
Showing
13 changed files
with
223 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
# `gexe ` Examples | ||
* [build](./build/main.go) - Show how to build Go binaries for multiple platforms and OSes. | ||
|
||
* [build](./build/main.go) - Shows how to build Go binaries for multiple platforms and OSes. | ||
* [concurrent](./concurrent/main.go) - Shows how to execute OS commands concurrently | ||
* [filesys](./filesys/main.go) - Shows how to use the `fs` package to easily write content | ||
* [git](./git/main.go) - Uses git to print logs and commit info | ||
* [helloecho](./helloecho/main.go) - Simple example | ||
* [ping](./ping/main.go) - Stream output of long-running processes | ||
* [hellogexe](./hellogexe/main.go) - Simple example to show how to get started | ||
* [http](./http/main.go) - Shows the use of the gexe `http` package to retrieve HTTP remote resources. | ||
* [ping](./ping/main.go) - Example of streaming output of long-running processes | ||
* [pipe](./pipe/main.go) - An examples that shows how to pipe multiple OS commands |
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,36 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/vladimirvivien/gexe" | ||
) | ||
|
||
// This example shows how to execute OS commands concurrently and wait for the result. | ||
func main() { | ||
|
||
fmt.Println("Downloading 3 books concurrently from Gutenberg") | ||
|
||
// The following launches each command concurrently to download long text from Gutenberg. | ||
// The download should be faster than if ran sequentially. | ||
result := gexe.RunConcur( | ||
"wget -O /tmp/thenegro.txt https://www.gutenberg.org/cache/epub/15359/pg15359.txt", | ||
"wget -O /tmp/fleece.txt https://www.gutenberg.org/cache/epub/15265/pg15265.txt", | ||
"wget -O /tmp/conversation.txt https://www.gutenberg.org/cache/epub/31254/pg31254.txt", | ||
) | ||
|
||
// inspect result or check for errors. | ||
if len(result.ErrProcs()) > 0 { | ||
log.Println("One or more commands failed") | ||
} | ||
|
||
for _, path := range []string{"/tmp/thenegro.txt", "/tmp/fleece.txt", "/tmp/conversation.txt"} { | ||
if _, err := os.Stat(path); err == nil { | ||
fmt.Printf("file %s downloaded OK\n", path) | ||
os.RemoveAll(path) | ||
} | ||
} | ||
|
||
} |
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
File renamed without changes.
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,25 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/vladimirvivien/gexe" | ||
) | ||
|
||
func main() { | ||
fmt.Println("Download and saving text") | ||
|
||
// The following downloads a large text and saves the result | ||
url := "https://www.gutenberg.org/cache/epub/2148/pg2148.txt" | ||
|
||
if w := gexe.Write("/tmp/eapv2.txt").From(gexe.GetUrl(url).Body()); w.Err() != nil { | ||
fmt.Println(w.Err()) | ||
os.Exit(1) | ||
} | ||
|
||
if err := os.Remove("/tmp/eapv2.txt"); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} |
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,24 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/vladimirvivien/gexe" | ||
) | ||
|
||
// This example shows how to use gexe to pipe commands. | ||
// The first curl command will download a text by W. E. Du Bois, from Gutenberg, | ||
// and pipe it to the second command which returns the number of lines in that text | ||
|
||
func main() { | ||
pipe := gexe.Pipe( | ||
"curl https://www.gutenberg.org/cache/epub/15265/pg15265.txt", | ||
"wc -l", | ||
) | ||
|
||
if len(pipe.ErrProcs()) > 0 { | ||
log.Fatalf("failed to download file") | ||
} | ||
fmt.Printf("The Quest of the Silver Fleece, by W. E. B. Du Bois: has %s lines\n", pipe.LastProc().Result()) | ||
} |
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,13 @@ | ||
package gexe | ||
|
||
import "github.com/vladimirvivien/gexe/http" | ||
|
||
// Get creates a *http.ResourceReader to read resource content from HTTP server | ||
func (e *Echo) Get(url string) *http.ResourceReader { | ||
return http.Get(url) | ||
} | ||
|
||
// Post creates a *http.ResourceWriter to write content to an HTTP server | ||
func (e *Echo) Post(url string) *http.ResourceWriter { | ||
return http.Post(url) | ||
} |
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
Oops, something went wrong.