Skip to content
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

fix: search go module when update and no -module provide #41

Merged
merged 1 commit into from
Apr 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/cloudwego/cwgo/config"
Expand Down Expand Up @@ -86,7 +87,6 @@ func Server(c *config.ServerArgument) error {
if module != c.GoMod {
return fmt.Errorf("module name given by the '-module' option ('%s') is not consist with the name defined in go.mod ('%s' from %s)", c.GoMod, module, path)
}
c.GoMod = module
}
err = app.GenerateLayout(args)
if err != nil {
Expand All @@ -99,6 +99,20 @@ func Server(c *config.ServerArgument) error {
if err != nil {
return cli.Exit(err, meta.LoadError)
}
module, path, ok := util.SearchGoMod(".", false)
if ok {
// go.mod exists
if c.GoMod != "" && module != c.GoMod {
return fmt.Errorf("module name given by the '-module' option ('%s') is not consist with the name defined in go.mod ('%s' from %s)", c.GoMod, module, path)
}
args.Gomod = module
} else {
workPath, err := filepath.Abs(".")
if err != nil {
FGYFFFF marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf(err.Error())
}
return fmt.Errorf("go.mod not found in %s", workPath)
}
logs.Debugf("Args: %#v\n", args)
defer func() {
manifest.Version = meta.GoVersion
Expand Down