Some checks are pending
Docs Deploy / build_and_deploy (push) Waiting to run
Generate Docs / cli (push) Waiting to run
Generate Config Doc / cli (push) Waiting to run
Go formatting / go-formatting (push) Waiting to run
Check links / markdown-link-check (push) Waiting to run
Integration / pre-test (push) Waiting to run
Integration / test on (push) Blocked by required conditions
Integration / status (push) Blocked by required conditions
Lint / Lint Go code (push) Waiting to run
Test / test (ubuntu-latest) (push) Waiting to run
39 lines
1.5 KiB
Go
39 lines
1.5 KiB
Go
package module
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
|
|
"github.com/ignite/cli/v29/ignite/pkg/xstrings"
|
|
)
|
|
|
|
// ProtoPackageName creates a protocol buffer package name for an app module.
|
|
func ProtoPackageName(appModulePath, moduleName, version string) string {
|
|
pathArray := strings.Split(appModulePath, "/")
|
|
path := []string{pathArray[len(pathArray)-1], moduleName, version}
|
|
|
|
// Make sure that the first path element can be used as proto package name.
|
|
// This is required for app module names like "github.com/username/repo" where
|
|
// "username" might be not be compatible with proto buffer package names.
|
|
path[0] = xstrings.NoNumberPrefix(path[0])
|
|
|
|
return cleanProtoPackageName(strings.Join(path, "."))
|
|
}
|
|
|
|
// ProtoModulePackageName creates a protocol buffer module package name for an app module.
|
|
func ProtoModulePackageName(appModulePath, moduleName, version string) string {
|
|
pathArray := strings.Split(appModulePath, "/")
|
|
path := []string{pathArray[len(pathArray)-1], moduleName, "module", version}
|
|
|
|
// Make sure that the first path element can be used as proto package name.
|
|
// This is required for app module names like "github.com/username/repo" where
|
|
// "username" might be not be compatible with proto buffer package names.
|
|
path[0] = xstrings.NoNumberPrefix(path[0])
|
|
|
|
return cleanProtoPackageName(strings.Join(path, "."))
|
|
}
|
|
|
|
func cleanProtoPackageName(name string) string {
|
|
r := regexp.MustCompile("[^a-zA-Z0-9_.]+")
|
|
return strings.ToLower(r.ReplaceAllString(name, ""))
|
|
}
|