本文整理汇总了Golang中github.com/mitchellh/panicwrap.WrapConfig.CookieKey方法的典型用法代码示例。如果您正苦于以下问题:Golang WrapConfig.CookieKey方法的具体用法?Golang WrapConfig.CookieKey怎么用?Golang WrapConfig.CookieKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/mitchellh/panicwrap.WrapConfig
的用法示例。
在下文中一共展示了WrapConfig.CookieKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: realMain
func realMain() int {
// Set a custom panicwrap cookie key and value. Since we're executing
// other panicwrap executables, the default cookie key/value cause
// weird errors if we don't change them.
var wrapConfig panicwrap.WrapConfig
wrapConfig.CookieKey = "OTTO_PANICWRAP_COOKIE"
wrapConfig.CookieValue = fmt.Sprintf(
"otto-%s-%s-%s", Version, VersionPrerelease, GitCommit)
if !panicwrap.Wrapped(&wrapConfig) {
// Determine where logs should go in general (requested by the user)
logWriter, err := logOutput()
if err != nil {
fmt.Fprintf(os.Stderr, "Couldn't setup log output: %s", err)
return 1
}
if logWriter == nil {
logWriter = ioutil.Discard
}
// We always send logs to a temporary file that we use in case
// there is a panic. Otherwise, we delete it.
logTempFile, err := ioutil.TempFile("", "otto-log")
if err != nil {
fmt.Fprintf(os.Stderr, "Couldn't setup logging tempfile: %s", err)
return 1
}
defer os.Remove(logTempFile.Name())
defer logTempFile.Close()
// Tell the logger to log to this file
os.Setenv(EnvLog, "")
os.Setenv(EnvLogFile, "")
// Setup the prefixed readers that send data properly to
// stdout/stderr.
doneCh := make(chan struct{})
outR, outW := io.Pipe()
go copyOutput(outR, doneCh)
// Create the configuration for panicwrap and wrap our executable
wrapConfig.Handler = panicHandler(logTempFile)
wrapConfig.Writer = io.MultiWriter(logTempFile, logWriter)
wrapConfig.Stdout = outW
exitStatus, err := panicwrap.Wrap(&wrapConfig)
if err != nil {
fmt.Fprintf(os.Stderr, "Couldn't start Otto: %s", err)
return 1
}
// If >= 0, we're the parent, so just exit
if exitStatus >= 0 {
// Close the stdout writer so that our copy process can finish
outW.Close()
// Wait for the output copying to finish
<-doneCh
return exitStatus
}
// We're the child, so just close the tempfile we made in order to
// save file handles since the tempfile is only used by the parent.
logTempFile.Close()
}
// Call the real main
return wrappedMain()
}
示例2: realMain
func realMain() int {
//使用panicwrap封装panic
var wrapConfig panicwrap.WrapConfig
wrapConfig.CookieKey = "OTTO_PANICWRAP_COOKIE"
wrapConfig.CookieValue = fmt.Sprintf("otto-%s-%s-%s", Version, VersionPrerelease, GitCommit)
//fmt.Printf("warpConfig : %+v\n", wrapConfig)
if !panicwrap.Wrapped(&wrapConfig) {
fmt.Println("没有封装wrapConfig配置")
logWriter, err := logOutput()
if err != nil {
fmt.Fprintf(os.Stderr, "不能设置Log输出到:%s", err)
return 1
}
if logWriter == nil {
logWriter = ioutil.Discard //Discard实现了io.Writer接口
}
//当发生panic时我们发送log到临时文件,否则就删除
logTempFile, err := ioutil.TempFile("", "kuuyee-otto-log")
if err != nil {
fmt.Fprintf(os.Stderr, "不能设置Log临时文件:%s", err)
return 1
}
defer os.Remove(logTempFile.Name())
defer logTempFile.Close()
// 告诉logger把日志输出到这个文件
os.Setenv(Envlog, "")
os.Setenv(EnvLogFile, "")
// 设置发送到stdout/stderr数据的读取前缀
doneCh := make(chan struct{})
outR, outW := io.Pipe()
go copyOutput(outR, doneCh)
// 创建panicwrap配置
wrapConfig.Handler = panicHandler(logTempFile)
wrapConfig.Writer = io.MultiWriter(logTempFile, logWriter)
wrapConfig.Stdout = outW
exitStatus, err := panicwrap.Wrap(&wrapConfig)
if err != nil {
fmt.Fprintf(os.Stderr, "不能启动Otto: %s", err)
return 1
}
// 如果>=0,那么我们是父进程,所以退出
if exitStatus >= 0 {
outW.Close()
<-doneCh
return exitStatus
}
// 我们是子,所以关闭tempfile
logTempFile.Close()
}
fmt.Printf("[KuuYee_DEBUG]====> %s\n", "main.go/realMain/81")
//调用真正的main函数
return wrappedMain()
}