nf

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetContextValue

func GetContextValue(ctx context.Context, key string) (interface{}, bool)

GetContextValue 辅助函数,用于在控制器中获取上下文值

Types

type APIDefinition

type APIDefinition struct {
	HandlerName  string
	RequestType  reflect.Type
	ResponseType reflect.Type
	Meta         meta.Meta
}

APIDefinition 定义API结构

type APIFramework

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

APIFramework 核心框架结构

func NewAPIFramework

func NewAPIFramework() *APIFramework

NewAPIFramework 创建新的APIFramework实例

func (*APIFramework) AddWeaverService

func (f *APIFramework) AddWeaverService(s interface{}) error

AddWeaverService 自动添加 ServiceWeaver 服务

func (*APIFramework) EnableDebug

func (f *APIFramework) EnableDebug() *APIFramework

EnableDebug 启用调试模式

func (*APIFramework) GenerateSwaggerJSON

func (f *APIFramework) GenerateSwaggerJSON() (string, error)

GenerateSwaggerJSON 生成完整的 Swagger JSON

func (*APIFramework) GetController

func (f *APIFramework) GetController(name string) (interface{}, bool)

GetController 获取已注册的控制器

func (*APIFramework) GetServer

func (f *APIFramework) GetServer() http.Handler

GetServer 返回http.Handler接口,用于启动服务

func (*APIFramework) GetWeaverService

func (f *APIFramework) GetWeaverService(name string) (interface{}, error)

GetWeaverService 获取 ServiceWeaver 服务的通用方法

func (*APIFramework) Init

func (f *APIFramework) Init()

Init 初始化框架,设置路由和处理函数

func (*APIFramework) MustGetWeaverService

func (f *APIFramework) MustGetWeaverService(name string, target interface{}) error

MustGetWeaverService 获取 ServiceWeaver 服务并进行类型断言

func (*APIFramework) NewStaticHandler

func (f *APIFramework) NewStaticHandler(fs fs.FS, dir string) *StaticHandler

NewStaticHandler 创建静态文件处理器

func (*APIFramework) PrintAPIRoutes

func (f *APIFramework) PrintAPIRoutes()

PrintAPIRoutes 输出所有注册的API访问地址

func (*APIFramework) RegisterController

func (f *APIFramework) RegisterController(prefix string, controllers ...interface{}) error

RegisterController 注册控制器

func (*APIFramework) SetContextValue

func (f *APIFramework) SetContextValue(key string, value interface{})

SetContextValue 设置全局上下文值

func (*APIFramework) SetFileSystem

func (f *APIFramework) SetFileSystem(fs fs.FS) *APIFramework

SetFileSystem 设置文件系统

func (*APIFramework) SetStaticDir

func (f *APIFramework) SetStaticDir(dir string) *APIFramework

SetStaticDir 设置静态资源目录

func (*APIFramework) SetWebRoot

func (f *APIFramework) SetWebRoot(dir string) *APIFramework

SetWebRoot 设置Web根目录

func (*APIFramework) WithMiddleware

func (f *APIFramework) WithMiddleware(middlewares ...mux.MiddlewareFunc) *APIFramework

WithMiddleware 添加一个或多个中间件

type Controller

type Controller interface {
}

Controller 接口定义控制器的基本结构

type StaticHandler

type StaticHandler struct {
	FS        fs.FS
	Directory string
}

StaticHandler 处理静态文件的结构

func (*StaticHandler) ServeHTTP

func (sh *StaticHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP 实现 http.Handler 接口

type WeaverContext

type WeaverContext struct {
	Services map[string]interface{} // 存储任意 ServiceWeaver 服务,包括配置
}

WeaverContext 包含 ServiceWeaver 相关的上下文

Directories

Path Synopsis
g

Jump to

Keyboard shortcuts

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