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


Golang syscall.Setenv函数代码示例

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


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

示例1: TestFixedGOROOT

func TestFixedGOROOT(t *testing.T) {
	if runtime.GOOS == "plan9" {
		t.Skipf("skipping plan9, it is inconsistent by allowing GOROOT to be updated by Setenv")
	}

	// Restore both the real GOROOT environment variable, and runtime's copies:
	if orig, ok := syscall.Getenv("GOROOT"); ok {
		defer syscall.Setenv("GOROOT", orig)
	} else {
		defer syscall.Unsetenv("GOROOT")
	}
	envs := runtime.Envs()
	oldenvs := append([]string{}, envs...)
	defer runtime.SetEnvs(oldenvs)

	// attempt to reuse existing envs backing array.
	want := runtime.GOROOT()
	runtime.SetEnvs(append(envs[:0], "GOROOT="+want))

	if got := runtime.GOROOT(); got != want {
		t.Errorf(`initial runtime.GOROOT()=%q, want %q`, got, want)
	}
	if err := syscall.Setenv("GOROOT", "/os"); err != nil {
		t.Fatal(err)
	}
	if got := runtime.GOROOT(); got != want {
		t.Errorf(`after setenv runtime.GOROOT()=%q, want %q`, got, want)
	}
	if err := syscall.Unsetenv("GOROOT"); err != nil {
		t.Fatal(err)
	}
	if got := runtime.GOROOT(); got != want {
		t.Errorf(`after unsetenv runtime.GOROOT()=%q, want %q`, got, want)
	}
}
开发者ID:2thetop,项目名称:go,代码行数:35,代码来源:env_test.go

示例2: TestParseEnv

// Test parsing a environment variables
func TestParseEnv(t *testing.T) {

	syscall.Setenv("BOOL", "")
	syscall.Setenv("BOOL2", "true")
	syscall.Setenv("INT", "22")
	syscall.Setenv("INT64", "0x23")
	syscall.Setenv("UINT", "24")
	syscall.Setenv("UINT64", "25")
	syscall.Setenv("STRING", "hello")
	syscall.Setenv("FLOAT64", "2718e28")
	syscall.Setenv("DURATION", "2m")

	f := NewFlagSet(os.Args[0], ContinueOnError)

	boolFlag := f.Bool("bool", false, "bool value")
	bool2Flag := f.Bool("bool2", false, "bool2 value")
	intFlag := f.Int("int", 0, "int value")
	int64Flag := f.Int64("int64", 0, "int64 value")
	uintFlag := f.Uint("uint", 0, "uint value")
	uint64Flag := f.Uint64("uint64", 0, "uint64 value")
	stringFlag := f.String("string", "0", "string value")
	float64Flag := f.Float64("float64", 0, "float64 value")
	durationFlag := f.Duration("duration", 5*time.Second, "time.Duration value")

	err := f.ParseEnv(os.Environ())
	if err != nil {
		t.Fatal("expected no error; got ", err)
	}
	if *boolFlag != true {
		t.Error("bool flag should be true, is ", *boolFlag)
	}
	if *bool2Flag != true {
		t.Error("bool2 flag should be true, is ", *bool2Flag)
	}
	if *intFlag != 22 {
		t.Error("int flag should be 22, is ", *intFlag)
	}
	if *int64Flag != 0x23 {
		t.Error("int64 flag should be 0x23, is ", *int64Flag)
	}
	if *uintFlag != 24 {
		t.Error("uint flag should be 24, is ", *uintFlag)
	}
	if *uint64Flag != 25 {
		t.Error("uint64 flag should be 25, is ", *uint64Flag)
	}
	if *stringFlag != "hello" {
		t.Error("string flag should be `hello`, is ", *stringFlag)
	}
	if *float64Flag != 2718e28 {
		t.Error("float64 flag should be 2718e28, is ", *float64Flag)
	}
	if *durationFlag != 2*time.Minute {
		t.Error("duration flag should be 2m, is ", *durationFlag)
	}
}
开发者ID:namsral,项目名称:flag,代码行数:57,代码来源:extras_test.go

示例3: Setenv

// Setenv sets the value of the environment variable named by the key.
// It returns an error, if any.
func Setenv(key, value string) error {
	err := syscall.Setenv(key, value)
	if err != nil {
		return NewSyscallError("setenv", err)
	}
	return nil
}
开发者ID:jroelofs,项目名称:darwin-gcc-5,代码行数:9,代码来源:env.go

示例4: init

func init() {
	switch path, _ := syscall.Getenv("GOCOVOUT"); path {
	case "":
		// No tracing
	case "-":
		Default.Tracer = fdwriter(syscall.Stdout)
	default:
		// Add the process ID to the filename.
		// TODO handle PID reuse by checking if file exists.
		path += "." + itoa(syscall.Getpid())

		mode := syscall.O_WRONLY | syscall.O_CREAT | syscall.O_TRUNC
		fd, err := syscall.Open(path, mode, 0666)
		if err != nil {
			msg := "gocov: failed to create log file: "
			msg += err.Error() + "\n"
			write(fdwriter(syscall.Stderr), []byte(msg))
			syscall.Exit(1)
		}
		Default.Tracer = fdwriter(int(fd))
	}

	// Remove GOCOVOUT from environ, to prevent noise from child processes.
	// TODO Don't do this; append .pid to output filename.
	syscall.Setenv("GOCOVOUT", "")
}
开发者ID:bouticfactory,项目名称:gocov,代码行数:26,代码来源:gocov.go

示例5: mount_osxfusefs

func mount_osxfusefs(fd int, mnt string) error {
	var err error
	if err = syscall.Setenv("MOUNT_FUSEFS_CALL_BY_LIB", ""); err != nil {
		return err
	}
	if err = syscall.Setenv("MOUNT_FUSEFS_DAEMON_PATH", "/Library/Filesystems/osxfusefs.fs/Support/mount_osxfusefs"); err != nil {
		return err
	}
	cmd := exec.Command("/Library/Filesystems/osxfusefs.fs/Support/mount_osxfusefs", "-o", "iosize=4096", strconv.Itoa(fd), mnt)
	/*cmd.SysProcAttr = &syscall.SysProcAttr{
		//Setsid:  true,
		Setpgid: true,
	}*/
	out, err := cmd.CombinedOutput()
	if len(out) > 0 || err != nil {
		fmt.Errorf("mount_osxfusefs: %q, %v", out, err)
	}
	return nil
}
开发者ID:petar,项目名称:rscfuse,代码行数:19,代码来源:mount_darwin.go

示例6: testSetGetenv

func testSetGetenv(t *testing.T, key, value string) {
	err := syscall.Setenv(key, value)
	if err != nil {
		t.Fatalf("Setenv failed to set %q: %v", value, err)
	}
	newvalue, found := syscall.Getenv(key)
	if !found {
		t.Fatalf("Getenv failed to find %v variable (want value %q)", key, value)
	}
	if newvalue != value {
		t.Fatalf("Getenv(%v) = %q; want %q", key, newvalue, value)
	}
}
开发者ID:achanda,项目名称:go,代码行数:13,代码来源:syscall_test.go

示例7: init

func init() {
	switch path, _ := syscall.Getenv("GOCOVOUT"); path {
	case "":
		// No tracing
	case "-":
		Default.Tracer = fdwriter(syscall.Stdout)
	default:
		mode := syscall.O_WRONLY | syscall.O_CREAT | syscall.O_APPEND
		fd, err := syscall.Open(path, mode, 0666)
		if err != nil {
			msg := "gocov: failed to create log file: "
			msg += err.Error() + "\n"
			write(fdwriter(syscall.Stderr), []byte(msg))
			syscall.Exit(1)
		}
		Default.Tracer = fdwriter(int(fd))
	}

	// Remove GOCOVOUT from environ, to prevent noise from child processes.
	// TODO Don't do this; append .pid to output filename.
	syscall.Setenv("GOCOVOUT", "")
}
开发者ID:davecheney,项目名称:gocov,代码行数:22,代码来源:gocov.go

示例8: initTestingZone

func initTestingZone() {
	syscall.Setenv("TZ", "America/Los_Angeles")
	initLocal()
}
开发者ID:kostyll,项目名称:gccpy,代码行数:4,代码来源:zoneinfo_unix.go

示例9: Setenv

func Setenv(key, value string) error {
	return syscall.Setenv(key, value)
}
开发者ID:Chengyumeng,项目名称:sys,代码行数:3,代码来源:env_plan9.go

示例10: PrependToGoPath

func (genv *GoatEnv) PrependToGoPath() error {
	gopath, _ := syscall.Getenv("GOPATH")
	return syscall.Setenv("GOPATH", genv.AbsDepDir()+":"+gopath)
}
开发者ID:kinghrothgar,项目名称:goat,代码行数:4,代码来源:env.go


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