Files
Gumble-Backend/scripts/internal/util/get_module_name.go
Zane Walker 7e940c83a7
Some checks failed
Build & Test / build-test (push) Has been cancelled
Build & Test / swagger-codegen-cli (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
(Feat): Initial Commit
2026-07-03 19:41:31 +05:30

29 lines
580 B
Go

//go:build scripts
// nolint:revive
package util
import (
"fmt"
"log"
"os"
"golang.org/x/mod/modfile"
)
// GetModuleName returns the current go module's name as defined in the go.mod file.
// https://stackoverflow.com/questions/53183356/api-to-get-the-module-name
// https://github.com/rogpeppe/go-internal
func GetModuleName(absolutePathToGoMod string) (string, error) {
dat, err := os.ReadFile(absolutePathToGoMod)
if err != nil {
log.Fatal(err)
return "", fmt.Errorf("failed to read go.mod file: %w", err)
}
mod := modfile.ModulePath(dat)
return mod, nil
}