Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-linux: fmt lint
CGO_ENABLE=0 GOOS=linux go build -ldflags "-w -s" -o bin/linux/hd
upx bin/linux/hd

test: fmt lint
test: fmt
go test ./... -coverprofile coverage.out

run:
Expand Down
6 changes: 6 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This project could be a Golang library to use. Please feel free to check the following examples:

| Name | Description |
|----------------------|--------------------------------------------------------------------------------------------------------------|
| [dep](dep) | Demonstrate how to check and install a set of dependency tools |
| [download](download) | Demonstrate how to use this library to download a file with the features: GitHub proxy, continuously download |
7 changes: 7 additions & 0 deletions examples/dep/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This is a demo about how to use the feature of checking and install a dependency tool.

Run this with the command:

```shell
go run .
```
38 changes: 38 additions & 0 deletions examples/dep/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module github.com/linuxsuren/http-downloader/examples/dep

go 1.17

require github.com/linuxsuren/http-downloader v0.0.55

require (
github.com/AlecAivazis/survey/v2 v2.3.2 // indirect
github.com/Microsoft/go-winio v0.4.16 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/emirpasic/gods v1.12.0 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.3.1 // indirect
github.com/go-git/go-git/v5 v5.4.2 // indirect
github.com/google/go-github/v29 v29.0.3 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/gosuri/uilive v0.0.3 // indirect
github.com/gosuri/uiprogress v0.0.1 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/xanzy/ssh-agent v0.3.0 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420 // indirect
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 // indirect
golang.org/x/text v0.3.6 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
931 changes: 931 additions & 0 deletions examples/dep/go.sum

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions examples/dep/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"fmt"
"github.com/linuxsuren/http-downloader/pkg/installer"
"os"
"os/exec"
"runtime"
)

func main() {
is := installer.Installer{
Provider: "github",
OS: runtime.GOOS,
Arch: runtime.GOARCH,
Fetch: true,
}
if err := is.CheckDepAndInstall(map[string]string{
"hd": "linuxsuren/http-downloader",
}); err != nil {
panic(err)
}

if binary, err := exec.LookPath("hd"); err != nil {
fmt.Println("cannot found the command", err)
panic(err)
} else {
cmd := exec.Command(binary, "version")
cmd.Stderr = os.Stdout // TODO this might be a bug a http-downloader
if data, err := cmd.Output(); err != nil {
fmt.Println("failed to run command", err)
} else {
fmt.Print(string(data))
}
}
}
15 changes: 15 additions & 0 deletions examples/download/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module github.com/linuxsuren/http-downloader/examples/download

go 1.17

require github.com/linuxsuren/http-downloader v0.0.55

require (
github.com/google/go-github/v29 v29.0.3 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/gosuri/uilive v0.0.3 // indirect
github.com/gosuri/uiprogress v0.0.1 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
)
897 changes: 897 additions & 0 deletions examples/download/go.sum

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions examples/download/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
installer "github.com/linuxsuren/http-downloader/pkg"
)

func main() {
targetURL := "https://github.com/LinuxSuRen/http-downloader/releases/download/v0.0.55/hd-linux-amd64.tar.gz"
if err := installer.DownloadWithContinue(targetURL,
"test.tar.gz", 0, -1, 0, true); err != nil {
panic(err)
}
}
Binary file added examples/download/test.tar.gz
Binary file not shown.