code
stringlengths
11
335k
docstring
stringlengths
20
11.8k
func_name
stringlengths
1
100
language
stringclasses
1 value
repo
stringclasses
245 values
path
stringlengths
4
144
url
stringlengths
43
214
license
stringclasses
4 values
func IsDebugMode(ctx context.Context) bool { return ctx.Value(debugMode{}) != nil }
IsDebugMode is used to decide whether to disable PostAction and PostShell
IsDebugMode
go
storyicon/powerproto
pkg/consts/context.go
https://github.com/storyicon/powerproto/blob/master/pkg/consts/context.go
Apache-2.0
func IsDisableAction(ctx context.Context) bool { return ctx.Value(disableAction{}) != nil }
IsDisableAction is used to decide whether to disable PostAction and PostShell
IsDisableAction
go
storyicon/powerproto
pkg/consts/context.go
https://github.com/storyicon/powerproto/blob/master/pkg/consts/context.go
Apache-2.0
func IsIgnoreDryRun(ctx context.Context) bool { return ctx.Value(ignoreDryRun{}) != nil }
IsIgnoreDryRun is used to determine whether it is currently in ignore DryRun mode
IsIgnoreDryRun
go
storyicon/powerproto
pkg/consts/context.go
https://github.com/storyicon/powerproto/blob/master/pkg/consts/context.go
Apache-2.0
func IsDryRun(ctx context.Context) bool { return ctx.Value(dryRun{}) != nil }
IsDryRun is used to determine whether it is currently in DryRun mode
IsDryRun
go
storyicon/powerproto
pkg/consts/context.go
https://github.com/storyicon/powerproto/blob/master/pkg/consts/context.go
Apache-2.0
func (p *ProtocRelease) GetIncludePath() string { return filepath.Join(p.workspace, "include") }
GetIncludePath is used to get the include path
GetIncludePath
go
storyicon/powerproto
pkg/component/pluginmanager/protoc.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/protoc.go
Apache-2.0
func (p *ProtocRelease) GetProtocPath() string { return filepath.Join(p.workspace, "bin", util.GetBinaryFileName("protoc")) }
GetProtocPath is used to get the protoc path
GetProtocPath
go
storyicon/powerproto
pkg/component/pluginmanager/protoc.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/protoc.go
Apache-2.0
func (p *ProtocRelease) Clear() error { return os.RemoveAll(p.workspace) }
Clear is used to clear the workspace
Clear
go
storyicon/powerproto
pkg/component/pluginmanager/protoc.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/protoc.go
Apache-2.0
func GetProtocRelease(ctx context.Context, version string) (*ProtocRelease, error) { if strings.HasPrefix(version, "v") { version = strings.TrimPrefix(version, "v") } workspace, err := os.MkdirTemp("", "") if err != nil { return nil, err } suffix, err := inferProtocReleaseSuffix() if err != nil { return nil, err } filename := fmt.Sprintf("protoc-%s-%s.zip", version, suffix) url := fmt.Sprintf("https://github.com/protocolbuffers/protobuf/"+ "releases/download/v%s/%s", version, filename) req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) if err != nil { return nil, &ErrHTTPDownload{ Url: url, Err: err, } } resp, err := http.DefaultClient.Do(req) if err != nil { return nil, &ErrHTTPDownload{ Url: url, Err: err, } } zipFilePath := filepath.Join(workspace, filename) if err := downloadFile(resp, zipFilePath); err != nil { return nil, &ErrHTTPDownload{ Url: url, Err: err, Code: resp.StatusCode, } } zip := archiver.NewZip() if err := zip.Unarchive(zipFilePath, workspace); err != nil { return nil, err } return &ProtocRelease{ workspace: workspace, }, nil }
GetProtocRelease is used to download protoc release
GetProtocRelease
go
storyicon/powerproto
pkg/component/pluginmanager/protoc.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/protoc.go
Apache-2.0
func IsProtocInstalled(ctx context.Context, storageDir string, version string) (bool, string, error) { local := PathForProtoc(storageDir, version) exists, err := util.IsFileExists(local) if err != nil { return false, "", err } return exists, local, nil }
IsProtocInstalled is used to check whether the protoc version is installed
IsProtocInstalled
go
storyicon/powerproto
pkg/component/pluginmanager/protoc.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/protoc.go
Apache-2.0
func NewConfig() *Config { return &Config{ StorageDir: consts.GetHomeDir(), } }
NewConfig is used to create config
NewConfig
go
storyicon/powerproto
pkg/component/pluginmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/manager.go
Apache-2.0
func NewPluginManager(cfg *Config, log logger.Logger) (PluginManager, error) { return NewBasicPluginManager(cfg.StorageDir, log) }
NewPluginManager is used to create PluginManager
NewPluginManager
go
storyicon/powerproto
pkg/component/pluginmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/manager.go
Apache-2.0
func NewBasicPluginManager(storageDir string, log logger.Logger) (*BasicPluginManager, error) { return &BasicPluginManager{ Logger: log.NewLogger("pluginmanager"), storageDir: storageDir, versions: map[string][]string{}, }, nil }
NewBasicPluginManager is used to create basic PluginManager
NewBasicPluginManager
go
storyicon/powerproto
pkg/component/pluginmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/manager.go
Apache-2.0
func (b *BasicPluginManager) GetPluginLatestVersion(ctx context.Context, path string) (string, error) { ctx, cancel := consts.GetContextWithPerCommandTimeout(ctx) defer cancel() versions, err := b.ListPluginVersions(ctx, path) if err != nil { return "", err } if len(versions) == 0 { return "", errors.New("no version list") } return versions[len(versions)-1], nil }
GetPluginLatestVersion is used to get the latest version of plugin
GetPluginLatestVersion
go
storyicon/powerproto
pkg/component/pluginmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/manager.go
Apache-2.0
func (b *BasicPluginManager) ListPluginVersions(ctx context.Context, path string) ([]string, error) { ctx, cancel := consts.GetContextWithPerCommandTimeout(ctx) defer cancel() b.versionsLock.RLock() versions, ok := b.versions[path] b.versionsLock.RUnlock() if ok { return versions, nil } versions, err := ListsGoPackageVersionsAmbiguously(ctx, b.Logger, path) if err != nil { return nil, err } b.versionsLock.Lock() b.versions[path] = versions b.versionsLock.Unlock() return versions, nil }
ListPluginVersions is used to list the versions of plugin
ListPluginVersions
go
storyicon/powerproto
pkg/component/pluginmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/manager.go
Apache-2.0
func (b *BasicPluginManager) IsPluginInstalled(ctx context.Context, path string, version string) (bool, string, error) { return IsPluginInstalled(ctx, b.storageDir, path, version) }
IsPluginInstalled is used to check whether the plugin is installed
IsPluginInstalled
go
storyicon/powerproto
pkg/component/pluginmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/manager.go
Apache-2.0
func (b *BasicPluginManager) GetPathForPlugin(ctx context.Context, path string, version string) (local string, err error) { return PathForPlugin(b.storageDir, path, version) }
GetPathForPlugin is used to get path for plugin executable file
GetPathForPlugin
go
storyicon/powerproto
pkg/component/pluginmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/manager.go
Apache-2.0
func (b *BasicPluginManager) InstallPlugin(ctx context.Context, path string, version string) (local string, err error) { return InstallPluginUsingGo(ctx, b.Logger, b.storageDir, path, version) }
InstallPlugin is used to install plugin
InstallPlugin
go
storyicon/powerproto
pkg/component/pluginmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/manager.go
Apache-2.0
func (b *BasicPluginManager) GetGitRepoLatestVersion(ctx context.Context, url string) (string, error) { return GetGitLatestCommitId(ctx, b.Logger, url) }
GetGitRepoLatestVersion is used to get the latest version of google apis
GetGitRepoLatestVersion
go
storyicon/powerproto
pkg/component/pluginmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/manager.go
Apache-2.0
func (b *BasicPluginManager) InstallGitRepo(ctx context.Context, uri string, commitId string) (string, error) { ctx, cancel := consts.GetContextWithPerCommandTimeout(ctx) defer cancel() exists, local, err := b.IsGitRepoInstalled(ctx, uri, commitId) if err != nil { return "", err } if exists { return local, nil } release, err := GetGithubArchive(ctx, uri, commitId) if err != nil { return "", err } defer release.Clear() codePath, err := PathForGitReposCode(b.storageDir, uri, commitId) if err != nil { return "", err } if err := util.CopyDirectory(release.GetLocalDir(), codePath); err != nil { return "", err } return local, nil }
InstallGitRepo is used to install google apis
InstallGitRepo
go
storyicon/powerproto
pkg/component/pluginmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/manager.go
Apache-2.0
func (b *BasicPluginManager) IsGitRepoInstalled(ctx context.Context, uri string, commitId string) (bool, string, error) { codePath, err := PathForGitReposCode(b.storageDir, uri, commitId) if err != nil { return false, "", err } exists, err := util.IsDirExists(codePath) return exists, PathForGitRepos(b.storageDir, commitId), err }
IsGitRepoInstalled is used to check whether the protoc is installed
IsGitRepoInstalled
go
storyicon/powerproto
pkg/component/pluginmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/manager.go
Apache-2.0
func (b *BasicPluginManager) GitRepoPath(ctx context.Context, commitId string) (string, error) { return PathForGitRepos(b.storageDir, commitId), nil }
GitRepoPath returns the googleapis path
GitRepoPath
go
storyicon/powerproto
pkg/component/pluginmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/manager.go
Apache-2.0
func (b *BasicPluginManager) IsProtocInstalled(ctx context.Context, version string) (bool, string, error) { if strings.HasPrefix(version, "v") { version = strings.TrimPrefix(version, "v") } return IsProtocInstalled(ctx, b.storageDir, version) }
IsProtocInstalled is used to check whether the protoc is installed
IsProtocInstalled
go
storyicon/powerproto
pkg/component/pluginmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/manager.go
Apache-2.0
func (b *BasicPluginManager) GetProtocLatestVersion(ctx context.Context) (string, error) { ctx, cancel := consts.GetContextWithPerCommandTimeout(ctx) defer cancel() versions, err := b.ListProtocVersions(ctx) if err != nil { return "", err } if len(versions) == 0 { return "", errors.New("no version list") } regularVersions := make([]string, 0, len(versions)) for _, version := range versions { if util.IsRegularVersion(version) { regularVersions = append(regularVersions, version) } } return regularVersions[len(regularVersions)-1], nil }
GetProtocLatestVersion is used to get the latest version of protoc
GetProtocLatestVersion
go
storyicon/powerproto
pkg/component/pluginmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/manager.go
Apache-2.0
func (b *BasicPluginManager) ListProtocVersions(ctx context.Context) ([]string, error) { ctx, cancel := consts.GetContextWithPerCommandTimeout(ctx) defer cancel() b.versionsLock.RLock() versions, ok := b.versions["protoc"] b.versionsLock.RUnlock() if ok { return versions, nil } versions, err := ListGitTags(ctx, b.Logger, consts.ProtobufRepository) if err != nil { return nil, err } b.versionsLock.Lock() b.versions["protoc"] = versions b.versionsLock.Unlock() return versions, nil }
ListProtocVersions is used to list protoc version
ListProtocVersions
go
storyicon/powerproto
pkg/component/pluginmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/manager.go
Apache-2.0
func (b *BasicPluginManager) GetPathForProtoc(ctx context.Context, version string) (string, error) { return PathForProtoc(b.storageDir, version), nil }
GetPathForProtoc is used to get the path for protoc
GetPathForProtoc
go
storyicon/powerproto
pkg/component/pluginmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/manager.go
Apache-2.0
func (b *BasicPluginManager) InstallProtoc(ctx context.Context, version string) (string, error) { ctx, cancel := consts.GetContextWithPerCommandTimeout(ctx) defer cancel() local := PathForProtoc(b.storageDir, version) exists, err := util.IsFileExists(local) if err != nil { return "", err } if exists { return local, nil } release, err := GetProtocRelease(ctx, version) if err != nil { return "", err } defer release.Clear() // merge include files includeDir := PathForInclude(b.storageDir) if err := util.CopyDirectory(release.GetIncludePath(), includeDir); err != nil { return "", err } // download protoc file if err := util.CopyFile(release.GetProtocPath(), local); err != nil { return "", err } // * it is required on unix system if err := os.Chmod(local, fs.ModePerm); err != nil { return "", err } return local, nil }
InstallProtoc is used to install protoc of specified version
InstallProtoc
go
storyicon/powerproto
pkg/component/pluginmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/manager.go
Apache-2.0
func (b *BasicPluginManager) IncludePath(ctx context.Context) (string, error) { return PathForInclude(b.storageDir), nil }
IncludePath returns the default include path
IncludePath
go
storyicon/powerproto
pkg/component/pluginmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/manager.go
Apache-2.0
func IsPluginInstalled(ctx context.Context, storageDir string, path string, version string) (bool, string, error) { local, err := PathForPlugin(storageDir, path, version) if err != nil { return false, "", err } exists, err := util.IsFileExists(local) if err != nil { return false, "", err } if exists { return true, local, nil } return false, "", nil }
IsPluginInstalled is used to check whether a plugin is installed
IsPluginInstalled
go
storyicon/powerproto
pkg/component/pluginmanager/plugin.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/plugin.go
Apache-2.0
func InstallPluginUsingGo(ctx context.Context, log logger.Logger, storageDir string, path string, version string) (string, error) { exists, local, err := IsPluginInstalled(ctx, storageDir, path, version) if err != nil { return "", err } if exists { return local, nil } local, err = PathForPlugin(storageDir, path, version) if err != nil { return "", err } dir := filepath.Dir(local) uri := util.JoinGoPackageVersion(path, version) _, err2 := command.Execute(ctx, log, "", "go", []string{ "install", uri, }, []string{"GOBIN=" + dir, "GO111MODULE=on"}) if err2 != nil { return "", &ErrGoInstall{ ErrCommandExec: err2.(*command.ErrCommandExec), } } return local, nil }
InstallPluginUsingGo is used to install plugin using golang
InstallPluginUsingGo
go
storyicon/powerproto
pkg/component/pluginmanager/plugin.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/plugin.go
Apache-2.0
func ListGoPackageVersions(ctx context.Context, log logger.Logger, path string) ([]string, error) { // query from latest version // If latest is not specified here, the queried version // may be restricted to the current project go.mod/go.sum pkg := util.JoinGoPackageVersion(path, "latest") data, err := command.Execute(ctx, log, "", "go", []string{ "list", "-m", "-json", "-versions", pkg, }, []string{ "GO111MODULE=on", }) if err != nil { return nil, &ErrGoList{ ErrCommandExec: err.(*command.ErrCommandExec), } } var module Module if err := jsoniter.Unmarshal(data, &module); err != nil { return nil, err } if len(module.Versions) != 0 { return module.Versions, nil } return []string{module.Version}, nil }
ListGoPackageVersions is list go package versions
ListGoPackageVersions
go
storyicon/powerproto
pkg/component/pluginmanager/plugin.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/plugin.go
Apache-2.0
func ListsGoPackageVersionsAmbiguously(ctx context.Context, log logger.Logger, pkg string) ([]string, error) { type Result struct { err error pkg string versions []string } items := strings.Split(pkg, "/") dataMap := make([]*Result, len(items)) notify := make(chan struct{}, 1) maxIndex := len(items) - 1 for i := maxIndex; i >= 1; i-- { go func(i int) { pkg := strings.Join(items[0:i+1], "/") versions, err := ListGoPackageVersions(context.TODO(), log, pkg) dataMap[maxIndex-i] = &Result{ pkg: pkg, versions: versions, err: err, } notify <- struct{}{} }(i) } OutLoop: for { select { case <-notify: var errs error for _, data := range dataMap { if data == nil { continue OutLoop } if data.err != nil { errs = multierror.Append(errs, data.err) } if data.versions != nil { return data.versions, nil } } return nil, errs case <-ctx.Done(): return nil, ctx.Err() } } }
ListsGoPackageVersionsAmbiguously is used to list go package versions ambiguously
ListsGoPackageVersionsAmbiguously
go
storyicon/powerproto
pkg/component/pluginmanager/plugin.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/plugin.go
Apache-2.0
func PathForInclude(storageDir string) string { return filepath.Join(storageDir, "include") }
PathForInclude is used to get the local directory of include files
PathForInclude
go
storyicon/powerproto
pkg/component/pluginmanager/paths.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/paths.go
Apache-2.0
func PathForProtoc(storageDir string, version string) string { if strings.HasPrefix(version, "v") { version = strings.TrimPrefix(version, "v") } return filepath.Join(storageDir, "protoc", version, util.GetBinaryFileName("protoc")) }
PathForProtoc is used to get the local binary location where the specified version protoc should be stored
PathForProtoc
go
storyicon/powerproto
pkg/component/pluginmanager/paths.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/paths.go
Apache-2.0
func GetPluginPath(path string, version string) (string, error) { enc, err := module.EscapePath(path) if err != nil { return "", err } encVer, err := module.EscapeVersion(version) if err != nil { return "", err } return filepath.Join(enc + "@" + encVer), nil }
GetPluginPath is used to get the plugin path
GetPluginPath
go
storyicon/powerproto
pkg/component/pluginmanager/paths.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/paths.go
Apache-2.0
func PathForGitReposCode(storageDir string, uri string, commitId string) (string, error) { parsed, err := url.Parse(uri) if err != nil { return "", err } dir := parsed.Host + parsed.Path return filepath.Join(PathForGitRepos(storageDir, commitId), dir), nil }
PathForGitReposCode returns the code path for git repos
PathForGitReposCode
go
storyicon/powerproto
pkg/component/pluginmanager/paths.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/paths.go
Apache-2.0
func PathForGitRepos(storageDir string, commitId string) string { return filepath.Join(storageDir, "gits", commitId) }
PathForGitRepos is used to get the git repo local path
PathForGitRepos
go
storyicon/powerproto
pkg/component/pluginmanager/paths.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/paths.go
Apache-2.0
func PathForPluginDir(storageDir string, path string, version string) (string, error) { pluginPath, err := GetPluginPath(path, version) if err != nil { return "", err } return filepath.Join(storageDir, "plugins", pluginPath), nil }
PathForPluginDir is used to get the local directory where the specified version plug-in should be stored
PathForPluginDir
go
storyicon/powerproto
pkg/component/pluginmanager/paths.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/paths.go
Apache-2.0
func PathForPlugin(storageDir string, path string, version string) (string, error) { name := GetGoPkgExecName(path) dir, err := PathForPluginDir(storageDir, path, version) if err != nil { return "", err } return filepath.Join(dir, util.GetBinaryFileName(name)), nil }
PathForPlugin is used to get the binary path of plugin Path: e.g "google.golang.org/protobuf/cmd/protoc-gen-go"
PathForPlugin
go
storyicon/powerproto
pkg/component/pluginmanager/paths.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/paths.go
Apache-2.0
func isVersionElement(s string) bool { if len(s) < 2 || s[0] != 'v' || s[1] == '0' || s[1] == '1' && len(s) == 2 { return false } for i := 1; i < len(s); i++ { if s[i] < '0' || '9' < s[i] { return false } } return true }
isVersionElement reports whether s is a well-formed path version element: v2, v3, v10, etc, but not v0, v05, v1. `src\cmd\go\internal\load\pkg.go:1209`
isVersionElement
go
storyicon/powerproto
pkg/component/pluginmanager/paths.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/paths.go
Apache-2.0
func GetGoPkgExecName(pkgPath string) string { _, elem := path.Split(pkgPath) if elem != pkgPath && isVersionElement(elem) { _, elem = path.Split(path.Dir(pkgPath)) } return elem }
GetGoPkgExecName is used to parse binary name from pkg uri `src\cmd\go\internal\load\pkg.go:1595`
GetGoPkgExecName
go
storyicon/powerproto
pkg/component/pluginmanager/paths.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/paths.go
Apache-2.0
func GetGitLatestCommitId(ctx context.Context, log logger.Logger, repo string) (string, error) { data, err := command.Execute(ctx, log, "", "git", []string{ "ls-remote", repo, "HEAD", }, nil) if err != nil { return "", &ErrGitList{ ErrCommandExec: err.(*command.ErrCommandExec), } } f := strings.Fields(string(data)) if len(f) != 2 { return "", &ErrGitList{ ErrCommandExec: err.(*command.ErrCommandExec), } } return f[0], nil }
GetGitLatestCommitId is used to get the latest commit id
GetGitLatestCommitId
go
storyicon/powerproto
pkg/component/pluginmanager/git.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/git.go
Apache-2.0
func ListGitTags(ctx context.Context, log logger.Logger, repo string) ([]string, error) { data, err := command.Execute(ctx, log, "", "git", []string{ "ls-remote", "--tags", "--refs", repo, }, nil) if err != nil { return nil, &ErrGitList{ ErrCommandExec: err.(*command.ErrCommandExec), } } var tags []string for _, line := range strings.Split(string(data), "\n") { f := strings.Fields(line) if len(f) != 2 { continue } if strings.HasPrefix(f[1], "refs/tags/") { tags = append(tags, strings.TrimPrefix(f[1], "refs/tags/")) } } malformed, wellFormed := util.SortSemanticVersion(tags) return append(malformed, wellFormed...), nil }
ListGitTags is used to list the git tags of specified repository
ListGitTags
go
storyicon/powerproto
pkg/component/pluginmanager/git.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/git.go
Apache-2.0
func GetGithubArchive(ctx context.Context, uri string, commitId string) (*GithubArchive, error) { filename := fmt.Sprintf("%s.zip", commitId) addr := fmt.Sprintf("%s/archive/%s", uri, filename) req, err := http.NewRequestWithContext(ctx, http.MethodGet, addr, nil) if err != nil { return nil, &ErrHTTPDownload{ Url: addr, Err: err, } } workspace, err := os.MkdirTemp("", "") if err != nil { return nil, err } resp, err := http.DefaultClient.Do(req) if err != nil { return nil, &ErrHTTPDownload{ Url: addr, Err: err, } } zipFilePath := filepath.Join(workspace, filename) if err := downloadFile(resp, zipFilePath); err != nil { return nil, &ErrHTTPDownload{ Url: addr, Err: err, Code: resp.StatusCode, } } zip := archiver.NewZip() if err := zip.Unarchive(zipFilePath, workspace); err != nil { return nil, err } return &GithubArchive{ uri: uri, commit: commitId, workspace: workspace, }, nil }
GetGithubArchive is used to download github archive
GetGithubArchive
go
storyicon/powerproto
pkg/component/pluginmanager/git.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/git.go
Apache-2.0
func (c *GithubArchive) GetLocalDir() string { dir := path.Base(c.uri) + "-" + c.commit return filepath.Join(c.workspace, dir) }
GetLocalDir is used to get local dir of archive
GetLocalDir
go
storyicon/powerproto
pkg/component/pluginmanager/git.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/git.go
Apache-2.0
func (c *GithubArchive) Clear() error { return os.RemoveAll(c.workspace) }
Clear is used to clear the workspace
Clear
go
storyicon/powerproto
pkg/component/pluginmanager/git.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/git.go
Apache-2.0
func (err *ErrHTTPDownload) Error() string { return fmt.Sprintf("failed to download %s, code: %d, err: %s", err.Url, err.Code, err.Err) }
Error implements the error interface
Error
go
storyicon/powerproto
pkg/component/pluginmanager/errors.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/pluginmanager/errors.go
Apache-2.0
func NewConfigManager(log logger.Logger) (ConfigManager, error) { return NewBasicConfigManager(log) }
NewConfigManager is used to create ConfigManager
NewConfigManager
go
storyicon/powerproto
pkg/component/configmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/configmanager/manager.go
Apache-2.0
func NewBasicConfigManager(log logger.Logger) (*BasicConfigManager, error) { return &BasicConfigManager{ Logger: log.NewLogger("configmanager"), tree: map[string][]configs.ConfigItem{}, }, nil }
NewBasicConfigManager is used to create a basic ConfigManager
NewBasicConfigManager
go
storyicon/powerproto
pkg/component/configmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/configmanager/manager.go
Apache-2.0
func (b *BasicConfigManager) GetConfig(ctx context.Context, protoFilePath string) (configs.ConfigItem, error) { possiblePath := configs.ListConfigPaths(filepath.Dir(protoFilePath)) for _, configFilePath := range possiblePath { items, err := b.loadConfig(configFilePath) if err != nil { return nil, err } dir := filepath.Dir(configFilePath) for _, config := range items { for _, scope := range config.Config().Scopes { scopePath := filepath.Join(dir, scope) if strings.Contains(protoFilePath, scopePath) { return config, nil } } } } return nil, errors.Errorf("unable to find config: %s", protoFilePath) }
GetConfig is used to get config of specified proto file path
GetConfig
go
storyicon/powerproto
pkg/component/configmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/configmanager/manager.go
Apache-2.0
func NewActionManager(log logger.Logger) (ActionManager, error) { return NewBasicActionManager(log) }
NewActionManager is used to create action manager
NewActionManager
go
storyicon/powerproto
pkg/component/actionmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/actionmanager/manager.go
Apache-2.0
func NewBasicActionManager(log logger.Logger) (*BasicActionManager, error) { return &BasicActionManager{ Logger: log.NewLogger("actionmanager"), actions: map[string]actions.ActionFunc{ "move": actions.ActionMove, "replace": actions.ActionReplace, "remove": actions.ActionRemove, "copy": actions.ActionCopy, }, }, nil }
NewBasicActionManager is used to create a BasicActionManager
NewBasicActionManager
go
storyicon/powerproto
pkg/component/actionmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/actionmanager/manager.go
Apache-2.0
func (m *BasicActionManager) ExecutePostShell(ctx context.Context, config configs.ConfigItem) error { script := config.Config().PostShell if script == "" { return nil } dir := filepath.Dir(config.Path()) _, err := command.Execute(ctx, m.Logger, dir, "/bin/sh", []string{ "-c", script, }, nil) if err != nil { return &ErrPostShell{ Path: config.Path(), ErrCommandExec: err.(*command.ErrCommandExec), } } return nil }
ExecutePostShell is used to execute post shell in config item
ExecutePostShell
go
storyicon/powerproto
pkg/component/actionmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/actionmanager/manager.go
Apache-2.0
func (m *BasicActionManager) ExecutePostAction(ctx context.Context, config configs.ConfigItem) error { for _, action := range config.Config().PostActions { actionFunc, ok := m.actions[action.Name] if !ok { return fmt.Errorf("unknown action: %s", action.Name) } if err := actionFunc(ctx, m.Logger, action.Args, &actions.CommonOptions{ ConfigFilePath: config.Path(), }); err != nil { return &ErrPostAction{ Path: config.Path(), Name: action.Name, Arguments: action.Args, Err: err, } } } return nil }
ExecutePostAction is used to execute post action in config item
ExecutePostAction
go
storyicon/powerproto
pkg/component/actionmanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/actionmanager/manager.go
Apache-2.0
func (err *ErrPostAction) Error() string { return fmt.Sprintf("failed to execute action: %s, path: %s, arguments: %s, err: %s", err.Name, err.Path, err.Arguments, err.Err, ) }
Error implements the standard error interface
Error
go
storyicon/powerproto
pkg/component/actionmanager/errors.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/actionmanager/errors.go
Apache-2.0
func ActionReplace(ctx context.Context, log logger.Logger, args []string, options *CommonOptions) error { if len(args) != 3 { return errors.Errorf("expected length of args is 3, but received %d", len(args)) } var ( pattern = args[0] path = filepath.Dir(options.ConfigFilePath) from = args[1] to = args[2] ) if pattern == "" || from == "" { return errors.Errorf("pattern and from arguments in action replace can not be empty") } if filepath.IsAbs(pattern) { return errors.Errorf("absolute path %s is not allowed in action replace", pattern) } pattern = filepath.Join(path, pattern) return filepath.Walk(path, func(path string, info fs.FileInfo, err error) error { if info.IsDir() { return nil } matched, err := util.MatchPath(pattern, path) if err != nil { panic(err) } if matched { if consts.IsDryRun(ctx) { log.LogInfo(map[string]interface{}{ "action": "replace", "file": path, "from": from, "to": to, }, consts.TextDryRun) return nil } log.LogDebug(map[string]interface{}{ "action": "replace", "file": path, "from": from, "to": to, }, consts.TextExecuteAction) data, err := ioutil.ReadFile(path) if err != nil { return err } data = bytes.ReplaceAll(data, []byte(from), []byte(to)) return ioutil.WriteFile(path, data, fs.ModePerm) } return nil }) }
ActionReplace is used to replace text in bulk Its args prototype is: args: (pattern string, from string, to string) pattern is used to match files
ActionReplace
go
storyicon/powerproto
pkg/component/actionmanager/actions/replace.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/actionmanager/actions/replace.go
Apache-2.0
func ActionCopy(ctx context.Context, log logger.Logger, args []string, options *CommonOptions) error { if len(args) != 2 || util.ContainsEmpty(args...) { return errors.Errorf("expected length of args is 3, but received %d", len(args)) } var ( source = args[0] destination = args[1] path = filepath.Dir(options.ConfigFilePath) absSource = filepath.Join(path, source) absDestination = filepath.Join(path, destination) ) if filepath.IsAbs(source) { return errors.Errorf("absolute source %s is not allowed in action move", source) } if filepath.IsAbs(destination) { return errors.Errorf("absolute destination %s is not allowed in action move", destination) } if consts.IsDryRun(ctx) { log.LogInfo(map[string]interface{}{ "action": "copy", "from": absSource, "to": absDestination, }, consts.TextDryRun) return nil } log.LogDebug(map[string]interface{}{ "action": "copy", "from": absSource, "to": absDestination, }, consts.TextExecuteAction) if err := util.CopyDirectory(absSource, absDestination); err != nil { return err } return nil }
ActionCopy is used to copy directory or file from src to dest Its args prototype is: args: (src string, dest string)
ActionCopy
go
storyicon/powerproto
pkg/component/actionmanager/actions/copy.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/actionmanager/actions/copy.go
Apache-2.0
func ActionRemove(ctx context.Context, log logger.Logger, args []string, options *CommonOptions) error { for _, arg := range args { if filepath.IsAbs(arg) { return errors.Errorf("absolute path %s is not allowed in action remove", arg) } path := filepath.Join(filepath.Dir(options.ConfigFilePath), arg) if consts.IsDryRun(ctx) { log.LogInfo(map[string]interface{}{ "action": "remove", "target": path, }, consts.TextDryRun) return nil } log.LogDebug(map[string]interface{}{ "action": "remove", "target": path, }, consts.TextExecuteAction) if err := os.RemoveAll(path); err != nil { return err } } return nil }
ActionRemove is used to delete directories or files Its args prototype is: args: (path ...string)
ActionRemove
go
storyicon/powerproto
pkg/component/actionmanager/actions/remove.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/actionmanager/actions/remove.go
Apache-2.0
func ActionMove(ctx context.Context, log logger.Logger, args []string, options *CommonOptions) error { if len(args) != 2 || util.ContainsEmpty(args...) { return errors.Errorf("expected length of args is 3, but received %d", len(args)) } var ( source = args[0] destination = args[1] path = filepath.Dir(options.ConfigFilePath) absSource = filepath.Join(path, source) absDestination = filepath.Join(path, destination) ) if filepath.IsAbs(source) { return errors.Errorf("absolute source %s is not allowed in action move", source) } if filepath.IsAbs(destination) { return errors.Errorf("absolute destination %s is not allowed in action move", destination) } if consts.IsDryRun(ctx) { log.LogInfo(map[string]interface{}{ "action": "move", "from": absSource, "to": absDestination, }, consts.TextDryRun) return nil } log.LogDebug(map[string]interface{}{ "action": "move", "from": absSource, "to": absDestination, }, consts.TextExecuteAction) if err := util.CopyDirectory(absSource, absDestination); err != nil { return err } if err := os.RemoveAll(absSource); err != nil { return err } return nil }
ActionMove is used to move directory or file from src to dest Its args prototype is: args: (src string, dest string)
ActionMove
go
storyicon/powerproto
pkg/component/actionmanager/actions/move.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/actionmanager/actions/move.go
Apache-2.0
func NewCompilerManager(ctx context.Context, log logger.Logger, configManager configmanager.ConfigManager, pluginManager pluginmanager.PluginManager, ) (CompilerManager, error) { return NewBasicCompilerManager(ctx, log, configManager, pluginManager) }
NewCompilerManager is used to create CompilerManager
NewCompilerManager
go
storyicon/powerproto
pkg/component/compilermanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/compilermanager/manager.go
Apache-2.0
func NewBasicCompilerManager(ctx context.Context, log logger.Logger, configManager configmanager.ConfigManager, pluginManager pluginmanager.PluginManager, ) (*BasicCompilerManager, error) { return &BasicCompilerManager{ Logger: log.NewLogger("compilermanager"), configManager: configManager, pluginManager: pluginManager, tree: map[string]Compiler{}, }, nil }
NewBasicCompilerManager is used to create basic CompilerManager
NewBasicCompilerManager
go
storyicon/powerproto
pkg/component/compilermanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/compilermanager/manager.go
Apache-2.0
func (b *BasicCompilerManager) GetCompiler(ctx context.Context, protoFilePath string) (Compiler, error) { config, err := b.configManager.GetConfig(ctx, protoFilePath) if err != nil { return nil, err } b.treeLock.Lock() defer b.treeLock.Unlock() c, ok := b.tree[config.Path()] if ok { return c, nil } compiler, err := NewCompiler(ctx, b.Logger, b.pluginManager, config) if err != nil { return nil, err } b.tree[config.ID()] = compiler return compiler, nil }
GetCompiler is used to get compiler of specified proto file path
GetCompiler
go
storyicon/powerproto
pkg/component/compilermanager/manager.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/compilermanager/manager.go
Apache-2.0
func NewCompiler( ctx context.Context, log logger.Logger, pluginManager pluginmanager.PluginManager, config configs.ConfigItem, ) (Compiler, error) { return NewBasicCompiler(ctx, log, pluginManager, config) }
NewCompiler is used to create a compiler
NewCompiler
go
storyicon/powerproto
pkg/component/compilermanager/compiler.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/compilermanager/compiler.go
Apache-2.0
func NewBasicCompiler( ctx context.Context, log logger.Logger, pluginManager pluginmanager.PluginManager, config configs.ConfigItem, ) (*BasicCompiler, error) { return &BasicCompiler{ Logger: log.NewLogger("compiler"), config: config, pluginManager: pluginManager, }, nil }
NewBasicCompiler is used to create a basic compiler
NewBasicCompiler
go
storyicon/powerproto
pkg/component/compilermanager/compiler.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/compilermanager/compiler.go
Apache-2.0
func (b *BasicCompiler) Compile(ctx context.Context, protoFilePath string) error { dir := b.calcDir() protocPath, err := b.calcProtocPath(ctx) if err != nil { return err } arguments, err := b.calcArguments(ctx, protoFilePath) if err != nil { return err } arguments = append(arguments, protoFilePath) _, err = command.Execute(ctx, b.Logger, dir, protocPath, arguments, nil) if err != nil { return &ErrCompile{ ErrCommandExec: err.(*command.ErrCommandExec), } } return nil }
Compile is used to compile proto file
Compile
go
storyicon/powerproto
pkg/component/compilermanager/compiler.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/compilermanager/compiler.go
Apache-2.0
func (b *BasicCompiler) GetConfig(ctx context.Context) configs.ConfigItem { return b.config }
GetConfig is used to return config that the compiler used
GetConfig
go
storyicon/powerproto
pkg/component/compilermanager/compiler.go
https://github.com/storyicon/powerproto/blob/master/pkg/component/compilermanager/compiler.go
Apache-2.0
func StepLookUpConfigs( ctx context.Context, targets []string, configManager configmanager.ConfigManager, ) ([]configs.ConfigItem, error) { progress := progressbar.GetProgressBar(ctx, len(targets)) progress.SetPrefix("Lookup configs of proto files") var configItems []configs.ConfigItem deduplicate := map[string]struct{}{} for _, target := range targets { cfg, err := configManager.GetConfig(ctx, target) if err != nil { return nil, err } if _, exists := deduplicate[cfg.ID()]; !exists { configItems = append(configItems, cfg) deduplicate[cfg.ID()] = struct{}{} } progress.SetSuffix("load %s", cfg.ID()) progress.Incr() } progress.SetSuffix("success!") progress.Wait() fmt.Printf("the following %d configurations will be used: \r\n", len(configItems)) for _, config := range configItems { fmt.Printf(" %s \r\n", config.Path()) } if len(configItems) == 0 { return nil, errors.New("no config file matched, please check the scope of config file " + "or use 'powerproto init' to create config file") } return configItems, nil }
StepLookUpConfigs is used to lookup config files according to target proto files
StepLookUpConfigs
go
storyicon/powerproto
pkg/bootstraps/build.go
https://github.com/storyicon/powerproto/blob/master/pkg/bootstraps/build.go
Apache-2.0
func StepInstallRepositories(ctx context.Context, pluginManager pluginmanager.PluginManager, configItems []configs.ConfigItem) error { deduplicate := map[string]struct{}{} for _, config := range configItems { for _, pkg := range config.Config().Repositories { deduplicate[pkg] = struct{}{} } } if len(deduplicate) == 0 { return nil } progress := progressbar.GetProgressBar(ctx, len(deduplicate)) progress.SetPrefix("Install repositories") repoMap := map[string]struct{}{} for pkg := range deduplicate { path, version, ok := util.SplitGoPackageVersion(pkg) if !ok { return errors.Errorf("invalid format: %s, should in path@version format", pkg) } if version == "latest" { progress.SetSuffix("query latest version of %s", path) latestVersion, err := pluginManager.GetGitRepoLatestVersion(ctx, path) if err != nil { return errors.Wrapf(err, "failed to query latest version of %s", path) } version = latestVersion pkg = util.JoinGoPackageVersion(path, version) } progress.SetSuffix("check cache of %s", pkg) exists, _, err := pluginManager.IsGitRepoInstalled(ctx, path, version) if err != nil { return err } if exists { progress.SetSuffix("the %s version of %s is already cached", version, path) } else { progress.SetSuffix("install %s version of %s", version, path) _, err = pluginManager.InstallGitRepo(ctx, path, version) if err != nil { return err } progress.SetSuffix("the %s version of %s is installed", version, path) } repoMap[pkg] = struct{}{} progress.Incr() } progress.SetSuffix("all repositories have been installed") progress.Wait() fmt.Println("the following versions of googleapis will be used:") for pkg := range repoMap { fmt.Printf(" %s\r\n", pkg) } return nil }
StepInstallRepositories is used to install repositories
StepInstallRepositories
go
storyicon/powerproto
pkg/bootstraps/build.go
https://github.com/storyicon/powerproto/blob/master/pkg/bootstraps/build.go
Apache-2.0
func StepInstallProtoc(ctx context.Context, pluginManager pluginmanager.PluginManager, configItems []configs.ConfigItem) error { deduplicate := map[string]struct{}{} for _, config := range configItems { version := config.Config().Protoc if version == "" { return errors.Errorf("protoc version is required: %s", config.Path()) } deduplicate[version] = struct{}{} } progress := progressbar.GetProgressBar(ctx, len(deduplicate)) progress.SetPrefix("Install protoc") versionsMap := map[string]struct{}{} for version := range deduplicate { if version == "latest" { progress.SetSuffix("query latest version of protoc") latestVersion, err := pluginManager.GetProtocLatestVersion(ctx) if err != nil { return errors.Wrap(err, "failed to list protoc versions") } version = latestVersion } progress.SetSuffix("check cache of protoc %s", version) exists, _, err := pluginManager.IsProtocInstalled(ctx, version) if err != nil { return err } if exists { progress.SetSuffix("the %s version of protoc is already cached", version) } else { progress.SetSuffix("install %s version of protoc", version) _, err = pluginManager.InstallProtoc(ctx, version) if err != nil { return err } progress.SetSuffix("the %s version of protoc is installed", version) } versionsMap[version] = struct{}{} progress.Incr() } progress.Wait() fmt.Println("the following versions of protoc will be used:", util.SetToSlice(versionsMap)) return nil }
StepInstallProtoc is used to install protoc
StepInstallProtoc
go
storyicon/powerproto
pkg/bootstraps/build.go
https://github.com/storyicon/powerproto/blob/master/pkg/bootstraps/build.go
Apache-2.0
func StepInstallPlugins(ctx context.Context, pluginManager pluginmanager.PluginManager, configItems []configs.ConfigItem, ) error { deduplicate := map[string]struct{}{} for _, config := range configItems { for _, pkg := range config.Config().Plugins { deduplicate[pkg] = struct{}{} } } progress := progressbar.GetProgressBar(ctx, len(deduplicate)) progress.SetPrefix("Install plugins") pluginsMap := map[string]struct{}{} for pkg := range deduplicate { path, version, ok := util.SplitGoPackageVersion(pkg) if !ok { return errors.Errorf("invalid format: %s, should in path@version format", pkg) } if version == "latest" { progress.SetSuffix("query latest version of %s", path) data, err := pluginManager.GetPluginLatestVersion(ctx, path) if err != nil { return err } version = data pkg = util.JoinGoPackageVersion(path, version) } progress.SetSuffix("check cache of %s", pkg) exists, _, err := pluginManager.IsPluginInstalled(ctx, path, version) if err != nil { return err } if exists { progress.SetSuffix("%s is cached", pkg) } else { progress.SetSuffix("installing %s", pkg) _, err := pluginManager.InstallPlugin(ctx, path, version) if err != nil { panic(err) } progress.SetSuffix("%s installed", pkg) } pluginsMap[pkg] = struct{}{} progress.Incr() } progress.SetSuffix("all plugins have been installed") progress.Wait() fmt.Println("the following plugins will be used:") for pkg := range pluginsMap { fmt.Printf(" %s\r\n", pkg) } return nil }
StepInstallPlugins is used to install plugins
StepInstallPlugins
go
storyicon/powerproto
pkg/bootstraps/build.go
https://github.com/storyicon/powerproto/blob/master/pkg/bootstraps/build.go
Apache-2.0
func StepCompile(ctx context.Context, compilerManager compilermanager.CompilerManager, targets []string, ) error { progress := progressbar.GetProgressBar(ctx, len(targets)) progress.SetPrefix("Compile Proto Files") c := concurrent.NewErrGroup(ctx, 10) for _, target := range targets { func(target string) { c.Go(func(ctx context.Context) error { progress.SetSuffix(target) comp, err := compilerManager.GetCompiler(ctx, target) if err != nil { return err } if err := comp.Compile(ctx, target); err != nil { return err } progress.Incr() return nil }) }(target) } if err := c.Wait(); err != nil { return err } progress.Wait() return nil }
StepCompile is used to compile proto files
StepCompile
go
storyicon/powerproto
pkg/bootstraps/build.go
https://github.com/storyicon/powerproto/blob/master/pkg/bootstraps/build.go
Apache-2.0
func StepPostAction(ctx context.Context, actionsManager actionmanager.ActionManager, configItems []configs.ConfigItem) error { progress := progressbar.GetProgressBar(ctx, len(configItems)) progress.SetPrefix("PostAction") for _, cfg := range configItems { progress.SetSuffix(cfg.Path()) if err := actionsManager.ExecutePostAction(ctx, cfg); err != nil { return err } progress.Incr() } progress.Wait() return nil }
StepPostAction is used to execute post actions
StepPostAction
go
storyicon/powerproto
pkg/bootstraps/build.go
https://github.com/storyicon/powerproto/blob/master/pkg/bootstraps/build.go
Apache-2.0
func StepPostShell(ctx context.Context, actionsManager actionmanager.ActionManager, configItems []configs.ConfigItem) error { progress := progressbar.GetProgressBar(ctx, len(configItems)) progress.SetPrefix("PostShell") for _, cfg := range configItems { progress.SetSuffix(cfg.Path()) if err := actionsManager.ExecutePostShell(ctx, cfg); err != nil { return err } progress.Incr() } progress.Wait() return nil }
StepPostShell is used to execute post shell
StepPostShell
go
storyicon/powerproto
pkg/bootstraps/build.go
https://github.com/storyicon/powerproto/blob/master/pkg/bootstraps/build.go
Apache-2.0
func Compile(ctx context.Context, targets []string) error { log := logger.NewDefault("compile") log.SetLogLevel(logger.LevelInfo) if consts.IsDebugMode(ctx) { log.SetLogLevel(logger.LevelDebug) } configManager, err := configmanager.NewConfigManager(log) if err != nil { return err } pluginManager, err := pluginmanager.NewPluginManager(pluginmanager.NewConfig(), log) if err != nil { return err } compilerManager, err := compilermanager.NewCompilerManager(ctx, log, configManager, pluginManager) if err != nil { return err } actionManager, err := actionmanager.NewActionManager(log) if err != nil { return err } configItems, err := StepLookUpConfigs(ctx, targets, configManager) if err != nil { return err } if err := StepInstallProtoc(ctx, pluginManager, configItems); err != nil { return err } if err := StepInstallRepositories(ctx, pluginManager, configItems); err != nil { return err } if err := StepInstallPlugins(ctx, pluginManager, configItems); err != nil { return err } if err := StepCompile(ctx, compilerManager, targets); err != nil { return err } if !consts.IsDisableAction(ctx) { if err := StepPostAction(ctx, actionManager, configItems); err != nil { return err } if err := StepPostShell(ctx, actionManager, configItems); err != nil { return err } } else { displayWarn := false for _, configItem := range configItems { if len(configItem.Config().PostActions) > 0 || configItem.Config().PostShell != "" { displayWarn = true break } } if displayWarn { log.LogWarn(nil, "PostAction and PostShell is skipped. If you need to allow execution, please append '-p' to command flags to enable") } } log.LogInfo(nil, "Good job! you are ready to go :)") return nil }
Compile is used to compile proto files
Compile
go
storyicon/powerproto
pkg/bootstraps/build.go
https://github.com/storyicon/powerproto/blob/master/pkg/bootstraps/build.go
Apache-2.0
func StepTidyConfig(ctx context.Context, targets []string) error { log := logger.NewDefault("tidy") log.SetLogLevel(logger.LevelInfo) if consts.IsDebugMode(ctx) { log.SetLogLevel(logger.LevelDebug) } configManager, err := configmanager.NewConfigManager(log) if err != nil { return err } pluginManager, err := pluginmanager.NewPluginManager(pluginmanager.NewConfig(), log) if err != nil { return err } configPaths := map[string]struct{}{} for _, target := range targets { cfg, err := configManager.GetConfig(ctx, target) if err != nil { return err } configPaths[cfg.Path()] = struct{}{} } if len(configPaths) == 0 { return nil } progress := progressbar.GetProgressBar(ctx, len(configPaths)) progress.SetPrefix("tidy configs") for path := range configPaths { progress.SetSuffix(path) err := StepTidyConfigFile(ctx, pluginManager, progress, path) if err != nil { return err } progress.Incr() } progress.SetSuffix("success!") progress.Wait() return nil }
StepTidyConfig is used to tidy configs by proto file targets
StepTidyConfig
go
storyicon/powerproto
pkg/bootstraps/tidy.go
https://github.com/storyicon/powerproto/blob/master/pkg/bootstraps/tidy.go
Apache-2.0
func StepTidyConfigFile(ctx context.Context, pluginManager pluginmanager.PluginManager, progress progressbar.ProgressBar, configFilePath string, ) error { progress.SetSuffix("load config: %s", configFilePath) configItems, err := configs.LoadConfigs(configFilePath) if err != nil { return err } var cleanable bool for _, item := range configItems { if item.Protoc == "latest" { progress.SetSuffix("query latest version of protoc") version, err := pluginManager.GetProtocLatestVersion(ctx) if err != nil { return err } item.Protoc = version cleanable = true } for name, pkg := range item.Repositories { path, version, ok := util.SplitGoPackageVersion(pkg) if !ok { return errors.Errorf("invalid package format: %s, should be in path@version format", pkg) } if version == "latest" { progress.SetSuffix("query latest version of %s", path) version, err := pluginManager.GetGitRepoLatestVersion(ctx, path) if err != nil { return err } item.Repositories[name] = util.JoinGoPackageVersion(path, version) cleanable = true } } for name, pkg := range item.Plugins { path, version, ok := util.SplitGoPackageVersion(pkg) if !ok { return errors.Errorf("invalid package format: %s, should be in path@version format", pkg) } if version == "latest" { progress.SetSuffix("query latest version of %s", path) version, err := pluginManager.GetPluginLatestVersion(ctx, path) if err != nil { return err } item.Plugins[name] = util.JoinGoPackageVersion(path, version) cleanable = true } } } if cleanable { progress.SetSuffix("save %s", configFilePath) if err := configs.SaveConfigs(configFilePath, configItems...); err != nil { return err } } progress.SetSuffix("config file tidied: %s", configFilePath) return nil }
StepTidyConfigFile is used clean config It will amend the 'latest' version to the latest version number in 'vx.y.z' format
StepTidyConfigFile
go
storyicon/powerproto
pkg/bootstraps/tidy.go
https://github.com/storyicon/powerproto/blob/master/pkg/bootstraps/tidy.go
Apache-2.0
func GetRootCommand() *cobra.Command { return &cobra.Command{ Use: "[powerproto]", Version: fmt.Sprintf("%s, branch: %s, revision: %s, buildDate: %s", Version, Branch, Revision, BuildDate), Short: "powerproto is used to build proto files and version control of protoc and related plug-ins", Run: func(cmd *cobra.Command, args []string) { _ = cmd.Help() }, } }
GetRootCommand is used to get root command
GetRootCommand
go
storyicon/powerproto
cmd/powerproto/main.go
https://github.com/storyicon/powerproto/blob/master/cmd/powerproto/main.go
Apache-2.0
func GetUserPreference() (*UserPreference, error) { var preference UserPreference err := survey.Ask([]*survey.Question{ { Name: "plugins", Prompt: &survey.MultiSelect{ Message: "select plugins to use. Later, you can also manually add in the configuration file", Options: GetWellKnownPluginsOptionValues(), }, }, { Name: "repositories", Prompt: &survey.MultiSelect{ Message: "select repositories to use. Later, you can also manually add in the configuration file", Options: GetWellKnownRepositoriesOptionValues(), }, }, }, &preference) if len(preference.Plugins) == 0 { preference.Plugins = []string{ GetPluginProtocGenGo().GetOptionsValue(), GetPluginProtocGenGoGRPC().GetOptionsValue(), } } if len(preference.Repositories) == 0 { preference.Repositories = []string{ GetRepositoryGoogleAPIs().GetOptionsValue(), } } return &preference, err }
GetUserPreference is used to get user preference
GetUserPreference
go
storyicon/powerproto
cmd/powerproto/subcommands/init/command.go
https://github.com/storyicon/powerproto/blob/master/cmd/powerproto/subcommands/init/command.go
Apache-2.0
func GetDefaultConfig() *configs.Config { return &configs.Config{ Scopes: []string{ "./", }, Protoc: "latest", Plugins: map[string]string{}, Repositories: map[string]string{}, Options: []string{}, ImportPaths: []string{ ".", "$GOPATH", consts.KeyPowerProtoInclude, consts.KeySourceRelative, }, } }
GetDefaultConfig is used to get default config
GetDefaultConfig
go
storyicon/powerproto
cmd/powerproto/subcommands/init/command.go
https://github.com/storyicon/powerproto/blob/master/cmd/powerproto/subcommands/init/command.go
Apache-2.0
func CommandInit(log logger.Logger) *cobra.Command { return &cobra.Command{ Use: "init", Short: "init a config file in current directory", Run: func(cmd *cobra.Command, args []string) { exists, err := util.IsFileExists(consts.ConfigFileName) if err != nil { log.LogError(nil, err.Error()) return } if exists { log.LogInfo(nil, "config file already exists in this directory") return } preference, err := GetUserPreference() if err != nil { log.LogError(nil, err.Error()) return } config := GetDefaultConfig() for _, val := range preference.Plugins { if plugin, ok := GetPluginFromOptionsValue(val); ok { config.Plugins[plugin.Name] = plugin.Pkg config.Options = append(config.Options, plugin.Options...) } } for _, val := range preference.Repositories { if repo, ok := GetRepositoryFromOptionsValue(val); ok { config.Repositories[repo.Name] = repo.Pkg config.ImportPaths = append(config.ImportPaths, repo.ImportPaths...) } } if err := configs.SaveConfigs(consts.ConfigFileName, config); err != nil { log.LogFatal(nil, "failed to save config: %s", err) } log.LogInfo(nil, "succeed! You can use `powerproto tidy` to tidy this config file") }, } }
CommandInit is used to initialize the configuration file in the current directory
CommandInit
go
storyicon/powerproto
cmd/powerproto/subcommands/init/command.go
https://github.com/storyicon/powerproto/blob/master/cmd/powerproto/subcommands/init/command.go
Apache-2.0
func (repo *Repository) GetOptionsValue() string { if repo.OptionsValue != "" { return repo.OptionsValue } return fmt.Sprintf("%s: %s", strings.ToLower(repo.Name), repo.Pkg) }
OptionsValue is used to return the options value
GetOptionsValue
go
storyicon/powerproto
cmd/powerproto/subcommands/init/repositories.go
https://github.com/storyicon/powerproto/blob/master/cmd/powerproto/subcommands/init/repositories.go
Apache-2.0
func GetWellKnownRepositories() []*Repository { return []*Repository{ GetRepositoryGoogleAPIs(), GetRepositoryGoGoProtobuf(), } }
GetWellKnownRepositories is used to get well known plugins
GetWellKnownRepositories
go
storyicon/powerproto
cmd/powerproto/subcommands/init/repositories.go
https://github.com/storyicon/powerproto/blob/master/cmd/powerproto/subcommands/init/repositories.go
Apache-2.0
func GetRepositoryGoGoProtobuf() *Repository { return &Repository{ Name: "GOGO_PROTOBUF", Pkg: "https://github.com/gogo/protobuf@226206f39bd7276e88ec684ea0028c18ec2c91ae", ImportPaths: []string{ "$GOGO_PROTOBUF", }, } }
GetRepositoryGoGoProtobuf is used to get gogo protobuf repository
GetRepositoryGoGoProtobuf
go
storyicon/powerproto
cmd/powerproto/subcommands/init/repositories.go
https://github.com/storyicon/powerproto/blob/master/cmd/powerproto/subcommands/init/repositories.go
Apache-2.0
func GetRepositoryGoogleAPIs() *Repository { return &Repository{ Name: "GOOGLE_APIS", Pkg: "https://github.com/googleapis/googleapis@75e9812478607db997376ccea247dd6928f70f45", ImportPaths: []string{ "$GOOGLE_APIS/github.com/googleapis/googleapis", }, } }
GetRepositoryGoogleAPIs is used to get google apis repository
GetRepositoryGoogleAPIs
go
storyicon/powerproto
cmd/powerproto/subcommands/init/repositories.go
https://github.com/storyicon/powerproto/blob/master/cmd/powerproto/subcommands/init/repositories.go
Apache-2.0
func GetRepositoryFromOptionsValue(val string) (*Repository, bool) { repositories := GetWellKnownRepositories() for _, repo := range repositories { if repo.GetOptionsValue() == val { return repo, true } } return nil, false }
GetRepositoryFromOptionsValue is used to get plugin by option value
GetRepositoryFromOptionsValue
go
storyicon/powerproto
cmd/powerproto/subcommands/init/repositories.go
https://github.com/storyicon/powerproto/blob/master/cmd/powerproto/subcommands/init/repositories.go
Apache-2.0
func GetWellKnownRepositoriesOptionValues() []string { repos := GetWellKnownRepositories() packages := make([]string, 0, len(repos)) for _, repo := range repos { packages = append(packages, repo.GetOptionsValue()) } return packages }
GetWellKnownRepositoriesOptionValues is used to get option values of well known plugins
GetWellKnownRepositoriesOptionValues
go
storyicon/powerproto
cmd/powerproto/subcommands/init/repositories.go
https://github.com/storyicon/powerproto/blob/master/cmd/powerproto/subcommands/init/repositories.go
Apache-2.0
func (plugin *Plugin) GetOptionsValue() string { if plugin.OptionsValue != "" { return plugin.OptionsValue } return fmt.Sprintf("%s: %s", plugin.Name, plugin.Pkg) }
GetOptionsValue is used to get options value of plugin
GetOptionsValue
go
storyicon/powerproto
cmd/powerproto/subcommands/init/plugins.go
https://github.com/storyicon/powerproto/blob/master/cmd/powerproto/subcommands/init/plugins.go
Apache-2.0
func GetPluginProtocGenGo() *Plugin { return &Plugin{ Name: "protoc-gen-go", Pkg: "google.golang.org/protobuf/cmd/protoc-gen-go@latest", Options: []string{ "--go_out=.", "--go_opt=paths=source_relative", }, } }
GetPluginProtocGenGo is used to get protoc-gen-go plugin
GetPluginProtocGenGo
go
storyicon/powerproto
cmd/powerproto/subcommands/init/plugins.go
https://github.com/storyicon/powerproto/blob/master/cmd/powerproto/subcommands/init/plugins.go
Apache-2.0
func GetPluginProtocGenGoGRPC() *Plugin { return &Plugin{ Name: "protoc-gen-go-grpc", Pkg: "google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest", Options: []string{ "--go-grpc_out=.", "--go-grpc_opt=paths=source_relative", }, } }
GetPluginProtocGenGoGRPC is used to get protoc-gen-go-grpc plugin
GetPluginProtocGenGoGRPC
go
storyicon/powerproto
cmd/powerproto/subcommands/init/plugins.go
https://github.com/storyicon/powerproto/blob/master/cmd/powerproto/subcommands/init/plugins.go
Apache-2.0
func GetWellKnownPlugins() []*Plugin { return []*Plugin{ GetPluginProtocGenGo(), GetPluginProtocGenGoGRPC(), { Name: "protoc-gen-grpc-gateway", Pkg: "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest", Options: []string{ "--grpc-gateway_out=.", "--grpc-gateway_opt=paths=source_relative", }, }, { OptionsValue: "protoc-gen-go-grpc (SupportPackageIsVersion6)", Name: "protoc-gen-go-grpc", Pkg: "google.golang.org/grpc/cmd/protoc-gen-go-grpc@ad51f572fd270f2323e3aa2c1d2775cab9087af2", Options: []string{ "--go-grpc_out=.", "--go-grpc_opt=paths=source_relative", }, }, { Name: "protoc-gen-openapiv2", Pkg: "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest", Options: []string{ "--openapiv2_out=.", }, }, { Name: "protoc-gen-gogo", Pkg: "github.com/gogo/protobuf/protoc-gen-gogo@latest", Options: []string{ "--gogo_out=plugins=grpc:.", "--gogo_opt=paths=source_relative", }, }, { Name: "protoc-gen-gofast", Pkg: "github.com/gogo/protobuf/protoc-gen-gofast@latest", Options: []string{ "--gofast_out=plugins=grpc:.", "--gofast_opt=paths=source_relative", }, }, { Name: "protoc-gen-deepcopy", Pkg: "istio.io/tools/cmd/protoc-gen-deepcopy@latest", Options: []string{ "--deepcopy_out=source_relative:.", }, }, { Name: "protoc-gen-go-json", Pkg: "github.com/mitchellh/protoc-gen-go-json@latest", Options: []string{ "--go-json_out=.", }, }, } }
GetWellKnownPlugins is used to get well known plugins
GetWellKnownPlugins
go
storyicon/powerproto
cmd/powerproto/subcommands/init/plugins.go
https://github.com/storyicon/powerproto/blob/master/cmd/powerproto/subcommands/init/plugins.go
Apache-2.0
func GetPluginFromOptionsValue(val string) (*Plugin, bool) { plugins := GetWellKnownPlugins() for _, plugin := range plugins { if plugin.GetOptionsValue() == val { return plugin, true } } return nil, false }
GetPluginFromOptionsValue is used to get plugin by option value
GetPluginFromOptionsValue
go
storyicon/powerproto
cmd/powerproto/subcommands/init/plugins.go
https://github.com/storyicon/powerproto/blob/master/cmd/powerproto/subcommands/init/plugins.go
Apache-2.0
func GetWellKnownPluginsOptionValues() []string { plugins := GetWellKnownPlugins() packages := make([]string, 0, len(plugins)) for _, plugin := range plugins { packages = append(packages, plugin.GetOptionsValue()) } return packages }
GetWellKnownPluginsOptionValues is used to get option values of well known plugins
GetWellKnownPluginsOptionValues
go
storyicon/powerproto
cmd/powerproto/subcommands/init/plugins.go
https://github.com/storyicon/powerproto/blob/master/cmd/powerproto/subcommands/init/plugins.go
Apache-2.0
func CommandEnv(log logger.Logger) *cobra.Command { return &cobra.Command{ Use: "env", Short: "list the environments and binary files", Run: func(cmd *cobra.Command, args []string) { log.LogInfo(nil, "[ENVIRONMENT]") for _, key := range []string{ consts.EnvHomeDir, "HTTP_PROXY", "HTTPS_PROXY", "GOPROXY", } { log.LogInfo(nil, "%s=%s", key, os.Getenv(key)) } log.LogInfo(nil, "[BIN]") for _, key := range []string{ "go", "git", } { path, err := exec.LookPath(key) if err != nil { log.LogError(nil, "failed to find: %s", key) continue } log.LogInfo(nil, "%s=%s", key, path) } }, } }
CommandEnv is used to print environment variables related to program operation
CommandEnv
go
storyicon/powerproto
cmd/powerproto/subcommands/env/command.go
https://github.com/storyicon/powerproto/blob/master/cmd/powerproto/subcommands/env/command.go
Apache-2.0
func CommandBuild(log logger.Logger) *cobra.Command { var recursive bool var dryRun bool var debugMode bool var postScriptEnabled bool perCommandTimeout := time.Second * 300 cmd := &cobra.Command{ Use: "build [dir|proto file]", Short: "compile proto files", Long: strings.TrimSpace(description), Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { log.SetLogLevel(logger.LevelInfo) ctx := cmd.Context() ctx = consts.WithPerCommandTimeout(ctx, perCommandTimeout) if debugMode { ctx = consts.WithDebugMode(ctx) log.LogWarn(nil, "running in debug mode") log.SetLogLevel(logger.LevelDebug) } if dryRun { ctx = consts.WithDryRun(ctx) log.LogWarn(nil, "running in dryRun mode") } if !postScriptEnabled { ctx = consts.WithDisableAction(ctx) } target, err := filepath.Abs(args[0]) if err != nil { log.LogFatal(nil, "failed to abs target path: %s", err) } fileInfo, err := os.Stat(target) if err != nil { log.LogFatal(map[string]interface{}{ "target": target, }, "failed to stat target: %s", err) } var targets []string if fileInfo.IsDir() { log.LogInfo(nil, "search proto files...") if recursive { targets, err = util.GetFilesWithExtRecursively(target, ".proto") if err != nil { log.LogFatal(nil, "failed to walk directory: %s", err) } } else { targets, err = util.GetFilesWithExt(target, ".proto") if err != nil { log.LogFatal(nil, "failed to walk directory: %s", err) } } } else { targets = append(targets, target) } if len(targets) == 0 { log.LogWarn(nil, "no file to compile") return } if err := bootstraps.StepTidyConfig(ctx, targets); err != nil { log.LogFatal(nil, "failed to tidy config: %+v", err) return } if err := bootstraps.Compile(ctx, targets); err != nil { log.LogFatal(nil, "failed to compile: %+v", err) } log.LogInfo(nil, "succeed! you are ready to go :)") }, } flags := cmd.PersistentFlags() flags.BoolVarP(&recursive, "recursive", "r", recursive, "whether to recursively traverse all child folders") flags.BoolVarP(&postScriptEnabled, "postScriptEnabled", "p", postScriptEnabled, "when this flag is attached, it will allow the execution of postActions and postShell") flags.BoolVarP(&debugMode, "debug", "d", debugMode, "debug mode") flags.BoolVarP(&dryRun, "dryRun", "y", dryRun, "dryRun mode") flags.DurationVarP(&perCommandTimeout, "timeout", "t", perCommandTimeout, "execution timeout for per command") return cmd }
CommandBuild is used to compile proto files powerproto build -r . powerproto build . powerproto build xxxxx.proto
CommandBuild
go
storyicon/powerproto
cmd/powerproto/subcommands/build/command.go
https://github.com/storyicon/powerproto/blob/master/cmd/powerproto/subcommands/build/command.go
Apache-2.0
func CommandTidy(log logger.Logger) *cobra.Command { var debugMode bool perCommandTimeout := time.Second * 300 cmd := &cobra.Command{ Use: "tidy [config file]", Short: "tidy the config file. It will replace the version number and install the protoc and proto plugins that declared in the config file", Run: func(cmd *cobra.Command, args []string) { ctx := cmd.Context() ctx = consts.WithPerCommandTimeout(ctx, perCommandTimeout) log.SetLogLevel(logger.LevelInfo) if debugMode { log.SetLogLevel(logger.LevelDebug) ctx = consts.WithDebugMode(ctx) log.LogWarn(nil, "running in debug mode") } var targets []string if len(args) != 0 { for _, arg := range args { dir, _ := filepath.Abs(arg) targets = append(targets, dir) } } else { dir, err := os.Getwd() if err != nil { log.LogFatal(nil, "failed to get current dir: %s", err) } targets = configs.ListConfigPaths(dir) } pluginManager, err := pluginmanager.NewPluginManager(pluginmanager.NewConfig(), log) if err != nil { log.LogFatal(nil, "failed to create plugin manager: %s", err) } configMap := map[string]struct{}{} for _, path := range targets { exists, err := util.IsFileExists(path) if err != nil { log.LogFatal(map[string]interface{}{ "path": path, "err": err, }, "failed to tidy config") } if !exists { continue } log.LogInfo(nil, "tidy %s", path) if err := tidy(ctx, pluginManager, path); err != nil { log.LogFatal(map[string]interface{}{ "path": path, "err": err, }, "failed to tidy config") } configMap[path] = struct{}{} } log.LogInfo(nil, "these following config files were tidied:") for path := range configMap { log.LogInfo(nil, " %s", path) } log.LogInfo(nil, "\r\nsucceeded, you are ready to go :)") }, } flags := cmd.PersistentFlags() flags.BoolVarP(&debugMode, "debug", "d", debugMode, "debug mode") flags.DurationVarP(&perCommandTimeout, "timeout", "t", perCommandTimeout, "execution timeout for per command") return cmd }
CommandTidy is used to clean the config file By default, clean the powerproto.yaml of the current directory and all parent directories You can also explicitly specify the configuration file to clean up
CommandTidy
go
storyicon/powerproto
cmd/powerproto/subcommands/tidy/command.go
https://github.com/storyicon/powerproto/blob/master/cmd/powerproto/subcommands/tidy/command.go
Apache-2.0
func (e Entry) MarshalBinary() ([]byte, error) { entry := struct { C []string V [][]driver.Value }{ C: e.Columns, V: e.Values, } var buf bytes.Buffer if err := gob.NewEncoder(&buf).Encode(entry); err != nil { return nil, err } return buf.Bytes(), nil }
MarshalBinary implements the encoding.BinaryMarshaler interface.
MarshalBinary
go
ariga/entcache
level.go
https://github.com/ariga/entcache/blob/master/level.go
Apache-2.0
func (e *Entry) UnmarshalBinary(buf []byte) error { var entry struct { C []string V [][]driver.Value } if err := gob.NewDecoder(bytes.NewBuffer(buf)).Decode(&entry); err != nil { return err } e.Values = entry.V e.Columns = entry.C return nil }
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
UnmarshalBinary
go
ariga/entcache
level.go
https://github.com/ariga/entcache/blob/master/level.go
Apache-2.0
func NewLRU(maxEntries int) *LRU { return &LRU{ Cache: lru.New(maxEntries), } }
NewLRU creates a new Cache. If maxEntries is zero, the cache has no limit.
NewLRU
go
ariga/entcache
level.go
https://github.com/ariga/entcache/blob/master/level.go
Apache-2.0
func (l *LRU) Add(_ context.Context, k Key, e *Entry, ttl time.Duration) error { l.mu.Lock() defer l.mu.Unlock() buf, err := e.MarshalBinary() if err != nil { return err } ne := &Entry{} if err := ne.UnmarshalBinary(buf); err != nil { return err } if ttl == 0 { l.Cache.Add(k, ne) } else { l.Cache.Add(k, &entry{Entry: ne, expiry: time.Now().Add(ttl)}) } return nil }
Add adds the entry to the cache.
Add
go
ariga/entcache
level.go
https://github.com/ariga/entcache/blob/master/level.go
Apache-2.0
func (l *LRU) Get(_ context.Context, k Key) (*Entry, error) { l.mu.Lock() e, ok := l.Cache.Get(k) l.mu.Unlock() if !ok { return nil, ErrNotFound } switch e := e.(type) { case *Entry: return e, nil case *entry: if time.Now().Before(e.expiry) { return e.Entry, nil } l.mu.Lock() l.Cache.Remove(k) l.mu.Unlock() return nil, ErrNotFound default: return nil, fmt.Errorf("entcache: unexpected entry type: %T", e) }
Get gets an entry from the cache.
Get
go
ariga/entcache
level.go
https://github.com/ariga/entcache/blob/master/level.go
Apache-2.0
func NewRedis(c redis.Cmdable) *Redis { return &Redis{c: c} }
NewRedis returns a new Redis cache level from the given Redis connection. entcache.NewRedis(redis.NewClient(&redis.Options{ Addr: ":6379" })) entcache.NewRedis(redis.NewClusterClient(&redis.ClusterOptions{ Addrs: []string{":7000", ":7001", ":7002"}, }))
NewRedis
go
ariga/entcache
level.go
https://github.com/ariga/entcache/blob/master/level.go
Apache-2.0