Skip to content

proposal: x/vgo: allow aliases in go.mod #25518

Closed
@ufoscout

Description

@ufoscout

As of today, it is required to hardcode the full import path of dependencies in each go file, this proposal is to define an alias for the dependencies directly in the go.mod file and to use it throughout the code.

For example, this is a typical go.mod file:

module github.com/ufoscout/myModule
require (
	github.com/gin-gonic/gin v1.1.4
	github.com/ufoscout/go-up v0.5.0
)

Currently, the dependencies in a go file are imported this way:

import (
	ginweb "github.com/gin-gonic/gin" // using "ginweb" alias 
	"github.com/ufoscout/go-up"
	"github.com/ufoscout/myModule/subpackage" // import a subpackage
)

With this proposal, the aliases could be specified directly in the go.mod file. For example, introducing the aliases in the previous go.mod file:

module myModule github.com/ufoscout/myModule
require (
	ginweb github.com/gin-gonic/gin v1.1.4
	go-up github.com/ufoscout/go-up v0.5.0
)

the go code becomes:

import (
	"ginweb"
	"go-up"
	"myModule/subpackage" // import a subpackage
)

This permits to decouple the source code from the physical location of a dependency and to, for example, easily switch to a fork with a single change in the go.mod file.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions