core

package
v0.7.0-rc1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package core contains every logic for working cli.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidRule = errors.New("invalid rule")
)

Functions

func CheckIsIgnored

func CheckIsIgnored(comments []*parser.Comment, ruleName string) bool

CheckIsIgnored check if passed ruleName has to be ignored due to ignore command in comments

func GetRuleName

func GetRuleName(rule Rule) string

GetRuleName returns rule name

func SetAllowCommentIgnores

func SetAllowCommentIgnores(val bool)

Types

type BUFConfig

type BUFConfig struct {
	Version  string   `yaml:"version"`
	Deps     []string `yaml:"deps"`
	Build    Build    `yaml:"build"`
	Lint     Lint     `yaml:"lint"`
	Breaking Breaking `yaml:"breaking"`
}

BUFConfig is the configuration for the buf tool.

type Breaking

type Breaking struct {
	Use                    []string            `yaml:"use"`
	Except                 []string            `yaml:"except"`
	Ignore                 []string            `yaml:"ignore"`
	IgnoreOnly             map[string][]string `yaml:"ignore_only"`
	IgnoreUnstablePackages bool                `yaml:"ignore_unstable_packages"`
}

Breaking is the configuration for the breaking section of the buf tool.

type Build

type Build struct {
	Excludes []string `yaml:"excludes"`
}

Build is the configuration for the build section of the buf tool.

type Config

type Config struct {
	Deps          []string
	Plugins       []Plugin
	Inputs        Inputs
	ModuleReflect *modulereflect.ModuleReflect
}

Config is the configuration for EasyP generate.

type Console

type Console interface {
	RunCmd(ctx context.Context, dir string, command string, commandParams ...string) (string, error)
}

Console is provide to terminal command in console.

type Core

type Core struct {
	// contains filtered or unexported fields
}

Core provide to business logic of EasyP.

func New

func New(
	rules []Rule,
	ignore []string,
	deps []string,
	moduleReflect *modulereflect.ModuleReflect,
	ignoreOnly map[string][]string,
	logger *slog.Logger,
	plugins []Plugin,
	inputs Inputs,
	console Console,
	storage Storage,
	moduleConfig ModuleConfig,
	lockFile LockFile,
) *Core

func (*Core) Download

func (c *Core) Download(ctx context.Context, dependencies []string) error

Download all packages from config dependencies slice of strings format: origin@version: github.com/company/repository@v1.2.3 if version is absent use the latest commit

func (*Core) Generate

func (c *Core) Generate(ctx context.Context, root, directory string) error

Generate generates files.

func (*Core) Get

func (c *Core) Get(ctx context.Context, requestedModule models.Module) error

Get download package.

func (*Core) Initialize

func (i *Core) Initialize(ctx context.Context, disk FS, defaultLinters []string) error

Initialize initializes the EasyP configuration.

func (*Core) Lint

func (c *Core) Lint(ctx context.Context, disk fs.FS, path string) ([]IssueInfo, error)

Lint lints the proto file.

func (*Core) Update

func (c *Core) Update(ctx context.Context, dependencies []string) error

Update all packages from config dependencies slice of strings format: origin@version: github.com/company/repository@v1.2.3 if version is absent use the latest commit

func (*Core) Vendor

func (c *Core) Vendor(ctx context.Context) error

Vendor copy all proto files from deps to local dir

type EasyPConfig

type EasyPConfig struct {
	Version  string   `yaml:"version"`
	Deps     []string `yaml:"deps"`
	Build    Build    `yaml:"build"`
	Lint     Lint     `yaml:"lint"`
	Breaking Breaking `yaml:"breaking"`
}

EasyPConfig is the configuration for EasyP.

type FS

type FS interface {
	fs.FS
	// Create creates a file.
	Create(name string) (*os.File, error)
}

FS is the interface for the file system.

type ImportPath

type ImportPath string

ImportPath type alias for path import in proto file

func ConvertImportPath

func ConvertImportPath(source string) ImportPath

type Inputs

type Inputs struct {
	Dirs []string
}

Inputs is the source for generating code.

type InstructionInfo

type InstructionInfo struct {
	PkgName     string
	Instruction string
}

instructionInfo collects info about instruction in proto file e.g `google.api.http`:

`google.api` - package name
'http' - instruction name

func (InstructionInfo) GetFullName

func (i InstructionInfo) GetFullName() string

type InstructionParser

type InstructionParser struct {
	SourcePkgName string
}

parseInstruction parse input string and return its package name if passed input does not have package -> return pkgName as package name source proto file

func (InstructionParser) Parse

func (p InstructionParser) Parse(input string) InstructionInfo

type Issue

type Issue struct {
	Position   meta.Position
	SourceName string
	Message    string
	RuleName   string
}

Issue contains the information of an issue.

func AppendIssue

func AppendIssue(
	issues []Issue, lintRule Rule, pos meta.Position, sourceName string, comments []*parser.Comment,
) []Issue

AppendIssue check if lint error is ignored -> add new error to slice otherwise ignore appending

type IssueInfo

type IssueInfo struct {
	Issue
	Path string
}

IssueInfo contains the information of an issue and the path.

type Lint

type Lint struct {
	Use                                  []string            `yaml:"use"`
	Except                               []string            `yaml:"except"`
	Ignore                               []string            `yaml:"ignore"`
	IgnoreOnly                           map[string][]string `yaml:"ignore_only"`
	AllowCommentIgnores                  bool                `yaml:"allow_comment_ignores"`
	EnumZeroValueSuffix                  string              `yaml:"enum_zero_value_suffix"`
	RPCAllowSameRequestResponse          bool                `yaml:"rpc_allow_same_request_response"`
	RPCAllowGoogleProtobufEmptyRequests  bool                `yaml:"rpc_allow_google_protobuf_empty_requests"`
	RPCAllowGoogleProtobufEmptyResponses bool                `yaml:"rpc_allow_google_protobuf_empty_responses"`
	ServiceSuffix                        string              `yaml:"service_suffix"`
}

Lint is the configuration for the lint section of the buf tool.

type LockFile

type LockFile interface {
	Read(moduleName string) (models.LockFileInfo, error)
	Write(
		moduleName string, revisionVersion string, installedPackageHash models.ModuleHash,
	) error
	IsEmpty() bool
	DepsIter() iter.Seq[models.LockFileInfo]
}

LockFile should implement adapter for lock file workflow

type Migrate

type Migrate struct {
	BUF *BUFConfig
}

Migrate contains original configuration for the migration.

type ModuleConfig

type ModuleConfig interface {
	ReadFromRepo(ctx context.Context, repo repository.Repo, revision models.Revision) (models.ModuleConfig, error)
}

ModuleConfig should implement adapter for reading module configs

type OpenImportFileError

type OpenImportFileError struct {
	FileName string
}

func (*OpenImportFileError) Error

func (e *OpenImportFileError) Error() string

type Plugin

type Plugin struct {
	Name    string
	Out     string
	Options map[string]string
}

Plugin is a plugin for gRPC generator.

type ProtoInfo

type ProtoInfo struct {
	Path                 string
	Info                 *unordered.Proto
	ProtoFilesFromImport map[ImportPath]*unordered.Proto
}

ProtoInfo is the information of a proto file.

type Query

type Query struct {
	Compiler string
	Imports  []string
	Plugins  []Plugin
	Files    []string
}

Query is a query for making sh command.

type Rule

type Rule interface {
	// Message returns the message of the rule.
	Message() string
	// Validate validates the proto rule.
	Validate(ProtoInfo) ([]Issue, error)
}

Rule is an interface for a rule checking.

type Storage

type Storage interface {
	CreateCacheRepositoryDir(name string) (string, error)
	CreateCacheDownloadDir(models.CacheDownloadPaths) error
	GetCacheDownloadPaths(module models.Module, revision models.Revision) models.CacheDownloadPaths
	Install(
		cacheDownloadPaths models.CacheDownloadPaths,
		module models.Module,
		revision models.Revision,
		moduleConfig models.ModuleConfig,
	) (models.ModuleHash, error)
	GetInstalledModuleHash(moduleName string, revisionVersion string) (models.ModuleHash, error)
	IsModuleInstalled(module models.Module) (bool, error)
}

Storage should implement workflow with storage adapter

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL