package main

/* 
	This simply parses the command line arguments using the default golang
	package called 'flag'. This can be used as a simple template to parse
	command line arguments in other programs.

	It puts everything in a 'config' Protobuf which I think is a good
	wrapper around the 'flags' package and doesn't need a whole mess of
	global variables
*/

import "os"
import "net/http"
import "bytes"
import "io"

/*
import "log"
import "os/user"
import "flag"
import "fmt"
import "runtime"
import "strings"
import "reflect"

import "github.com/golang/protobuf/jsonpb"
import pb "git.wit.com/wit/witProtobuf"
import "git.wit.com/wit/shell"

import "github.com/davecgh/go-spew/spew"
*/

func wget(url string) (*bytes.Buffer, error) {
	buf := new(bytes.Buffer)

	// Get the data
	resp, err := http.Get(url)
	if err != nil {
		return buf, err
	}
	defer resp.Body.Close()

	buf.ReadFrom(resp.Body)
	// newStr := buf.String()
	// tmp := string(resp.Body)
	return buf, err
}

func wgetToFile(filepath string, url string) error {
	// Get the data
	resp, err := http.Get(url)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	// Create the file
	out, err := os.Create(filepath)
	if err != nil {
		return err
	}
	defer out.Close()

	// Write the body to file
	_, err = io.Copy(out, resp.Body)
	return err
}
