mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-26 05:30:54 +03:00
parent
d89b9d891c
commit
2c77719cd6
4 changed files with 83 additions and 19 deletions
|
@ -32,6 +32,7 @@ import (
|
|||
"github.com/gohugoio/hugo/common/herrors"
|
||||
"github.com/gohugoio/hugo/common/hexec"
|
||||
"github.com/gohugoio/hugo/common/loggers"
|
||||
"github.com/gohugoio/hugo/config"
|
||||
|
||||
hglob "github.com/gohugoio/hugo/hugofs/glob"
|
||||
|
||||
|
@ -41,8 +42,6 @@ import (
|
|||
|
||||
"github.com/gohugoio/hugo/hugofs/files"
|
||||
|
||||
"github.com/gohugoio/hugo/config"
|
||||
|
||||
"golang.org/x/mod/module"
|
||||
|
||||
"github.com/gohugoio/hugo/common/hugio"
|
||||
|
@ -79,21 +78,6 @@ func NewClient(cfg ClientConfig) *Client {
|
|||
goModFilename = n
|
||||
}
|
||||
|
||||
var env []string
|
||||
mcfg := cfg.ModuleConfig
|
||||
|
||||
config.SetEnvVars(&env,
|
||||
"PWD", cfg.WorkingDir,
|
||||
"GO111MODULE", "on",
|
||||
"GOPROXY", mcfg.Proxy,
|
||||
"GOPRIVATE", mcfg.Private,
|
||||
"GONOPROXY", mcfg.NoProxy,
|
||||
"GOPATH", cfg.CacheDir,
|
||||
"GOWORK", mcfg.Workspace, // Requires Go 1.18, see https://tip.golang.org/doc/go1.18
|
||||
// GOCACHE was introduced in Go 1.15. This matches the location derived from GOPATH above.
|
||||
"GOCACHE", filepath.Join(cfg.CacheDir, "pkg", "mod"),
|
||||
)
|
||||
|
||||
logger := cfg.Logger
|
||||
if logger == nil {
|
||||
logger = loggers.NewDefault()
|
||||
|
@ -109,8 +93,8 @@ func NewClient(cfg ClientConfig) *Client {
|
|||
ccfg: cfg,
|
||||
logger: logger,
|
||||
noVendor: noVendor,
|
||||
moduleConfig: mcfg,
|
||||
environ: env,
|
||||
moduleConfig: cfg.ModuleConfig,
|
||||
environ: cfg.toEnv(),
|
||||
GoModulesFilename: goModFilename,
|
||||
}
|
||||
}
|
||||
|
@ -785,6 +769,37 @@ func (c ClientConfig) shouldIgnoreVendor(path string) bool {
|
|||
return c.IgnoreVendor != nil && c.IgnoreVendor.Match(path)
|
||||
}
|
||||
|
||||
func (cfg ClientConfig) toEnv() []string {
|
||||
mcfg := cfg.ModuleConfig
|
||||
var env []string
|
||||
keyVals := []string{
|
||||
"PWD", cfg.WorkingDir,
|
||||
"GO111MODULE", "on",
|
||||
"GOPATH", cfg.CacheDir,
|
||||
"GOWORK", mcfg.Workspace, // Requires Go 1.18, see https://tip.golang.org/doc/go1.18
|
||||
// GOCACHE was introduced in Go 1.15. This matches the location derived from GOPATH above.
|
||||
"GOCACHE", filepath.Join(cfg.CacheDir, "pkg", "mod"),
|
||||
}
|
||||
|
||||
if mcfg.Proxy != "" {
|
||||
keyVals = append(keyVals, "GOPROXY", mcfg.Proxy)
|
||||
}
|
||||
if mcfg.Private != "" {
|
||||
keyVals = append(keyVals, "GOPRIVATE", mcfg.Private)
|
||||
}
|
||||
if mcfg.NoProxy != "" {
|
||||
keyVals = append(keyVals, "GONOPROXY", mcfg.NoProxy)
|
||||
}
|
||||
if mcfg.Auth != "" {
|
||||
// GOAUTH was introduced in Go 1.24, see https://tip.golang.org/doc/go1.24.
|
||||
keyVals = append(keyVals, "GOAUTH", mcfg.Auth)
|
||||
}
|
||||
|
||||
config.SetEnvVars(&env, keyVals...)
|
||||
|
||||
return env
|
||||
}
|
||||
|
||||
type goBinaryStatus int
|
||||
|
||||
type goModule struct {
|
||||
|
|
|
@ -216,3 +216,42 @@ func TestGetModlineSplitter(t *testing.T) {
|
|||
gosumSplitter := getModlineSplitter(false)
|
||||
c.Assert(gosumSplitter("github.com/BurntSushi/toml v0.3.1"), qt.DeepEquals, []string{"github.com/BurntSushi/toml", "v0.3.1"})
|
||||
}
|
||||
|
||||
func TestClientConfigToEnv(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
ccfg := ClientConfig{
|
||||
WorkingDir: "/mywork",
|
||||
CacheDir: "/mycache",
|
||||
}
|
||||
|
||||
env := ccfg.toEnv()
|
||||
|
||||
c.Assert(env, qt.DeepEquals, []string{"PWD=/mywork", "GO111MODULE=on", "GOPATH=/mycache", "GOWORK=", filepath.FromSlash("GOCACHE=/mycache/pkg/mod")})
|
||||
|
||||
ccfg = ClientConfig{
|
||||
WorkingDir: "/mywork",
|
||||
CacheDir: "/mycache",
|
||||
ModuleConfig: Config{
|
||||
Proxy: "https://proxy.example.org",
|
||||
Private: "myprivate",
|
||||
NoProxy: "mynoproxy",
|
||||
Workspace: "myworkspace",
|
||||
Auth: "myauth",
|
||||
},
|
||||
}
|
||||
|
||||
env = ccfg.toEnv()
|
||||
|
||||
c.Assert(env, qt.DeepEquals, []string{
|
||||
"PWD=/mywork",
|
||||
"GO111MODULE=on",
|
||||
"GOPATH=/mycache",
|
||||
"GOWORK=myworkspace",
|
||||
filepath.FromSlash("GOCACHE=/mycache/pkg/mod"),
|
||||
"GOPROXY=https://proxy.example.org",
|
||||
"GOPRIVATE=myprivate",
|
||||
"GONOPROXY=mynoproxy",
|
||||
"GOAUTH=myauth",
|
||||
})
|
||||
}
|
||||
|
|
|
@ -295,6 +295,12 @@ type Config struct {
|
|||
// Configures GOPRIVATE when running the Go command for module operations.
|
||||
Private string
|
||||
|
||||
// Configures GOAUTH when running the Go command for module operations.
|
||||
// This is a semicolon-separated list of authentication commands for go-import and HTTPS module mirror interactions.
|
||||
// This is useful for private repositories.
|
||||
// See `go help goauth` for more information.
|
||||
Auth string
|
||||
|
||||
// Defaults to "off".
|
||||
// Set to a work file, e.g. hugo.work, to enable Go "Workspace" mode.
|
||||
// Can be relative to the working directory or absolute.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue