anno

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package annotation parse annotation from source code file and recognize follows.

Comment @Handler("name", "pkg.ExampleHandler") to define handler and use @Middleware("name") to use it around Controller handler or route handler.

Index

Constants

View Source
const (
	Description = "Build annotation files for middleware, crontab, controller etc"
	Name        = "gen:annotation"

	OptAnnotationPath             = "annotation-path"
	OptAnnotationPathDesc         = "Generated files will be saved to"
	OptAnnotationPathShort        = 'a'
	OptAnnotationPathDefaultValue = "app/annotations"

	OptControllerPath             = "controller-path"
	OptControllerPathDesc         = "Controller files location"
	OptControllerPathShort        = 'c'
	OptControllerPathDefaultValue = "app/controllers"

	OptCrontabPath             = "crontab-path"
	OptCrontabPathDesc         = "Crontab files location"
	OptCrontabPathShort        = 'r'
	OptCrontabPathDefaultValue = "app/crontabs"

	OptHandlerPath             = "handler-path"
	OptHandlerPathDesc         = "Handler files location"
	OptHandlerPathShort        = 'h'
	OptHandlerPathDefaultValue = "app/handlers"

	OptMiddlewarePath             = "middleware-path"
	OptMiddlewarePathDesc         = "Middleware files location"
	OptMiddlewarePathShort        = 'm'
	OptMiddlewarePathDefaultValue = "app/middlewares"

	OptOverride     = "override"
	OptOverrideDesc = "Override existed file, Do nothing if not specified"

	OptWorkingDir             = "working-dir"
	OptWorkingDirShort        = 'w'
	OptWorkingDirDesc         = "Current working dir is"
	OptWorkingDirDefaultValue = "./"
)

Variables

View Source
var (
	BuilderVariables = regexp.MustCompile(`{{([^}]*)}}`)
)

Functions

func New

func New() *console.Command

New creates a command for console.

You can run `go run main.go gen:annotation` to run this command.

Types

type ParseCrontab

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

ParseCrontab is a parser component used to parse crontab source code.

func (*ParseCrontab) Parse

func (o *ParseCrontab) Parse(pkg, path string) error

Parse middleware files.

Param path is an absolute file path.

func (*ParseCrontab) Save

func (o *ParseCrontab) Save() (err error)

Save parsed items into target file.

type ParseCrontabItem

type ParseCrontabItem struct {
	Pkg, Name string

	GlobalUnique, NodeUnique bool
	RunOnStart               bool
	Strategy                 string
}

ParseCrontabItem middleware parsed from source code.

ParseCrontabItem{
    Pkg: "sketch/app/crontabs",
    Name: "ExampleCrontab",
}

type ParseHandler

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

ParseHandler is a parser component used to parse middleware source code.

func (*ParseHandler) Parse

func (o *ParseHandler) Parse(pkg, path string) error

Parse middleware files.

Param path is an absolute file path.

func (*ParseHandler) Save

func (o *ParseHandler) Save() (err error)

Save parsed items into target file.

type ParseHandlerItem

type ParseHandlerItem struct {
	Pkg, Name   string
	Method, Uri string
	Middlewares []string
	// contains filtered or unexported fields
}

ParseHandlerItem middleware parsed from source code.

ParseHandlerItem{
    Key: "custom",
    Pkg: "sketch/app/middlewares",
    Name: "Example",
}

type ParseMiddleware

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

ParseMiddleware is a parser component used to parse middleware source code.

func (*ParseMiddleware) Parse

func (o *ParseMiddleware) Parse(pkg, path string) error

Parse middleware files.

Param path is an absolute file path.

func (*ParseMiddleware) Save

func (o *ParseMiddleware) Save() (err error)

Save parsed items into target file.

type ParseMiddlewareItem

type ParseMiddlewareItem struct {
	Key       string
	Pkg, Name string
}

ParseMiddlewareItem middleware parsed from source code.

ParseMiddlewareItem{
    Key: "custom",
    Pkg: "sketch/app/middlewares",
    Name: "Example",
}

type Parser

type Parser interface {
	// Parse
	// parses source code from any file path.
	//
	//   .Parse(
	//       "sketch/app/middlewares",
	//       "/data/sketch/app/middlewares/example.go",
	//   )
	Parse(pkg, path string) (err error)

	// Save
	// parsed template to a file.
	Save() (err error)
}

Parser is an interface for source code parse.

type Provider

type Provider struct {
	commands.Common
	// contains filtered or unexported fields
}

Provider is a component used to parse source to and save to annotation file.

func (*Provider) Before

func (o *Provider) Before(_ context.Context, container *console.Container, command *console.Command) (err error)

Before validate command options and accesses.

func (*Provider) Run

func (o *Provider) Run(_ context.Context, container *console.Container, _ *console.Command) (err error)

Run provider process to seek files and generate.

Jump to

Keyboard shortcuts

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