-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: allow "go run" to run command in current directory #5164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Initial attempt: https://golang.org/cl/8119049 |
I rolled back the CL. I'd like the semantics to be a bit different. See comment on https://golang.org/cl/8119049 Labels changed: added priority-later, removed priority-soon, go1.1. Status changed to Accepted. |
This issue was updated by revision e2b2e0d. R=golang-dev, dave CC=golang-dev https://golang.org/cl/9049043 |
I've submitted a CL for this issue: https://golang.org/cl/73350043 My CL is based off the conversation in the previous CL: https://golang.org/cl/8119049 |
FYI, the current CL under review is https://golang.org/cl/50970043/ |
CL https://golang.org/cl/50970043 references this issue. |
Move route registration to the `init()` function of `routes.go` (still part of the main package). Also, create a new `handler` package which will contain functions implementing `http.HandlerFunc` that `routes.go` will refer to when registering routes. Note that splitting the main package over two files (`main.go` and `routes.go`) means that `go run main.go` no longer runs the application correctly as it ignores `routes.go` entirely. Instead, we have to run `go run main.go routes.go` or `go build && ./timeoff`. See this issue for more details: golang/go#5164 Keep the route registration for `/debug/vars` (as provided by the `expvar` package) in `main.go` as it's not part of the main application functionality. One thing I still need to work out is how to expose `l`, i.e. `*logrus.Logger`, to the handler functions now that they're part of the `handler` package instead of `main`.
The HTTP server port is now defined using the `TIMEOFF_ADDR` environment variable. Also, run `go build` rather than `go run` to ensure that both `main.go` and `routes.go` are taken into account by the compiler; see: golang/go#5164
@rsc This is simple and Forgotten |
Forgotten, maybe, but not simple. |
I reread the discussion on https://golang.org/cl/50970043/, and I still don't see a way to integrate this. Obviously the command-line 'go run' could run the program in the current directory, but then 'go run arg' and 'go run arg.go' behave completely differently. I think this is probably OK to leave as is. For single-file programs people know about 'go run foo.go', and for larger programs 'go build && ./myprog' seems to be working fine. |
The text was updated successfully, but these errors were encountered: