本文整理汇总了Golang中github.com/docker/docker/pkg/archive.TarOptions.Compression方法的典型用法代码示例。如果您正苦于以下问题:Golang TarOptions.Compression方法的具体用法?Golang TarOptions.Compression怎么用?Golang TarOptions.Compression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/docker/docker/pkg/archive.TarOptions
的用法示例。
在下文中一共展示了TarOptions.Compression方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: do_export
func do_export(ctx *context, ctrl *ext.Controller) bool {
r := ctrl.Request
if r.MethodToLower() != "get" {
ctrl.JsonError(http.StatusMethodNotAllowed, errors.New("method not allowed"))
return true
}
directory := path.Join(ctx.app.Options.Root, r.TrimSuffixURI(".export"))
var tarOpt archive.TarOptions
tarOpt.ExcludePatterns = append(tarOpt.ExcludePatterns,
".tmp", ".h2object", "h2object.pid", "h2object.conf")
tarOpt.Compression = archive.Gzip
rd, err := archive.TarWithOptions(directory, &tarOpt)
if err != nil {
ctrl.JsonError(http.StatusInternalServerError, err)
return true
}
defer rd.Close()
_, fname := path.Split(r.TrimSuffixURI(".export"))
if fname == "" {
fname = "h2object"
}
fname = fname + ".tar.gz"
fn := path.Join(ctx.app.Options.TempRoot, fname)
fd, err := os.Create(fn)
if err != nil {
ctrl.JsonError(http.StatusInternalServerError, err)
return true
}
if _, err := io.Copy(fd, rd); err != nil {
ctrl.JsonError(http.StatusInternalServerError, err)
return true
}
fd.Close()
fout, err := os.Open(fn)
if err != nil {
ctrl.JsonError(http.StatusInternalServerError, err)
return true
}
fstat, err := fout.Stat()
if err != nil {
ctrl.JsonError(http.StatusInternalServerError, err)
return true
}
ctrl.Binary(fname, fout, fstat.Size())
return true
}
示例2: themePushCommand
func themePushCommand(ctx *cli.Context) {
workdir := ctx.GlobalString("workdir")
if workdir == "" {
fmt.Println("unknown working directory, please use -w to provide.")
os.Exit(1)
}
// directory
directory, err := filepath.Abs(workdir)
if err != nil {
fmt.Println("workdir:", err)
return
}
stdout := os.Stdout
stderr := os.Stderr
// auth check
config, err := LoadConfigFile(directory)
if err != nil {
fmt.Fprintln(stderr, err.Error())
os.Exit(1)
}
if config.Auth.Token == "" || config.Auth.Secret == "" {
fmt.Fprintln(stdout, "theme push need login first. ")
os.Exit(1)
}
h2oconf, err := app.LoadCONFIG(path.Join(directory, "h2object.conf"))
if err != nil {
fmt.Fprintln(stdout, err)
os.Exit(1)
}
host := ctx.String("Host")
port := ctx.Int("Port")
client := NewClient(directory, host, port)
var pkg Package
h2oconf.SetSection("theme")
pkg.Provider = h2oconf.StringDefault("provider", "")
if pkg.Provider == "" {
fmt.Fprintln(stderr, "please set h2object.conf [theme]provider first.")
os.Exit(1)
}
pkg.Name = h2oconf.StringDefault("name", "")
if pkg.Name == "" {
fmt.Fprintln(stderr, "please set h2object.conf [theme]name first.")
os.Exit(1)
}
pkg.Description = h2oconf.StringDefault("description", "")
if pkg.Description == "" {
fmt.Fprintln(stderr, "please set h2object.conf [theme]description first.")
os.Exit(1)
}
pkg.Version = h2oconf.StringDefault("version", "1.0.0")
public := h2oconf.BoolDefault("public", false)
pkg.Status = 1
if public == true {
pkg.Status = 2
}
pkg.Price = h2oconf.FloatDefault("price", 0.0)
pkg.Catagory = int64(h2oconf.IntDefault("catagory", 1))
var tarOpt archive.TarOptions
tarOpt.ExcludePatterns = append(tarOpt.ExcludePatterns, ".h2object")
tarOpt.Compression = archive.Gzip
rd, err := archive.TarWithOptions(directory, &tarOpt)
if err != nil {
fmt.Fprintln(stderr, err.Error())
os.Exit(1)
}
defer rd.Close()
pkg.ArchiveReader = rd
pkg.ArchiveName = pkg.Version + ".tar.gz"
if err := client.ThemePush(config.Auth.Token, &pkg); err != nil {
fmt.Fprintln(stderr, err.Error())
os.Exit(1)
}
os.Exit(0)
}