当前位置: 首页>>代码示例>>Golang>>正文


Golang archive.Archive类代码示例

本文整理汇总了Golang中github.com/jpillora/archive.Archive的典型用法代码示例。如果您正苦于以下问题:Golang Archive类的具体用法?Golang Archive怎么用?Golang Archive使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Archive类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Build

// Build injects a script for loading the environment.
func (p *Plugin) Build(fn *function.Function, zip *archive.Archive) error {
	if len(fn.Environment) == 0 {
		return nil
	}

	fn.Log.Debug("injecting prelude")

	var buf bytes.Buffer
	file := strings.Split(fn.Handler, ".")[0]
	method := strings.Split(fn.Handler, ".")[1]

	err := prelude.Execute(&buf, struct {
		EnvFile      string
		HandleFile   string
		HandleMethod string
	}{
		EnvFile:      ".env.json",
		HandleFile:   file,
		HandleMethod: method,
	})

	if err != nil {
		return err
	}

	fn.Handler = "_apex_index.handle"

	return zip.AddBytes("_apex_index.js", buf.Bytes())
}
开发者ID:kujohn,项目名称:apex,代码行数:30,代码来源:nodejs.go

示例2: Build

// Build injects a script for loading the environment.
func (p *Plugin) Build(fn *function.Function, zip *archive.Archive) error {
	if fn.Runtime != RuntimeCanonical || len(fn.Environment) == 0 {
		return nil
	}

	fn.Log.Debug("injecting prelude")

	var buf bytes.Buffer
	file := strings.Split(fn.Handler, ".")[0]
	method := strings.Split(fn.Handler, ".")[1]

	err := prelude.Execute(&buf, struct {
		EnvFile      string
		HandleFile   string
		HandleMethod string
	}{
		EnvFile:      env.FileName,
		HandleFile:   file,
		HandleMethod: method,
	})

	if err != nil {
		return err
	}

	fn.Handler = "_apex_main.handle"

	return zip.AddBytesMTime("_apex_main.py", buf.Bytes(), time.Unix(0, 0))
}
开发者ID:elizar,项目名称:apex,代码行数:30,代码来源:python.go

示例3: Build

// Build calls mvn package, add jar contents to zipfile.
func (p *Plugin) Build(fn *function.Function, zip *archive.Archive) error {
	if fn.Runtime != RuntimeCanonical {
		return nil
	}

	if fn.Environment != nil {
		fn.Log.Debug("creating properties file")
		if err := p.generatePropertiesFile(fn); err != nil {
			return errors.New("Can't generate properties file: " + err.Error())
		}
	}

	fn.Log.Debug("creating jar")
	mvnCmd := exec.Command("mvn", "package", "-Djar.finalName="+targetJarFile)
	mvnCmd.Dir = fn.Path
	if err := mvnCmd.Run(); err != nil {
		return err
	}

	expectedJarPath := filepath.Join(fn.Path, "target", targetJarFile+".jar")
	if _, err := os.Stat(expectedJarPath); err != nil {
		return errors.New("Expected jar file not found")
	}

	fn.Log.Debug("appending compiled files")
	reader, err := azip.OpenReader(expectedJarPath)
	if err != nil {
		return err
	}
	defer reader.Close()

	for _, file := range reader.File {
		r, err := file.Open()
		if err != nil {
			return err
		}

		b, err := ioutil.ReadAll(r)
		if err != nil {
			return err
		}
		r.Close()

		zip.AddBytes(file.Name, b)
	}

	if err := p.cleanProperties(fn); err != nil {
		return err
	}

	return nil
}
开发者ID:skarnecki,项目名称:apex,代码行数:53,代码来源:java.go

示例4: Build

// Build hook adds .env.json populate with Function.Enironment.
func (p *Plugin) Build(fn *function.Function, zip *archive.Archive) error {
	if len(fn.Environment) == 0 {
		return nil
	}

	fn.Log.WithField("env", fn.Environment).Debug("adding env")

	env, err := json.Marshal(fn.Environment)
	if err != nil {
		return err
	}

	return zip.AddBytesMTime(FileName, env, time.Unix(0, 0))
}
开发者ID:elizar,项目名称:apex,代码行数:15,代码来源:env.go

示例5: Build

// Build adds the nodejs shim files.
func (p *Plugin) Build(fn *function.Function, zip *archive.Archive) error {
	if fn.Shim {
		fn.Log.Debug("add shim")

		if err := zip.AddBytes("index.js", shim.MustAsset("index.js")); err != nil {
			return err
		}

		if err := zip.AddBytes("byline.js", shim.MustAsset("byline.js")); err != nil {
			return err
		}
	}

	return nil
}
开发者ID:sirodoht,项目名称:apex,代码行数:16,代码来源:shim.go

示例6: Build

// Build adds the jar contents to zipfile.
func (p *Plugin) Build(fn *function.Function, zip *archive.Archive) error {
	if fn.Runtime != Runtime {
		return nil
	}
	fn.Runtime = RuntimeCanonical

	fn.Log.Debugf("searching for JAR (%s) in directories: %s", jarFile, strings.Join(jarSearchPaths, ", "))
	expectedJarPath := findJar(fn.Path)
	if expectedJarPath == "" {
		return errors.New("Expected jar file not found")
	}
	fn.Log.Debugf("found jar path: %s", expectedJarPath)

	fn.Log.Debug("appending compiled files")
	reader, err := azip.OpenReader(expectedJarPath)
	if err != nil {
		return err
	}
	defer reader.Close()

	for _, file := range reader.File {
		r, err := file.Open()
		if err != nil {
			return err
		}

		b, err := ioutil.ReadAll(r)
		if err != nil {
			return err
		}
		r.Close()

		zip.AddBytes(file.Name, b)
	}

	return nil
}
开发者ID:tobyjoe,项目名称:apex,代码行数:38,代码来源:java.go


注:本文中的github.com/jpillora/archive.Archive类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。