func processTarFile(uncompressedStream *gzip.Reader) (string, error) {
	var dirName []string
	var count = 0
	var totalWrote int64
	fileCount := 0
	tarReader := tar.NewReader(uncompressedStream)
	for true {
		header, err := tarReader.Next()
		if err == io.EOF || header == nil {
			break
		}
		if header.Typeflag == tar.TypeDir {
			_ = os.MkdirAll(header.Name, 0755)
		} else if header.Typeflag == tar.TypeReg {
			dir, _ := filepath.Split(header.Name)
			if count == 0 {
				dirName = strings.Split(dir, "/")
				count += 1
			}
			tw, err := handleRegularFile(dir, header, tarReader, totalWrote, fileCount)
			if err != nil {
				return "", err
			}
			totalWrote = tw
		}
		fileCount++
	}
	return dirName[0], nil
}
Process tar file
package config
import (
	"archive/tar"
	"compress/gzip"
	"encoding/json"
	"errors"
	"fmt"
	"github.com/ghodss/yaml"
	log "github.com/sirupsen/logrus"
	"io"
	"io/ioutil"
	"k8splugin/util"
	"os"
	"path/filepath"
	"strings"
)
type AppAuthConfigBuilder struct {
	AppInsId string
	Ak       string
	Sk       string
}
func NewBuildAppAuthConfig(appInsId string, ak string, sk string) (appAuthCfg AppAuthConfigBuilder) {
	appAuthCfg.AppInsId = appInsId
	appAuthCfg.Ak = ak
	appAuthCfg.Sk = sk
	return
}
func (_ *AppAuthConfigBuilder) extractTarFile(gzipStream io.Reader) (string, error) {
	uncompressedStream, err := gzip.NewReader(gzipStream)
	if err != nil {
		log.Error("failed to read the file")
		return "", err
	}
	dirName, err := processTarFile(uncompressedStream)
	if err != nil {
		log.Error("failed to process the tar file")
		return "", err
	}
	defer uncompressedStream.Close()
	return dirName, nil
}