Skip to content

proposal: Support simple code that contain 3rd package in go run rather than need a go.mod #61788

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

Closed
NewUserHa opened this issue Aug 6, 2023 · 1 comment

Comments

@NewUserHa
Copy link

NewUserHa commented Aug 6, 2023

eg: any simple code that's only few lines and a single file like:

# test.go
package main

import (
	"fmt"
	"net/http"

	"github.com/gin-gonic/gin"
)

func main() {
	fmt.Println("123")
	r := gin.Default()
	r.GET("/ping", func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{
			"message": "pong",
		})
	})
	r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}

go run test.go will get "test.go:7:2: no required module provides package github.com/gin-gonic/gin: go.mod file not found in current directory or any parent directory; see 'go help modules'", which is technically correct in the current latest version.

But what about adding the default package searching paths including the two folders more: the $goroot and the current folder, to make those single .go files with simple codes that have 1 or 2 3rd party packages could run without any problem? (it currently can run when only the std libs.)

The change affected things may be:
go run test.go # this one currently will only work if only using std libs.
go get "github.com/gin-gonic/gin" # this one currently will complain like "... outside go mod..." and refuse work.

@gopherbot gopherbot added this to the Proposal milestone Aug 6, 2023
@seankhliao
Copy link
Member

Duplicate of #36513

@seankhliao seankhliao marked this as a duplicate of #36513 Aug 6, 2023
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Aug 6, 2023
@golang golang locked and limited conversation to collaborators Aug 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants