iris_enhance

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: MIT Imports: 13 Imported by: 1

README

Release Coverage Status

iris-enhance

中文版 README

Iris Enhancement (including Swagger documentation generation, custom annotations, etc.)

Project Description
  • Enhances development with annotations, enabling a Java-like controller development approach
  • Reduces code duplication and improves development efficiency
  • One-click generation of Swagger documentation
  • Supports custom annotations for implementing features like logging and access control
Example
  1. Create a service file in the service folder
  2. Run the iris-enhance command to generate corresponding handler and router code
  3. Register routes
  4. Bind Swagger documentation (UI from knife4j)

For detailed examples, please refer to the Chinese README.

Supported Annotation Tags
  • @zService
  • @zResult
  • @zSummary
  • @zDescription
  • @zTags
  • @zParam
  • @zResultData
  • @zAccept
  • @zProduce
  • @zRouter

For detailed explanations of these tags, please refer to the Chinese README.

Command Usage
  1. Installation:

    go get github.com/celt237/iris-enhance/cmd/iris-enhance@latest
    
  2. Add github.com/celt237/iris-enhance dependency to your project

  3. Run the iris-enhance command:

    iris-enhance --servicePath=xxx --handlePath=xxx --result=xxx --errorCode=xxx
    

For detailed instructions and troubleshooting, please refer to the Chinese README.

MIT LICENSE

LICENSE

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetParamFromContext

func GetParamFromContext[T any](ctx iris.Context, paramName string, dataType string, paramType string, ptr bool, required bool) (value T, err error)

GetParamFromContext 从iris.Context中获取参数 ctx iris.Context 上下文 paramName string 参数名 dataType string 数据类型 paramType string 参数类型 ptr bool 是否指针 required bool 是否必须

func RegisterSwaggerDoc

func RegisterSwaggerDoc(app *iris.Application, jsonPath string, route string)

RegisterSwaggerDoc registers swagger documentation

app : the iris application

jsonPath: the path to the swagger json file (e.g. ./docs/swagger.json)

route: the path to register the swagger documentation (e.g. /doc)

return: the path of the swagger documentation

Types

type ApiHandler

type ApiHandler interface {
	// WrapContext 从iris.Context中获取context.Context
	WrapContext(ctx iris.Context) context.Context

	// Success 成功返回
	// ctx iris.Context 上下文
	// produceType string 返回类型
	// data interface{} 返回数据
	Success(ctx iris.Context, produceType string, data interface{})

	// CodeError 失败返回
	// ctx iris.Context 上下文
	// produceType string 返回类型
	// data interface{} 返回数据
	// code int 错误码
	// err error 错误
	CodeError(ctx iris.Context, produceType string, data interface{}, code int, err error)

	// Error 失败返回
	// ctx iris.Context 上下文
	// produceType string 返回类型
	// data interface{} 返回数据
	// err error 错误
	Error(ctx iris.Context, produceType string, data interface{}, err error)

	// HandleCustomerAnnotation 处理自定义注解
	// ctx iris.Context 上下文
	// annotation string 注解名
	// opt ...string 参数
	HandleCustomerAnnotation(ctx iris.Context, annotation string, opt ...string) error
}

type Config

type Config struct {
	RelativePath string
	DocJson      []byte
}

type ErrorWithCode

type ErrorWithCode interface {
	error
	Code() int
}

type FileInfo added in v0.0.4

type FileInfo interface {
	GetFileHeader() *multipart.FileHeader
	GetFile() multipart.File
}

func NewFileInfo added in v0.0.4

func NewFileInfo(file multipart.File, fileHeader *multipart.FileHeader) FileInfo

type FileInfoImpl added in v0.0.4

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

func (*FileInfoImpl) GetFile added in v0.0.4

func (f *FileInfoImpl) GetFile() multipart.File

func (*FileInfoImpl) GetFileHeader added in v0.0.4

func (f *FileInfoImpl) GetFileHeader() *multipart.FileHeader

Directories

Path Synopsis
cmd
tmp

Jump to

Keyboard shortcuts

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