Documentation
¶
Index ¶
- func ConfigExample()
- func Example()
- func IntegratedExample()
- func StartWithHotReload()
- func UsageWithDebugLogger()
- type Config
- func (c *Config) AddHeader(key, value string) *Config
- func (c *Config) AddProxy(path, target string) *Config
- func (c *Config) AddSetting(key string, value interface{}) *Config
- func (c *Config) AddWatchDir(dir string) *Config
- func (c *Config) EnableCORS(enabled bool) *Config
- func (c *Config) EnableConsole(enabled bool) *Config
- func (c *Config) EnableHTTPS(enabled bool) *Config
- func (c *Config) EnableHotReload(enabled bool) *Config
- func (c *Config) EnableOpenBrowser(enabled bool) *Config
- func (c *Config) EnableProfiler(enabled bool) *Config
- func (c *Config) EnableShowHTTP(enabled bool) *Config
- func (c *Config) EnableShowRoutes(enabled bool) *Config
- func (c *Config) EnableShowSQL(enabled bool) *Config
- func (c *Config) EnableVerboseLogging(enabled bool) *Config
- func (c *Config) EnableWebSocket(enabled bool) *Config
- func (c *Config) GetWatchDirsAbsolute() []string
- func (c *Config) Load(configFile string) error
- func (c *Config) Save(configFile string) error
- func (c *Config) SetConsolePort(port int) *Config
- func (c *Config) SetEnv(key, value string) *Config
- func (c *Config) SetIgnorePatterns(patterns ...string) *Config
- func (c *Config) SetProfilerPort(port int) *Config
- func (c *Config) SetReloadCallback(callback func()) *Config
- func (c *Config) SetReloadDelay(delay time.Duration) *Config
- func (c *Config) SetRootDir(dir string) *Config
- func (c *Config) SetServerHost(host string) *Config
- func (c *Config) SetServerPort(port int) *Config
- func (c *Config) SetStaticDir(dir string) *Config
- func (c *Config) ShouldIgnoreFile(path string) bool
- func (c *Config) String() string
- type DebugConfig
- type DebugLogger
- func (l *DebugLogger) AddRoute(route RouteInfo)
- func (l *DebugLogger) Close() error
- func (l *DebugLogger) Debug(v ...interface{})
- func (l *DebugLogger) Debugf(format string, v ...interface{})
- func (l *DebugLogger) DumpDebugInfo(w io.Writer) error
- func (l *DebugLogger) Error(v ...interface{})
- func (l *DebugLogger) Errorf(format string, v ...interface{})
- func (l *DebugLogger) Fatal(v ...interface{})
- func (l *DebugLogger) Fatalf(format string, v ...interface{})
- func (l *DebugLogger) GetHTTPRequests() []HTTPInfo
- func (l *DebugLogger) GetRoutes() []RouteInfo
- func (l *DebugLogger) GetSQLQueries() []SQLInfo
- func (l *DebugLogger) Info(v ...interface{})
- func (l *DebugLogger) Infof(format string, v ...interface{})
- func (l *DebugLogger) LogHTTPRequest(id, method, path string, headers http.Header, body []byte, ip string)
- func (l *DebugLogger) LogHTTPResponse(id string, statusCode int, headers http.Header, body []byte)
- func (l *DebugLogger) LogSQL(query string, args []interface{}, duration time.Duration, err error)
- func (l *DebugLogger) SetColor(enabled bool) *DebugLogger
- func (l *DebugLogger) SetLevel(level LogLevel) *DebugLogger
- func (l *DebugLogger) SetLogFile(filePath string) error
- func (l *DebugLogger) SetOutput(w io.Writer) *DebugLogger
- func (l *DebugLogger) SetPrefix(prefix string) *DebugLogger
- func (l *DebugLogger) Warn(v ...interface{})
- func (l *DebugLogger) Warnf(format string, v ...interface{})
- type DevServer
- type FileChange
- type HTTPInfo
- type HTTPLog
- type HotReloader
- func (r *HotReloader) AddFileExtension(ext ...string) *HotReloader
- func (r *HotReloader) AddFileMatcher(matcher func(string) bool) *HotReloader
- func (r *HotReloader) ForceReload()
- func (r *HotReloader) GetChangesChannel() <-chan FileChange
- func (r *HotReloader) GetReloadChannel() <-chan struct{}
- func (r *HotReloader) GetStats() WatchStats
- func (r *HotReloader) IsRunning() bool
- func (r *HotReloader) OnReload(callback func()) *HotReloader
- func (r *HotReloader) Start() error
- func (r *HotReloader) Stop() error
- type LogLevel
- type MiddlewareFunc
- type ReloadConfig
- type RouteInfo
- type RouteLog
- type SQLInfo
- type SQLLog
- type ServerConfig
- type ServerStatus
- type WatchStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// 应用根目录
RootDir string
// 热重载配置
Reload ReloadConfig
// 调试配置
Debug DebugConfig
// 开发服务器配置
Server ServerConfig
// 环境变量
Env map[string]string
// 自定义设置
Settings map[string]interface{}
}
Config 开发环境配置
func (*Config) AddSetting ¶
AddSetting 添加自定义设置
func (*Config) EnableConsole ¶
EnableConsole 启用调试控制台
func (*Config) EnableHotReload ¶
EnableHotReload 启用热重载
func (*Config) EnableOpenBrowser ¶
EnableOpenBrowser 启用自动打开浏览器
func (*Config) EnableProfiler ¶
EnableProfiler 启用性能分析
func (*Config) EnableShowHTTP ¶
EnableShowHTTP 启用显示HTTP请求和响应
func (*Config) EnableShowRoutes ¶
EnableShowRoutes 启用显示路由信息
func (*Config) EnableShowSQL ¶
EnableShowSQL 启用显示SQL查询
func (*Config) EnableVerboseLogging ¶
EnableVerboseLogging 启用详细日志
func (*Config) EnableWebSocket ¶
EnableWebSocket 启用WebSocket
func (*Config) GetWatchDirsAbsolute ¶
GetWatchDirsAbsolute 获取绝对路径的监视目录列表
func (*Config) SetConsolePort ¶
SetConsolePort 设置控制台端口
func (*Config) SetIgnorePatterns ¶
SetIgnorePatterns 设置忽略的文件模式
func (*Config) SetProfilerPort ¶
SetProfilerPort 设置性能分析端口
func (*Config) SetReloadCallback ¶
SetReloadCallback 设置重载回调
func (*Config) SetReloadDelay ¶
SetReloadDelay 设置重载延迟时间
func (*Config) SetServerHost ¶
SetServerHost 设置服务器地址
func (*Config) SetServerPort ¶
SetServerPort 设置服务器端口
func (*Config) SetStaticDir ¶
SetStaticDir 设置静态文件目录
func (*Config) ShouldIgnoreFile ¶
ShouldIgnoreFile 检查是否应该忽略文件
type DebugConfig ¶
type DebugConfig struct {
// 是否启用详细日志
VerboseLogging bool
// 是否显示路由信息
ShowRoutes bool
// 是否显示SQL查询
ShowSQL bool
// 是否显示HTTP请求和响应
ShowHTTP bool
// 是否启用性能分析
EnableProfiler bool
// 性能分析端口
ProfilerPort int
// 是否启用调试控制台
EnableConsole bool
// 控制台端口
ConsolePort int
}
DebugConfig 调试配置
type DebugLogger ¶
type DebugLogger struct {
// contains filtered or unexported fields
}
DebugLogger 调试日志记录器
func (*DebugLogger) Debugf ¶
func (l *DebugLogger) Debugf(format string, v ...interface{})
Debugf 记录调试级别日志(格式化)
func (*DebugLogger) DumpDebugInfo ¶
func (l *DebugLogger) DumpDebugInfo(w io.Writer) error
DumpDebugInfo 导出调试信息
func (*DebugLogger) Errorf ¶
func (l *DebugLogger) Errorf(format string, v ...interface{})
Errorf 记录错误级别日志(格式化)
func (*DebugLogger) Fatalf ¶
func (l *DebugLogger) Fatalf(format string, v ...interface{})
Fatalf 记录致命级别日志并退出(格式化)
func (*DebugLogger) GetHTTPRequests ¶
func (l *DebugLogger) GetHTTPRequests() []HTTPInfo
GetHTTPRequests 获取HTTP请求记录
func (*DebugLogger) GetSQLQueries ¶
func (l *DebugLogger) GetSQLQueries() []SQLInfo
GetSQLQueries 获取SQL查询记录
func (*DebugLogger) Infof ¶
func (l *DebugLogger) Infof(format string, v ...interface{})
Infof 记录信息级别日志(格式化)
func (*DebugLogger) LogHTTPRequest ¶
func (l *DebugLogger) LogHTTPRequest(id, method, path string, headers http.Header, body []byte, ip string)
LogHTTPRequest 记录HTTP请求
func (*DebugLogger) LogHTTPResponse ¶
LogHTTPResponse 记录HTTP响应
func (*DebugLogger) LogSQL ¶
func (l *DebugLogger) LogSQL(query string, args []interface{}, duration time.Duration, err error)
LogSQL 记录SQL查询
func (*DebugLogger) SetColor ¶
func (l *DebugLogger) SetColor(enabled bool) *DebugLogger
SetColor 设置是否启用控制台颜色
func (*DebugLogger) SetLevel ¶
func (l *DebugLogger) SetLevel(level LogLevel) *DebugLogger
SetLevel 设置日志级别
func (*DebugLogger) SetLogFile ¶
func (l *DebugLogger) SetLogFile(filePath string) error
SetLogFile 设置日志文件
func (*DebugLogger) SetOutput ¶
func (l *DebugLogger) SetOutput(w io.Writer) *DebugLogger
SetOutput 设置日志输出
func (*DebugLogger) SetPrefix ¶
func (l *DebugLogger) SetPrefix(prefix string) *DebugLogger
SetPrefix 设置日志前缀
func (*DebugLogger) Warnf ¶
func (l *DebugLogger) Warnf(format string, v ...interface{})
Warnf 记录警告级别日志(格式化)
type DevServer ¶
type DevServer struct {
// contains filtered or unexported fields
}
DevServer 开发服务器
type FileChange ¶
FileChange 文件变更信息
type HTTPInfo ¶
type HTTPInfo struct {
// 请求ID
ID string
// 请求方法
Method string
// 请求路径
Path string
// 请求头
Headers http.Header
// 请求体
Body []byte
// 状态码
StatusCode int
// 响应头
ResponseHeaders http.Header
// 响应体
ResponseBody []byte
// 开始时间
StartTime time.Time
// 结束时间
EndTime time.Time
// 持续时间
Duration time.Duration
// IP地址
IP string
}
HTTPInfo HTTP信息
type HTTPLog ¶
type HTTPLog struct {
// 请求记录
Requests []HTTPInfo
// contains filtered or unexported fields
}
HTTPLog HTTP日志
type HotReloader ¶
type HotReloader struct {
// contains filtered or unexported fields
}
HotReloader 热重载器
func NewHotReloader ¶
func NewHotReloader(config *Config) (*HotReloader, error)
NewHotReloader 创建热重载器
func (*HotReloader) AddFileExtension ¶
func (r *HotReloader) AddFileExtension(ext ...string) *HotReloader
AddFileExtension 添加监听的文件类型
func (*HotReloader) AddFileMatcher ¶
func (r *HotReloader) AddFileMatcher(matcher func(string) bool) *HotReloader
AddFileMatcher 添加文件匹配器
func (*HotReloader) GetChangesChannel ¶
func (r *HotReloader) GetChangesChannel() <-chan FileChange
GetChangesChannel 获取变更通道
func (*HotReloader) GetReloadChannel ¶
func (r *HotReloader) GetReloadChannel() <-chan struct{}
GetReloadChannel 获取重载通道
func (*HotReloader) OnReload ¶
func (r *HotReloader) OnReload(callback func()) *HotReloader
OnReload 设置重载回调
type ReloadConfig ¶
type ReloadConfig struct {
// 是否启用热重载
Enabled bool
// 监视的目录列表
WatchDirs []string
// 忽略的文件模式
IgnorePatterns []string
// 重载延迟时间(毫秒)
DelayMilliseconds int
// 重载回调
OnReload func()
// 最大触发频率(秒)
MaxFrequency int
}
ReloadConfig 热重载配置
type RouteInfo ¶
type RouteInfo struct {
// 方法
Method string
// 路径
Path string
// 处理器
Handler string
// 中间件
Middlewares []string
// 分组
Group string
}
RouteInfo 路由信息
type RouteLog ¶
type RouteLog struct {
// 路由列表
Routes []RouteInfo
// contains filtered or unexported fields
}
RouteLog 路由日志
type SQLInfo ¶
type SQLInfo struct {
// 查询语句
Query string
// 参数
Args []interface{}
// 执行时间
Duration time.Duration
// 发生时间
Time time.Time
// 调用栈
Stack string
// 发生错误
Error error
}
SQLInfo SQL信息
type SQLLog ¶
type SQLLog struct {
// SQL查询列表
Queries []SQLInfo
// contains filtered or unexported fields
}
SQLLog SQL日志
type ServerConfig ¶
type ServerConfig struct {
// 服务器地址
Host string
// 服务器端口
Port int
// 是否启用HTTPS
EnableHTTPS bool
// 是否启用自动打开浏览器
OpenBrowser bool
// 静态文件目录
StaticDir string
// 代理设置
Proxies map[string]string
// 自定义中间件
Middlewares []interface{}
// 是否启用WebSocket
EnableWebSocket bool
// 是否启用跨域
EnableCORS bool
// 自定义响应头
Headers map[string]string
}
ServerConfig 开发服务器配置
type ServerStatus ¶
type ServerStatus struct {
// 运行时间
Uptime time.Duration
// 请求数
RequestCount int
// 活跃请求数
ActiveRequests int
// 错误数
ErrorCount int
}
ServerStatus 服务器状态
type WatchStats ¶
type WatchStats struct {
// 监视的目录数量
DirCount int
// 最近的变更
RecentChanges []FileChange
// 最后重载时间
LastReload time.Time
}
WatchStats 监视器统计