nf

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: MIT Imports: 29 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 {
	HTTPSCertPath string
	HTTPSKeyPath  string
	// 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) BindHandler added in v0.0.3

func (f *APIFramework) BindHandler(prefix string, handler http.Handler) error

func (*APIFramework) BindHandlerFunc added in v0.0.3

func (f *APIFramework) BindHandlerFunc(prefix string, handler http.HandlerFunc) error

func (*APIFramework) BindStatusHandler added in v0.0.7

func (f *APIFramework) BindStatusHandler(status int, handler http.HandlerFunc)

BindStatusHandler binds the status handler for the specified pattern.

func (*APIFramework) BindStatusHandlerByMap added in v0.0.7

func (f *APIFramework) BindStatusHandlerByMap(handlers map[int]http.HandlerFunc)

BindStatusHandlerByMap binds multiple status handlers using a map.

func (*APIFramework) CORSDefault added in v0.0.6

func (f *APIFramework) CORSDefault(next http.Handler) http.Handler

CORSDefault 允许跨域请求

func (*APIFramework) CORSMiddleware added in v0.0.6

func (f *APIFramework) CORSMiddleware(opts CORSOptions) mux.MiddlewareFunc

CORSMiddleware 处理跨域请求

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) GetCookieDomain added in v0.0.7

func (f *APIFramework) GetCookieDomain() string

GetCookieDomain returns CookieDomain of server.

func (*APIFramework) GetCookieHttpOnly added in v0.0.7

func (f *APIFramework) GetCookieHttpOnly() bool

func (*APIFramework) GetCookieMaxAge added in v0.0.7

func (f *APIFramework) GetCookieMaxAge() time.Duration

GetCookieMaxAge returns the CookieMaxAge of the server.

func (*APIFramework) GetCookiePath added in v0.0.7

func (f *APIFramework) GetCookiePath() string

GetCookiePath returns the CookiePath of server.

func (*APIFramework) GetCookieSameSite added in v0.0.7

func (f *APIFramework) GetCookieSameSite() http.SameSite

GetCookieSameSite return CookieSameSite of server.

func (*APIFramework) GetCookieSecure added in v0.0.7

func (f *APIFramework) GetCookieSecure() bool

func (*APIFramework) GetIndexFiles added in v0.0.7

func (f *APIFramework) GetIndexFiles() []string

func (*APIFramework) GetServer

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

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

func (*APIFramework) GetSessionCookieMaxAge added in v0.0.7

func (f *APIFramework) GetSessionCookieMaxAge() time.Duration

GetSessionCookieMaxAge returns the SessionCookieMaxAge of server.

func (*APIFramework) GetSessionIdName added in v0.0.7

func (f *APIFramework) GetSessionIdName() string

GetSessionIdName returns the SessionIdName of server.

func (*APIFramework) GetSessionMaxAge added in v0.0.7

func (f *APIFramework) GetSessionMaxAge() time.Duration

GetSessionMaxAge returns the SessionMaxAge of server.

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) Run added in v0.0.3

func (f *APIFramework) Run()

func (*APIFramework) SetContextValue

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

SetContextValue 设置全局上下文值

func (*APIFramework) SetCookieDomain added in v0.0.7

func (f *APIFramework) SetCookieDomain(domain string)

SetCookieDomain sets the CookieDomain for server.

func (*APIFramework) SetCookieMaxAge added in v0.0.7

func (f *APIFramework) SetCookieMaxAge(ttl time.Duration)

SetCookieMaxAge sets the CookieMaxAge for server.

func (*APIFramework) SetCookiePath added in v0.0.7

func (f *APIFramework) SetCookiePath(path string)

SetCookiePath sets the CookiePath for server.

func (*APIFramework) SetFileServerEnabled added in v0.0.7

func (f *APIFramework) SetFileServerEnabled(enabled bool)

func (*APIFramework) SetFileSystem

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

SetFileSystem 设置文件系统

func (*APIFramework) SetHost added in v0.0.7

func (f *APIFramework) SetHost(host string)

func (*APIFramework) SetIndexFiles added in v0.0.7

func (f *APIFramework) SetIndexFiles(indexFiles []string)

func (*APIFramework) SetIndexFolder added in v0.0.7

func (f *APIFramework) SetIndexFolder(enabled bool)

func (*APIFramework) SetOpenApiPath added in v0.0.7

func (f *APIFramework) SetOpenApiPath(path string)

SetOpenApiPath sets the OpenApiPath for server.

func (*APIFramework) SetPort added in v0.0.3

func (f *APIFramework) SetPort(addr string)

func (*APIFramework) SetRewrite added in v0.0.7

func (f *APIFramework) SetRewrite(uri string, rewrite string)

SetRewrite sets rewrites for static URI for server.

func (*APIFramework) SetRewriteMap added in v0.0.7

func (f *APIFramework) SetRewriteMap(rewrites map[string]string)

SetRewriteMap sets the rewritten map for server.

func (*APIFramework) SetRouteOverWrite added in v0.0.7

func (f *APIFramework) SetRouteOverWrite(enabled bool)

SetRouteOverWrite sets the RouteOverWrite for server.

func (*APIFramework) SetSessionCookieMaxAge added in v0.0.7

func (f *APIFramework) SetSessionCookieMaxAge(maxAge time.Duration)

SetSessionCookieMaxAge sets the SessionCookieMaxAge for server.

func (*APIFramework) SetSessionCookieOutput added in v0.0.7

func (f *APIFramework) SetSessionCookieOutput(enabled bool)

SetSessionCookieOutput sets the SetSessionCookieOutput for server.

func (*APIFramework) SetSessionIdName added in v0.0.7

func (f *APIFramework) SetSessionIdName(name string)

SetSessionIdName sets the SessionIdName for server.

func (*APIFramework) SetSessionMaxAge added in v0.0.7

func (f *APIFramework) SetSessionMaxAge(ttl time.Duration)

SetSessionMaxAge sets the SessionMaxAge for server.

func (*APIFramework) SetStaticDir

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

SetStaticDir 设置静态资源目录

func (*APIFramework) SetSwaggerPath added in v0.0.7

func (f *APIFramework) SetSwaggerPath(path string)

SetSwaggerPath sets the SwaggerPath for server.

func (*APIFramework) SetSwaggerUITemplate added in v0.0.7

func (f *APIFramework) SetSwaggerUITemplate(swaggerUITemplate string)

SetSwaggerUITemplate sets the Swagger template for server.

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 CORSOptions added in v0.0.6

type CORSOptions struct {
	AllowDomain      []string // Used for allowing requests from custom domains
	AllowOrigin      string   // Access-Control-Allow-Origin
	AllowCredentials string   // Access-Control-Allow-Credentials
	ExposeHeaders    string   // Access-Control-Expose-Headers
	MaxAge           int      // Access-Control-Max-Age
	AllowMethods     string   // Access-Control-Allow-Methods
	AllowHeaders     string   // Access-Control-Allow-Headers
}

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