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


Golang runtime.Version函数代码示例

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


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

示例1: TestCrossCompile

func TestCrossCompile(t *testing.T) {
	if strings.HasPrefix(runtime.Version(), "go1.4") {
		t.Skip("skipping cross compile test, not supported on", runtime.Version())
	}
	gb := T{T: t}
	defer gb.cleanup()
	gb.tempDir("src/p")
	gb.tempFile("src/p/main.go", `package main
func main() { println("hello world") }
`)
	gb.cd(gb.tempdir)
	tmpdir := gb.tempDir("tmp")
	goos := "windows"
	if runtime.GOOS == goos {
		goos = "linux"
	}
	gb.setenv("TMP", tmpdir)
	gb.setenv("GOOS", goos)
	gb.run("build")
	gb.mustBeEmpty(tmpdir)
	name := fmt.Sprintf("p-%s-%s", goos, runtime.GOARCH)
	if goos == "windows" {
		name += ".exe"
	}
	gb.mustExist(gb.path("bin", name))
	gb.wantExecutable(gb.path("bin", name), "expected $PROJECT/bin/p-$GOOS-$GOARCH")
}
开发者ID:yonglehou,项目名称:gb,代码行数:27,代码来源:gb_test.go

示例2: Prepare

func (env *TravisEnvironment) Prepare() {
	msg("preparing environment for Travis CI\n")

	run("go", "get", "golang.org/x/tools/cmd/cover")
	run("go", "get", "github.com/mattn/goveralls")
	run("go", "get", "github.com/mitchellh/gox")

	if runtime.GOOS == "darwin" {
		// install the libraries necessary for fuse
		run("brew", "install", "caskroom/cask/brew-cask")
		run("brew", "cask", "install", "osxfuse")
	}

	// only test cross compilation on linux with Travis
	if runtime.GOOS == "linux" {
		env.goxArch = []string{"386", "amd64"}
		if !strings.HasPrefix(runtime.Version(), "go1.3") {
			env.goxArch = append(env.goxArch, "arm")
		}

		env.goxOS = []string{"linux", "darwin", "freebsd", "openbsd", "windows"}
	} else {
		env.goxArch = []string{runtime.GOARCH}
		env.goxOS = []string{runtime.GOOS}
	}

	msg("gox: OS %v, ARCH %v\n", env.goxOS, env.goxArch)

	if !strings.HasPrefix(runtime.Version(), "go1.5") {
		run("gox", "-build-toolchain",
			"-os", strings.Join(env.goxOS, " "),
			"-arch", strings.Join(env.goxArch, " "))
	}
}
开发者ID:JaCoB1123,项目名称:restic,代码行数:34,代码来源:run_integration_tests.go

示例3: main

func main() {
	flag.Parse()

	if *flagVersion {
		fmt.Fprintf(os.Stderr, "publisher version: %s\nGo version: %s (%s/%s)\n",
			buildinfo.Version(), runtime.Version(), runtime.GOOS, runtime.GOARCH)
		return
	}

	logf("Starting publisher version %s; Go %s (%s/%s)", buildinfo.Version(), runtime.Version(),
		runtime.GOOS, runtime.GOARCH)

	listenAddr, err := app.ListenAddress()
	if err != nil {
		logger.Fatalf("Listen address: %v", err)
	}
	conf := appConfig()
	ph := newPublishHandler(conf)
	if err := ph.initRootNode(); err != nil {
		logf("%v", err)
	}
	ws := webserver.New()
	ws.Logger = logger
	ws.Handle("/", ph)
	if conf.HTTPSCert != "" && conf.HTTPSKey != "" {
		ws.SetTLS(conf.HTTPSCert, conf.HTTPSKey)
	}
	if err := ws.Listen(listenAddr); err != nil {
		logger.Fatalf("Listen: %v", err)
	}
	ws.Serve()
}
开发者ID:pombredanne,项目名称:camlistore,代码行数:32,代码来源:main.go

示例4: New

// New constructs a new AirbrakeHandler.
//
// The projectId & key parameters should be obtained from airbrake. The
// environment parameter is the name of the environment to report errors under.
func New(projectId int64, key string, environment string) *AirbrakeHandler {
	repoRoot, _, repoVersion := util.RepoInfo()
	context := &AirbrakeContext{
		OS:            runtime.GOOS + " " + runtime.GOARCH, //TODO syscall.Uname() when in linux
		Language:      "go " + runtime.Version(),
		Environment:   environment,
		RootDirectory: repoRoot,
		Version:       repoVersion,
	}

	env := map[string]string{}
	env["_"] = os.Args[0]
	env["GOVERSION"] = runtime.Version()
	env["GOMAXPROCS"] = fmt.Sprintf("%d", runtime.GOMAXPROCS(0))
	env["GOROOT"] = runtime.GOROOT()
	env["HOSTNAME"], _ = os.Hostname()

	aURL, _ := url.Parse(fmt.Sprintf("%s/api/v3/projects/%d/notices?key=%s", airbrakeURL, projectId, key))
	return &AirbrakeHandler{
		AirbrakeURL: aURL,
		projectId:   projectId,
		key:         key,
		Context:     context,
		Env:         env,
	}
}
开发者ID:christianbak,项目名称:sawmill,代码行数:30,代码来源:airbrake.go

示例5: TestTestGoCommand

func TestTestGoCommand(t *testing.T) {
	var buf bytes.Buffer
	oldStderr := stderr
	stderr = &buf
	defer func() {
		stderr = oldStderr
	}()

	var devel = false
	if runtime.Version()[:5] == "devel" {
		devel = true
	}

	cmdPath := getCommandPath("go")

	if err := testGoCommand(cmdPath); err != nil {
		t.Fatal("Unexptected error testing go command: ", err.Error())
	}

	if !devel {
		if got := buf.String(); got != "" {
			t.Fatal("Didn't expect a message to stderr, but got one: " + got)
		}
	} else {
		expected := fmt.Sprintf("Warning running with development build: go "+
			"version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH)
		if got := buf.String(); got != expected {
			t.Fatalf("Expected the warning message to be %q, but got %q", expected,
				got)
		}
	}
}
开发者ID:Thomasdezeeuw,项目名称:gobuild,代码行数:32,代码来源:main_test.go

示例6: Prepare

// Prepare installs dependencies and starts services in order to run the tests.
func (env *TravisEnvironment) Prepare() error {
	env.env = make(map[string]string)

	msg("preparing environment for Travis CI\n")

	for _, pkg := range []string{
		"golang.org/x/tools/cmd/cover",
		"github.com/pierrre/gotestcover",
	} {
		err := run("go", "get", pkg)
		if err != nil {
			return err
		}
	}

	if err := env.getMinio(); err != nil {
		return err
	}
	if err := env.runMinio(); err != nil {
		return err
	}

	if *runCrossCompile && !(runtime.Version() < "go1.7") {
		// only test cross compilation on linux with Travis
		if err := run("go", "get", "github.com/mitchellh/gox"); err != nil {
			return err
		}
		if runtime.GOOS == "linux" {
			env.goxOSArch = []string{
				"linux/386", "linux/amd64",
				"windows/386", "windows/amd64",
				"darwin/386", "darwin/amd64",
				"freebsd/386", "freebsd/amd64",
				"opendbsd/386", "opendbsd/amd64",
			}
			if !strings.HasPrefix(runtime.Version(), "go1.3") {
				env.goxOSArch = append(env.goxOSArch,
					"linux/arm", "freebsd/arm")
			}
		} else {
			env.goxOSArch = []string{runtime.GOOS + "/" + runtime.GOARCH}
		}

		msg("gox: OS/ARCH %v\n", env.goxOSArch)

		if runtime.Version() < "go1.5" {
			err := run("gox", "-build-toolchain",
				"-osarch", strings.Join(env.goxOSArch, " "))

			if err != nil {
				return err
			}
		}
	}

	return nil
}
开发者ID:ckemper67,项目名称:restic,代码行数:58,代码来源:run_integration_tests.go

示例7: TestAirbrakeHandler

func TestAirbrakeHandler(t *testing.T) {
	ah := New(123456, "0123456789abcdef0123456789abcdef", "testing")

	ah.Context.URL = "http://example.com/airbrake"
	ah.Context.UserId = "johndoe"
	ah.Context.UserName = "john doe"
	ah.Context.UserEmail = "[email protected]"

	logEvent := event.New(1, event.Warning, "test AirbrakeHandler", map[string]interface{}{"foo": "bar"}, true)
	err := ah.Event(logEvent)
	require.NoError(t, err)

	notice := testAirbrakeServer.notices[len(testAirbrakeServer.notices)-1]

	nNotifier := notice["notifier"].(map[string]interface{})
	assert.Equal(t, notifier.Name, nNotifier["name"])
	assert.Equal(t, notifier.Version, nNotifier["version"])
	assert.Equal(t, notifier.Url, nNotifier["url"])

	_, selfFile, _, _ := runtime.Caller(0)
	nErrors := notice["errors"].([]interface{})
	nError := nErrors[0].(map[string]interface{})
	nBacktrace := nError["backtrace"].([]interface{})
	nBacktrace0 := nBacktrace[0].(map[string]interface{})
	assert.Equal(t, "warning", nError["type"])
	assert.Equal(t, "test AirbrakeHandler", nError["message"])
	assert.Equal(t, selfFile, nBacktrace0["file"])
	assert.NotEmpty(t, nBacktrace0["line"])
	assert.Equal(t, "TestAirbrakeHandler", nBacktrace0["function"])

	var repoVersion string
	execCmd := exec.Command("git", "describe", "--dirty", "--tags", "--always")
	output, err := execCmd.Output()
	if err == nil {
		repoVersion = string(bytes.TrimRight(output, "\n"))
	}
	nContext := notice["context"].(map[string]interface{})
	assert.Equal(t, runtime.GOOS+" "+runtime.GOARCH, nContext["os"])
	assert.Equal(t, "go "+runtime.Version(), nContext["language"])
	assert.Equal(t, "testing", nContext["environment"])
	assert.Equal(t, repoVersion, nContext["version"])
	assert.Equal(t, "http://example.com/airbrake", nContext["url"])
	assert.Equal(t, "johndoe", nContext["userId"])
	assert.Equal(t, "john doe", nContext["userName"])
	assert.Equal(t, "[email protected]", nContext["userEmail"])

	hostname, _ := os.Hostname()
	nEnvironment := notice["environment"].(map[string]interface{})
	assert.Equal(t, fmt.Sprintf("%d", runtime.GOMAXPROCS(0)), nEnvironment["GOMAXPROCS"])
	assert.Equal(t, runtime.Version(), nEnvironment["GOVERSION"])
	assert.Equal(t, runtime.GOROOT(), nEnvironment["GOROOT"])
	assert.Equal(t, hostname, nEnvironment["HOSTNAME"])

	nParams := notice["params"].(map[string]interface{})
	assert.Equal(t, "bar", nParams["foo"])
}
开发者ID:christianbak,项目名称:sawmill,代码行数:56,代码来源:airbrake_test.go

示例8: getSupportedPlatforms

func getSupportedPlatforms() []Platform {
	if strings.HasPrefix(runtime.Version(), "go1.4") {
		return SUPPORTED_PLATFORMS_1_4
	}
	if strings.HasPrefix(runtime.Version(), "go1.3") {
		return SUPPORTED_PLATFORMS_1_3
	}
	// otherwise default to <= go1.2
	return SUPPORTED_PLATFORMS_1_1
}
开发者ID:himanshugpt,项目名称:evergreen,代码行数:10,代码来源:platforms.go

示例9: TestVersion

func TestVersion(t *testing.T) {

	r := &g2z.AgentRequest{}
	s, err := Version(r)

	if err != nil {
		t.Error(err.Error())
	}

	if s != runtime.Version() {
		t.Errorf("Expected Version() to return '%s', got '%s'", runtime.Version(), s)
	}
}
开发者ID:cavaliercoder,项目名称:g2z,代码行数:13,代码来源:dummy_test.go

示例10: main

func main() {
	ftmdLog.Info("//////////////////////// Copyright 2015 Factom Foundation")
	ftmdLog.Info("//////////////////////// Use of this source code is governed by the MIT")
	ftmdLog.Info("//////////////////////// license that can be found in the LICENSE file.")

	ftmdLog.Warning("Go compiler version:", runtime.Version())
	fmt.Println("Go compiler version:", runtime.Version())
	cp.CP.AddUpdate("gocompiler",
		"system",
		fmt.Sprintln("Go compiler version: ", runtime.Version()),
		"",
		0)
	cp.CP.AddUpdate("copyright",
		"system",
		"Legal",
		"Copyright 2015 Factom Foundation\n"+
			"Use of this source code is governed by the MIT\n"+
			"license that can be found in the LICENSE file.",
		0)

	if !isCompilerVersionOK() {
		for i := 0; i < 30; i++ {
			fmt.Println("!!! !!! !!! ERROR: unsupported compiler version !!! !!! !!!")
		}
		time.Sleep(time.Second)
		os.Exit(1)
	}

	// Load configuration file and send settings to components
	loadConfigurations()

	// create the $home/.factom directory if it does not exist
	os.Mkdir(homeDir, 0755)

	// Initialize db
	initDB()

	// Use all processor cores.
	runtime.GOMAXPROCS(runtime.NumCPU())

	//Up some limits.
	if err := limits.SetLimits(); err != nil {
		os.Exit(1)
	}

	// Work around defer not working after os.Exit()
	if err := factomdMain(); err != nil {
		os.Exit(1)
	}

}
开发者ID:FactomProject,项目名称:FactomCode,代码行数:51,代码来源:factomd.go

示例11: NewBuildContext

func NewBuildContext(archSuffix string) *build.Context {
	if strings.HasPrefix(runtime.Version(), "go1.") && runtime.Version()[4] < '3' {
		panic("GopherJS requires Go 1.3. Please upgrade.")
	}
	return &build.Context{
		GOROOT:      build.Default.GOROOT,
		GOPATH:      build.Default.GOPATH,
		GOOS:        build.Default.GOOS,
		GOARCH:      archSuffix,
		Compiler:    "gc",
		BuildTags:   []string{"netgo"},
		ReleaseTags: build.Default.ReleaseTags,
	}
}
开发者ID:kpsmith,项目名称:gopherjs,代码行数:14,代码来源:build.go

示例12: TestCGONext

func TestCGONext(t *testing.T) {
	// Test if one can do 'next' in a cgo binary
	// On OSX with Go < 1.5 CGO is not supported due to: https://github.com/golang/go/issues/8973
	if runtime.GOOS == "darwin" && strings.Contains(runtime.Version(), "1.4") {
		return
	}

	withTestProcess("cgotest", t, func(p *Process, fixture protest.Fixture) {
		pc, err := p.FindFunctionLocation("main.main", true, 0)
		if err != nil {
			t.Fatal(err)
		}
		_, err = p.SetBreakpoint(pc)
		if err != nil {
			t.Fatal(err)
		}
		err = p.Continue()
		if err != nil {
			t.Fatal(err)
		}
		err = p.Next()
		if err != nil {
			t.Fatal(err)
		}
	})
}
开发者ID:vornet,项目名称:delve,代码行数:26,代码来源:proc_test.go

示例13: TestTestRace

// check that go test -race builds and runs a racy binary, and that it finds the race.
func TestTestRace(t *testing.T) {
	if !canRace {
		t.Skip("skipping because race detector not supported")
	}
	if strings.HasPrefix(runtime.Version(), "go1.4") {
		t.Skipf("skipping race test as Go version %v incorrectly marks race failures as success", runtime.Version())
	}

	gb := T{T: t}
	defer gb.cleanup()

	gb.tempDir("src/race")
	gb.tempFile("src/race/map_test.go", `package race
import "testing"

func TestRaceMapRW(t *testing.T) {
        m := make(map[int]int)
        ch := make(chan bool, 1)
        go func() {
                _ = m[1]
                ch <- true
        }()
        m[1] = 1
        <-ch
}
`)
	gb.cd(gb.tempdir)
	tmpdir := gb.tempDir("tmp")
	gb.setenv("TMP", tmpdir)
	gb.runFail("test", "-race")
	gb.mustBeEmpty(tmpdir)
}
开发者ID:yonglehou,项目名称:gb,代码行数:33,代码来源:gb_test.go

示例14: getPlatformInfo

func getPlatformInfo() keybase1.PlatformInfo {
	return keybase1.PlatformInfo{
		Os:        runtime.GOOS,
		Arch:      runtime.GOARCH,
		GoVersion: runtime.Version(),
	}
}
开发者ID:jacobhaven,项目名称:client,代码行数:7,代码来源:config.go

示例15: init

func init() {
	if Version != "unknown-dev" {
		// If not a generic dev build, version string should come from git describe
		exp := regexp.MustCompile(`^v\d+\.\d+\.\d+(-[a-z0-9]+)*(\+\d+-g[0-9a-f]+)?(-dirty)?$`)
		if !exp.MatchString(Version) {
			l.Fatalf("Invalid version string %q;\n\tdoes not match regexp %v", Version, exp)
		}
	}

	// Check for a clean release build. A release is something like "v0.1.2",
	// with an optional suffix of letters and dot separated numbers like
	// "-beta3.47". If there's more stuff, like a plus sign and a commit hash
	// and so on, then it's not a release. If there's a dash anywhere in
	// there, it's some kind of beta or prerelease version.

	exp := regexp.MustCompile(`^v\d+\.\d+\.\d+(-[a-z]+[\d\.]+)?$`)
	IsRelease = exp.MatchString(Version)
	IsBeta = strings.Contains(Version, "-")

	stamp, _ := strconv.Atoi(BuildStamp)
	BuildDate = time.Unix(int64(stamp), 0)

	date := BuildDate.UTC().Format("2006-01-02 15:04:05 MST")
	LongVersion = fmt.Sprintf("syncthing %s (%s %s-%s %s) %[email protected]%s %s", Version, runtime.Version(), runtime.GOOS, runtime.GOARCH, BuildEnv, BuildUser, BuildHost, date)

	if os.Getenv("STTRACE") != "" {
		logFlags = log.Ltime | log.Ldate | log.Lmicroseconds | log.Lshortfile
	}
}
开发者ID:beride,项目名称:syncthing,代码行数:29,代码来源:main.go


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