當前位置: 首頁>>代碼示例>>Golang>>正文


Golang panicwrap.Wrapped函數代碼示例

本文整理匯總了Golang中github.com/mitchellh/panicwrap.Wrapped函數的典型用法代碼示例。如果您正苦於以下問題:Golang Wrapped函數的具體用法?Golang Wrapped怎麽用?Golang Wrapped使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Wrapped函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Stderr

// Stderr returns the true stderr of the process.
func Stderr() *os.File {
	stderr := os.Stderr
	if panicwrap.Wrapped(nil) {
		stderr = wrappedStderr
	}

	return stderr
}
開發者ID:ryane,項目名稱:terraform,代碼行數:9,代碼來源:streams.go

示例2: Stdout

// Stdout returns the true stdout of the process.
func Stdout() *os.File {
	stdout := os.Stdout
	if panicwrap.Wrapped(nil) {
		stdout = wrappedStdout
	}

	return stdout
}
開發者ID:ryane,項目名稱:terraform,代碼行數:9,代碼來源:streams.go

示例3: Stdin

// Stdin returns the true stdin of the process.
func Stdin() *os.File {
	stdin := os.Stdin
	if panicwrap.Wrapped(nil) {
		stdin = wrappedStdin
	}

	return stdin
}
開發者ID:ryane,項目名稱:terraform,代碼行數:9,代碼來源:streams.go

示例4: realMain

func realMain() int {
	var wrapConfig panicwrap.WrapConfig

	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("", "terraform-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.
		outR, outW := io.Pipe()
		go copyOutput(outR)

		// 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 Terraform: %s", err)
			return 1
		}

		// If >= 0, we're the parent, so just exit
		if exitStatus >= 0 {
			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()
}
開發者ID:JasonGiedymin,項目名稱:terraform,代碼行數:56,代碼來源:main.go

示例5: realMain

func realMain() int {
	var wrapConfig panicwrap.WrapConfig

	// don't re-exec terraform as a child process for easier debugging
	if os.Getenv("TF_FORK") == "0" {
		return wrappedMain()
	}

	if !panicwrap.Wrapped(&wrapConfig) {
		// Determine where logs should go in general (requested by the user)
		logWriter, err := logging.LogOutput()
		if err != nil {
			fmt.Fprintf(os.Stderr, "Couldn't setup log output: %s", err)
			return 1
		}

		// 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("", "terraform-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()

		// 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 Terraform: %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()
}
開發者ID:mhlias,項目名稱:terraform,代碼行數:61,代碼來源:main.go

示例6: 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()
}
開發者ID:mbrodala,項目名稱:otto,代碼行數:69,代碼來源:main.go

示例7: 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()
}
開發者ID:kuuyee,項目名稱:otto-learn,代碼行數:64,代碼來源:main.go


注:本文中的github.com/mitchellh/panicwrap.Wrapped函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。