-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontext_interface.go
More file actions
92 lines (78 loc) · 3.08 KB
/
Copy pathcontext_interface.go
File metadata and controls
92 lines (78 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (c) 2025 lamxy and Contributors
// SPDX-License-Identifier: MIT
//
// Author: lamxy <pytho5170@hotmail.com>
// GitHub: https://github.com/lamxy
package fiberhouse
import (
"github.com/lamxy/fiberhouse/appconfig"
"github.com/lamxy/fiberhouse/bootstrap"
"github.com/lamxy/fiberhouse/component/container"
"github.com/lamxy/fiberhouse/component/validate"
"github.com/lamxy/fiberhouse/globalmanager"
"github.com/rs/zerolog"
)
// IContext 全局上下文接口
type IContext interface {
// GetConfig 定义获取全局配置的方法
GetConfig() appconfig.IAppConfig
// GetLogger 定义获取全局日志器的方法
GetLogger() bootstrap.LoggerWrapper
// GetContainer 定义获取全局管理器的方法
GetContainer() *globalmanager.GlobalManager
// GetStarter 定义获取启动器实例的方法,用于获取IApplication实例方法
GetStarter() IStarter
// GetLoggerWithOrigin 定义获取附加来源的子日志器单例的方法(从全局管理器获取)
GetLoggerWithOrigin(originFormCfg appconfig.LogOrigin) (*zerolog.Logger, error)
// GetMustLoggerWithOrigin 定义获取附加来源的日志器实例的方法,若获取失败则panic(从全局管理器获取)
GetMustLoggerWithOrigin(originFormCfg appconfig.LogOrigin) *zerolog.Logger
// GetValidateWrap 定义获取全局验证器包装器的方法
GetValidateWrap() validate.ValidateWrapper
}
// IApplicationContext 框架Web应用上下文接口
type IApplicationContext interface {
IContext
// RegisterStarterApp 挂载框架启动器app
RegisterStarterApp(sApp ApplicationStarter)
// GetStarterApp 获取框架应用启动器实例(如WebApplication)
GetStarterApp() ApplicationStarter
// RegisterAppState 注册应用启动状态
RegisterAppState(bool)
// GetAppState 获取应用启动状态
GetAppState() bool
// GetBootConfig 获取启动配置
GetBootConfig() *BootConfig
// RegisterBootConfig 注册启动配置
RegisterBootConfig(bc *BootConfig)
}
// IApplicationContext 框架命令行应用上下文接口
type ICommandContext interface {
IContext
// GetDigContainer 获取依赖注入容器
GetDigContainer() *container.DigContainer
// RegisterStarterApp 挂载框架启动器app
RegisterStarterApp(app CommandStarter)
// GetStarterApp 获取框架启动器实例(CommandStarter)
GetStarterApp() CommandStarter
}
// IStorage 通用键值存储接口
type IStorage interface {
// Set 设置键值对,如果键已存在则覆盖
Set(key string, value interface{})
// Get 获取指定键的值,返回值和是否存在的标志
Get(key string) (value interface{}, exists bool)
// GetOrDefault 获取值,如果不存在则返回默认值
GetOrDefault(key string, defaultValue interface{}) interface{}
// Delete 删除指定键,返回是否删除成功
Delete(key string) bool
// Has 检查键是否存在
Has(key string) bool
// Clear 清空所有键值对
Clear()
// Keys 返回所有键的切片
Keys() []string
// Len 返回存储的键值对数量
Len() int
// Range 遍历所有键值对,如果回调函数返回false则停止遍历
Range(f func(key string, value interface{}) bool)
}