nf

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultFileConfig = FileConfig{
	MaxFileSize:  10 << 20,
	MaxTotalSize: 50 << 20,
	AllowedTypes: []string{
		"image/jpeg",
		"image/png",
		"image/gif",
		"application/pdf",
		"application/msword",
		"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
	},
	SavePath: "uploads",
}

DefaultFileConfig 默认文件上传配置

Functions

func CustomError added in v0.0.9

func CustomError(w http.ResponseWriter, err error, status int)

CustomError 是一个辅助函数,用于在控制器中返回自定义错误

func GetContextValue

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

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

func RequestFromCtx added in v0.1.0

func RequestFromCtx(ctx context.Context) *http.Request

RequestFromCtx retrieves and returns the Request object from context.

Types

type APIDefinition

type APIDefinition struct {
	HandlerName  string
	RequestType  reflect.Type
	ResponseType reflect.Type
	Meta         meta.Meta
	Parameters   []spec.Parameter
	Responses    *spec.Responses
}

APIDefinition 定义API结构

type APIFramework

type APIFramework struct {
	Host string

	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) Context added in v0.1.6

func (f *APIFramework) Context() context.Context

func (*APIFramework) EnableDebug

func (f *APIFramework) EnableDebug() *APIFramework

EnableDebug 启用调试模式

func (*APIFramework) EnableStatsviz added in v0.0.10

func (f *APIFramework) EnableStatsviz()

func (*APIFramework) ErrorHandlingMiddleware added in v0.0.9

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

ErrorHandlingMiddleware 是一个自定义的错误处理中间件

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 http.FileSystem, dir string) http.Handler

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(httpServes ...weaver.Listener) (err error)

func (*APIFramework) SaveUploadedFile added in v0.1.6

func (f *APIFramework) SaveUploadedFile(file *UploadedFile, destPath string) error

SaveUploadedFile 保存上传的文件

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 http.FileSystem) *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) SetServerRoot added in v0.1.0

func (f *APIFramework) SetServerRoot(root string) *APIFramework

SetServerRoot 设置文档根目录用于静态服务

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) UseErrorHandlingMiddleware added in v0.0.9

func (f *APIFramework) UseErrorHandlingMiddleware()

UseErrorHandlingMiddleware 在APIFramework结构体中添加一个方法来应用这个中间件

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 ErrorResponse added in v0.0.9

type ErrorResponse struct {
	Error struct {
		Code    string `json:"code"`
		Message string `json:"message"`
	} `json:"error"`
}

ErrorResponse 定义了统一的错误响应结构

func NewErrorResponse added in v0.0.9

func NewErrorResponse(code string, message string) ErrorResponse

NewErrorResponse 创建一个新的ErrorResponse

type FileConfig added in v0.1.6

type FileConfig struct {
	MaxFileSize  int64                // 单个文件最大大小
	MaxTotalSize int64                // 总上传大小限制
	AllowedTypes []string             // 允许的文件类型
	SavePath     string               // 文件保存路径
	Fields       map[string]FileField // 字段配置
}

FileConfig 文件上传配置

type FileField added in v0.1.6

type FileField struct {
	MaxSize    int64    // 最大文件大小(字节)
	AllowTypes []string // 允许的文件类型
	Required   bool     // 是否必需
}

FileField 定义文件字段的配置

type UploadedFile added in v0.1.6

type UploadedFile struct {
	Filename    string
	Size        int64
	ContentType string
	File        multipart.File
	FileHeader  *multipart.FileHeader
}

UploadedFile 表示上传的文件

type WeaverContext

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

WeaverContext 包含 ServiceWeaver 相关的上下文

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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