analyzer

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package analyzer scanning source code and returns result of the scanning. Searches interfaces as a rpc description and returns list of the methods.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrGoSyntax returns when parsed packages contains errors.
	ErrGoSyntax = errors.New("go syntax")
	// ErrWrongNumberPackages returns when analyzer got unexpected number of packeges.
	ErrWrongNumberPackages = errors.New("wrong number of packages")
	// ErrProblemWithService returns when package not contains type with service methods or has some problems.
	ErrProblemWithService = errors.New("problem with service type")
	// ErrInvalidData generic error returns when we got unexpected data.
	ErrInvalidData = errors.New("invalid data")
	// ErrFieldSkippedByTag field should be skipped in json parser.
	ErrFieldSkippedByTag = errors.New("field skipped by tag")
	// ErrNotEnumType named type is not an enum type.
	ErrNotEnumType = errors.New("not enum type")
	// ErrMagicMethodSetErrorData error for magic method to set error data model.
	ErrMagicMethodSetErrorData = errors.New("magic method setErrorData")
)

Functions

func JoinComments

func JoinComments(comments ...*ast.CommentGroup) string

JoinComments joins some groups of comments.

func ParseKnownTypes added in v0.2.0

func ParseKnownTypes(path string) (map[string]model.Argument, error)

ParseKnownTypes parses known types from file.

Types

type Analyzer

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

Analyzer contains method to scan source code.

func New

func New(log *zerolog.Logger, conf *config.Search) (*Analyzer, error)

New creates new analyzer with search configuration.

func (*Analyzer) Run

func (a *Analyzer) Run(ctx context.Context) (*model.Service, error)

Run runs analyzer over source code and returns result of the scanning.

type FieldTag

type FieldTag struct {
	Name         string             // JSON tag's name or origin field's name.
	SwaggerKind  model.ArgumentKind // Type of the swagger.
	IsSkipped    bool               // The fields should be skipped in swagger spec.
	IsOptional   bool               // The field has the omitempty tag.
	IsDeprecated bool               // The field has deprecated mark in the tag.
}

FieldTag represents parsed field's tag.

func ParseStructTag

func ParseStructTag(fieldTag *ast.BasicLit, fieldName string) (*FieldTag, error)

ParseStructTag returns parsed field's tag with params.

type KnownType added in v0.2.0

type KnownType struct {
	BasicType string `json:"basic_type"`
	Format    string `json:"format,omitempty"`
}

KnownType describes type with data of the basic type and optional format.

type KnownTypesFile added in v0.2.0

type KnownTypesFile map[string]KnownType

KnownTypesFile describes file with known types. map["package.Type"] => {BasicType: "string", Format: "date-time"}.

type MagicCommentParams

type MagicCommentParams struct {
	MethodName   string
	SwaggerTags  []string
	IsDeprecated bool
}

MagicCommentParams parsed magic comments.

func ParseMagicComments

func ParseMagicComments(doc *ast.CommentGroup) (*MagicCommentParams, error)

ParseMagicComments returns parameter from magic comment of the genpjrpc comment.

Jump to

Keyboard shortcuts

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