apis

package
v1.41.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Parser = &resourceparser.Parser{
	Name: "APIs",

	InterestingImports: resourceparser.RunAlways,
	Run: func(p *resourceparser.Pass) {
		for _, file := range p.Pkg.Files {
			for _, decl := range file.AST().Decls {
				switch decl := decl.(type) {
				case *ast.FuncDecl:
					if decl.Doc == nil {
						continue
					}

					dir, doc, ok := directive.Parse(p.Errs, decl.Doc)
					if !ok {
						continue
					} else if dir == nil {
						continue
					}

					switch dir.Name {
					case "api":
						ep := api.Parse(api.ParseData{
							Errs:   p.Errs,
							Schema: p.SchemaParser,
							File:   file,
							Func:   decl,
							Dir:    dir,
							Doc:    doc,
						})

						if ep != nil {
							p.RegisterResource(ep)

							p.AddNamedBind(file, ep.Decl.AST.Name, ep)
						}

					case "authhandler":
						ah := authhandler.Parse(authhandler.ParseData{
							Errs:   p.Errs,
							Schema: p.SchemaParser,
							File:   file,
							Func:   decl,
							Dir:    dir,
							Doc:    doc,
						})
						if ah != nil {
							p.RegisterResource(ah)
							if ah.Recv.Empty() {
								p.AddNamedBind(file, ah.Decl.AST.Name, ah)
							}
						}

					case "middleware":
						mw := middleware.Parse(middleware.ParseData{
							Errs:   p.Errs,
							Schema: p.SchemaParser,
							File:   file,
							Func:   decl,
							Dir:    dir,
							Doc:    doc,
						})

						if mw != nil {
							p.RegisterResource(mw)
							if mw.Recv.Empty() {
								p.AddNamedBind(file, mw.Decl.AST.Name, mw)
							}
						}

					default:
						p.Errs.Add(errUnexpectedDirective(dir.Name).AtGoNode(decl))
					}

				case *ast.GenDecl:
					if decl.Tok != token.TYPE {
						continue
					} else if decl.Doc == nil {
						continue
					}

					dir, doc, ok := directive.Parse(p.Errs, decl.Doc)
					if !ok {
						continue
					} else if dir == nil {
						continue
					}

					switch dir.Name {
					case "service":
						ss := servicestruct.Parse(servicestruct.ParseData{
							Errs:   p.Errs,
							Schema: p.SchemaParser,
							File:   file,
							Decl:   decl,
							Dir:    dir,
							Doc:    doc,
						})

						if ss != nil {
							p.RegisterResource(ss)
							p.AddNamedBind(file, ss.Decl.AST.Name, ss)
						}

					default:
						p.Errs.Add(errUnexpectedDirective(dir.Name).AtGoNode(decl))
					}
				}
			}
		}
	},
}

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

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