本文整理匯總了Golang中github.com/square/p2/pkg/pods.Manifest.ConfigFileName方法的典型用法代碼示例。如果您正苦於以下問題:Golang Manifest.ConfigFileName方法的具體用法?Golang Manifest.ConfigFileName怎麽用?Golang Manifest.ConfigFileName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/square/p2/pkg/pods.Manifest
的用法示例。
在下文中一共展示了Manifest.ConfigFileName方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runHooks
func (h *HookDir) runHooks(dirpath string, pod Pod, podManifest *pods.Manifest) error {
logger := h.logger.SubLogger(logrus.Fields{
"hook": dirpath,
"pod": podManifest.ID(),
"pod_path": pod.Path(),
})
configFileName, err := podManifest.ConfigFileName()
if err != nil {
return err
}
// Write manifest to a file so hooks can read it.
tmpManifestFile, err := ioutil.TempFile("", fmt.Sprintf("%s-manifest.yaml", podManifest.Id))
if err != nil {
logger.WithField("err", err).Warnln("Unable to open manifest file for hooks")
return err
}
defer os.Remove(tmpManifestFile.Name())
err = podManifest.Write(tmpManifestFile)
if err != nil {
logger.WithField("err", err).Warnln("Unable to write manifest file for hooks")
return err
}
hookEnvironment := []string{
fmt.Sprintf("HOOK=%s", path.Base(dirpath)),
fmt.Sprintf("HOOKED_POD_ID=%s", podManifest.Id),
fmt.Sprintf("HOOKED_POD_HOME=%s", pod.Path()),
fmt.Sprintf("HOOKED_POD_MANIFEST=%s", tmpManifestFile.Name()),
fmt.Sprintf("HOOKED_CONFIG_PATH=%s", path.Join(pod.ConfigDir(), configFileName)),
fmt.Sprintf("HOOKED_ENV_PATH=%s", pod.EnvDir()),
}
return runDirectory(dirpath, hookEnvironment, logger)
}
示例2: runHooks
func (h *HookDir) runHooks(dirpath string, hType HookType, pod Pod, podManifest pods.Manifest, logger logging.Logger) error {
configFileName, err := podManifest.ConfigFileName()
if err != nil {
return err
}
// Write manifest to a file so hooks can read it.
tmpManifestFile, err := ioutil.TempFile("", fmt.Sprintf("%s-manifest.yaml", podManifest.ID()))
if err != nil {
logger.WithErrorAndFields(err, logrus.Fields{
"dir": dirpath,
}).Warnln("Unable to open manifest file for hooks")
return err
}
defer os.Remove(tmpManifestFile.Name())
err = podManifest.Write(tmpManifestFile)
if err != nil {
logger.WithErrorAndFields(err, logrus.Fields{
"dir": dirpath,
}).Warnln("Unable to write manifest file for hooks")
return err
}
hookEnvironment := []string{
fmt.Sprintf("%s=%s", HOOK_ENV_VAR, path.Base(dirpath)),
fmt.Sprintf("%s=%s", HOOK_EVENT_ENV_VAR, hType.String()),
fmt.Sprintf("%s=%s", HOOKED_POD_ID_ENV_VAR, podManifest.ID()),
fmt.Sprintf("%s=%s", HOOKED_POD_HOME_ENV_VAR, pod.Path()),
fmt.Sprintf("%s=%s", HOOKED_POD_MANIFEST_ENV_VAR, tmpManifestFile.Name()),
fmt.Sprintf("%s=%s", HOOKED_CONFIG_PATH_ENV_VAR, path.Join(pod.ConfigDir(), configFileName)),
fmt.Sprintf("%s=%s", HOOKED_ENV_PATH_ENV_VAR, pod.EnvDir()),
}
return runDirectory(dirpath, hookEnvironment, logger)
}