apigo

package module
v0.0.0-...-a36f1ba Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2024 License: MIT Imports: 28 Imported by: 0

README

apigo

Auto generate api from struct

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoCamelCase

func GoCamelCase(s string) string

GoCamelCase camel-cases a protobuf name for use as a Go identifier.

If there is an interior underscore followed by a lower case letter, drop the underscore and convert the letter to upper case.

func Notify

func Notify(c *Client, path string, method string, body any) error

func ReadMessage

func ReadMessage[T any](s *Server, ctx *gin.Context) (*T, error)

func Request

func Request[T any](c *Client, path string, method string, body any) (*T, error)

func TabulatorQuery

func TabulatorQuery[T any](ctx *gin.Context, collection string, selector any)

Types

type Client

type Client struct {
	WithBSON bool
	// contains filtered or unexported fields
}

func NewClient

func NewClient(host string) *Client

func (*Client) BuildURL

func (c *Client) BuildURL(p string) string

type Context

type Context = gin.Context

type ExprType

type ExprType int
const (
	Array   ExprType = iota
	Pointer ExprType = iota
)

type FuncDecl

type FuncDecl struct {
	Decl    *ast.FuncDecl
	Name    string
	Recv    NameType
	Params  []*NameType
	Results []*NameType

	LastResultIndex int
	HasNormalResult bool
	LastResultError bool
}

func (*FuncDecl) Init

func (method *FuncDecl) Init()

func (*FuncDecl) WriteRR

func (method *FuncDecl) WriteRR(builder *strings.Builder)

type NameType

type NameType struct {
	Name string
	Type string
}

type Parser

type Parser struct {
	Services map[string]*Service
	Pkgname  string
	// contains filtered or unexported fields
}

func NewParser

func NewParser() *Parser

func (*Parser) ParseDir

func (p *Parser) ParseDir(path string) error

func (*Parser) WriteClient

func (p *Parser) WriteClient(pkgname, hpath, path string) error

func (*Parser) WriteJS

func (p *Parser) WriteJS(hpath, path string) error

func (*Parser) WriteServer

func (p *Parser) WriteServer(pkgname, hpath, path string) error

type Server

type Server struct {
	App      *gin.Engine
	WithBSON bool
	// contains filtered or unexported fields
}

func NewServer

func NewServer() *Server

func (*Server) HandleGet

func (s *Server) HandleGet(path string, handler func(ctx *gin.Context))

func (*Server) HandlePost

func (s *Server) HandlePost(path string, handler func(ctx *gin.Context))

func (*Server) ResponseData

func (s *Server) ResponseData(ctx *gin.Context, data any)

func (*Server) ResponseError

func (s *Server) ResponseError(ctx *gin.Context, code int, err error)

func (*Server) Start

func (s *Server) Start(domain, email, addr string) error

Start start server cert: tls cert file path key: tls key file path addr: listen address. eg: :https

func (*Server) Static

func (s *Server) Static(relativePath string, root string)

Static add Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp to all routers

func (*Server) TusdHandle

func (s *Server) TusdHandle(path string, handle TusdHandle)

func (*Server) TusdUpload

func (s *Server) TusdUpload(store, path string) error

TusdUpload handle upload request store: upload file store path path: upload request path. eg: /upload/

type Service

type Service struct {
	Name    string
	Methods []*FuncDecl
}

type TusdHandle

type TusdHandle func(ctx *gin.Context, reader io.Reader, info *tusd.FileInfo) (any, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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