Skip to content

runtime: GOROOT() docs are confusing #22302

@natefinch

Description

@natefinch

The docs say:

GOROOT returns the root of the Go tree. It uses the GOROOT environment variable, if set, or else the root used during the Go build.

Thus I expect this would print "Hi!":

package main

import (
    "fmt"
    "log"
    "os"
    "runtime"
)

func main() {
    err := os.Setenv("GOROOT", "Hi!")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(runtime.GOROOT())
}

However, this prints my real goroot, not "Hi!".

Either GOROOT() should actually check the environment variable when called, or the docs should be clarified to specify that it returns the GOROOT environment variable set at init() time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions