func Untar(source, target string) error {
	file, err := os.Open(source)
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()
	var fileReader io.ReadCloser = file
	if strings.HasSuffix(source, ".gz") {
		if fileReader, err = gzip.NewReader(file); err != nil {
			log.Fatal(err)
		}
		defer fileReader.Close()
	}
	tarBallReader := tar.NewReader(fileReader)
	for {
		header, err := tarBallReader.Next()
		if err != nil {
			if err == io.EOF {
				break
			}
			return err
		}
		filename := filepath.Join(target, header.Name)
		switch header.Typeflag {
		case tar.TypeDir:
			log.Debugln("Creating directory :", filename)
			err = os.MkdirAll(filename, os.FileMode(header.Mode))  
			if err != nil {
				return err
			}
		case tar.TypeReg:
			log.Debugln("Un-tarring :", filename)
			writer, err := os.Create(filename)
			if err != nil {
				return err
			}
			if _, err = io.Copy(writer, tarBallReader); err != nil {
				return err
			}
			if err = os.Chmod(filename, os.FileMode(header.Mode)); err != nil {
				return err
			}
			writer.Close()
		default:
			log.Printf("Unable to untar type : %c in file %s", header.Typeflag, filename)
		}
	}
	return nil
}
Untar unpacks tar.gz archive
package archive
import (
	"archive/tar"
	"compress/gzip"
	"io"
	"os"
	"path/filepath"
	"strings"
	log "github.com/sirupsen/logrus"
)