diff --git a/commands/root.go b/commands/root.go index 70189a2..8f4dd8f 100644 --- a/commands/root.go +++ b/commands/root.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "time" "github.com/MakeNowJust/heredoc" @@ -30,7 +31,9 @@ var RootCmd = &cobra.Command{ SilenceErrors: true, SilenceUsage: true, Example: heredoc.Doc(` - $ fastget https://file.example.com + $ fastget https://file.example.com // Basic Usage + $ fastget http://speedtest.tele2.net/10MB.zip -H "Authorization: Basic ASYFASUF" // Custom Header + $ fastget http://speedtest.tele2.net/10MB.zip -w 6 // Increased no. of workers $ fastget -v `), RunE: runCommand, @@ -52,6 +55,8 @@ func runCommand(cmd *cobra.Command, args []string) error { threads, _ := cmd.Flags().GetInt("workers") + headers, _ := cmd.Flags().GetStringArray("header") + url := args[0] fg, err := fastget.NewFastGetter(url) @@ -61,6 +66,12 @@ func runCommand(cmd *cobra.Command, args []string) error { } fg.Workers = threads + for _, header := range headers { + split := strings.Split(header, ":") + fg.Headers[split[0]] = split[1] + fmt.Println(header) + } + fmt.Println("Initializing download..") mpbars := make(map[int]*barStatus) @@ -129,6 +140,7 @@ func init() { RootCmd.Flags().BoolP("debug", "d", false, "show debug information") RootCmd.Flags().IntP("workers", "w", 3, "use parellel threads") RootCmd.Flags().StringP("output", "o", ".", "output file to be written") + RootCmd.Flags().StringArrayP("header", "H", []string{}, "output file to be written") } func executeVersionCmd() { diff --git a/fastget.go b/fastget.go index 27c7a05..10b351f 100644 --- a/fastget.go +++ b/fastget.go @@ -44,6 +44,7 @@ func NewFastGetter(fileURL string) (*FastGetter, error) { FileURL: fileURL, Workers: 3, OutputFile: path.Base(fileURL), + Headers: make(map[string]string), } return fg, nil }