Skip to content

proposal: cmd/go: conditional/optional dependency for go mod #32419

Closed
@dfang

Description

@dfang

What version of Go are you using (go version)?

$ go version
go version go1.12.1 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mj/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/mj/go"
GOPROXY="https://goproxy.io"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.1/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/xb/dsd0_2b92x7bsl92xlzj6fbm0000gn/T/go-build051189324=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

main.go

package main

import (
    "github.com/jinzhu/gorm"
  _ "github.com/jinzhu/gorm/dialects/sqlite"
)

func main() {
  db, err := gorm.Open("sqlite3", "test.db")
  if err != nil {
    panic("failed to connect database")
  }
  defer db.Close()
}
go mod init gorm-demo
go mod tidy
go mod graph

when you run go mod graph, you can see so many dependencies,

Output
github.com/jinzhu/gorm@v1.9.8 github.com/denisenkom/go-mssqldb@v0.0.0-20190423183735-731ef375ac02
github.com/jinzhu/gorm@v1.9.8 github.com/erikstmartin/go-testdb@v0.0.0-20160219214506-8d10e4a1bae5
github.com/jinzhu/gorm@v1.9.8 github.com/go-sql-driver/mysql@v1.4.1
github.com/jinzhu/gorm@v1.9.8 github.com/jinzhu/inflection@v0.0.0-20180308033659-04140366298a
github.com/jinzhu/gorm@v1.9.8 github.com/jinzhu/now@v1.0.0
github.com/jinzhu/gorm@v1.9.8 github.com/lib/pq@v1.1.0
github.com/jinzhu/gorm@v1.9.8 github.com/mattn/go-sqlite3@v1.10.0

just for mssql

github.com/denisenkom/go-mssqldb@v0.0.0-20190423183735-731ef375ac02 cloud.google.com/go@v0.37.4
github.com/denisenkom/go-mssqldb@v0.0.0-20190423183735-731ef375ac02 golang.org/x/crypto@v0.0.0-20190325154230-a5d413f7728c
github.com/denisenkom/go-mssqldb@v0.0.0-20190423183735-731ef375ac02 gopkg.in/check.v1@v1.0.0-20180628173108-788fd7840127
github.com/denisenkom/go-mssqldb@v0.0.0-20190423183735-731ef375ac02 gopkg.in/yaml.v2@v2.2.2

just for cloud.google.com/go

cloud.google.com/go@v0.37.4 github.com/golang/mock@v1.2.0
cloud.google.com/go@v0.37.4 honnef.co/go/tools@v0.0.0-20190106161140-3f1c8253044a
cloud.google.com/go@v0.37.4 google.golang.org/grpc@v1.19.0
cloud.google.com/go@v0.37.4 google.golang.org/genproto@v0.0.0-20190404172233-64821d5d2107
cloud.google.com/go@v0.37.4 google.golang.org/api@v0.3.1
cloud.google.com/go@v0.37.4 golang.org/x/tools@v0.0.0-20190312170243-e65039ee4138
cloud.google.com/go@v0.37.4 golang.org/x/time@v0.0.0-20181108054448-85acf8d2951c
cloud.google.com/go@v0.37.4 golang.org/x/text@v0.3.1-0.20180807135948-17ff2d5776d2
cloud.google.com/go@v0.37.4 golang.org/x/sync@v0.0.0-20190227155943-e225da77a7e6
cloud.google.com/go@v0.37.4 golang.org/x/oauth2@v0.0.0-20190226205417-e64efc72b421
cloud.google.com/go@v0.37.4 golang.org/x/lint@v0.0.0-20190301231843-5614ed5bae6f
cloud.google.com/go@v0.37.4 golang.org/x/exp@v0.0.0-20190121172915-509febef88a4
cloud.google.com/go@v0.37.4 go.opencensus.io@v0.20.1
cloud.google.com/go@v0.37.4 github.com/jstemmer/go-junit-report@v0.0.0-20190106144839-af01ea7f8024
cloud.google.com/go@v0.37.4 github.com/googleapis/gax-go/v2@v2.0.4
cloud.google.com/go@v0.37.4 github.com/google/pprof@v0.0.0-20181206194817-3ea8567a2e57
cloud.google.com/go@v0.37.4 github.com/google/martian@v2.1.0+incompatible
cloud.google.com/go@v0.37.4 github.com/google/go-cmp@v0.2.0
cloud.google.com/go@v0.37.4 github.com/google/btree@v0.0.0-20180813153112-4030bb1f1f0c
cloud.google.com/go@v0.37.4 github.com/golang/protobuf@v1.2.0

and many more ....

What did you expect to see?

what if i only use postgres db, please don't install mssql, sqlite dependencies for me.

i'm not sure this feature calls, maybe conditional dependencies ?

this pattern is common in some library that as a provider .....

What did you see instead?

a huge dependencies tree

Extra information (FYI)

i was a ruby on rails developer, as my experience, package management in node.js is sucking, big node_modules, installed failed, unmet dependencies ...

however in ruby world, package management (bundler) is nearly perfect, maybe go mod designer can learn something from that

https://bundler.io/man/gemfile.5.html#INSTALL_IF
https://bundler.io/v1.10/whats_new.html#install-if
https://bundler.io/guides/groups.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeProposalWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.modules

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions