annotations

module
v0.0.0-...-dc97279 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: MIT

README

Annotations

Processador de anotações

Extensão

annotations-comments

Sintaxe

// @ Nome (chave: valor, outraChave: valor)

Exemplo

package main

// @Entity(collection: "user")
type UserEntity struct {}

// @Entity(collection: "product")
type ProductEntity struct {}

// @Repository(entity: UserEntity)
type UserRepository interface {}

// @Repository(entity: ProductEntity)
type ProductRepository interface {}

// @Service
type UserService struct {}

// @Controller
type UserController struct {}

Uso

package main

import (
	"go/ast"
	"log"

	"github.com/gleisonmv/annotations/annotation"
	"github.com/gleisonmv/annotations/processor"
)

var Log = log.Default()

func main() {
	proc := processor.New("diretório", &MainProcessor{})
	if err := proc.Run(); err != nil {
		panic(err)
	}
}

func Info(annotations annotation.Group) {
	for _, v := range annotations {
		Log.Printf("- %v", v)
	}
}

type MainProcessor struct{}

func (*MainProcessor) EnterFile(dir string, file string, doc *ast.File) {
	Log.Printf("Enter File %s", file)
}

func (*MainProcessor) ExitFile(dir string, file string, doc *ast.File, fset *token.FileSet) {
	Log.Printf("Exit File %s", file)
}

func (*MainProcessor) EnterStruct(
	name string, decl *ast.StructType, annotations annotation.Group) {
	Log.Printf("Struct %s", name)
	Info(annotations)
}

func (*MainProcessor) EnterInterface(
	name string, decl *ast.InterfaceType, annotations annotation.Group) {
	Log.Printf("Interface %s", name)
	Info(annotations)
}

func (*MainProcessor) EnterFunc(
	name string, decl *ast.FuncDecl, annotations annotation.Group) {
	Log.Printf("Func %s", name)
	Info(annotations)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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