Documentation ¶
Index ¶
- func AnyToStr(s any) string
- func CheckConvInt(value any) (any, error)
- func CheckConvMap(value any) (any, error)
- func CheckConvStr(value any) (any, error)
- func CreateSlogLogger(app *App, name string, withConsole bool) *slog.Logger
- func DecomposeFsid(fsid string) (Fstype, fssubid string)
- func HandleFailRetMiddleware(c *gin.Context)
- func LooseCalcFolderSize(folder string) int64
- func VueHandler(f http.FileSystem) gin.HandlerFunc
- type App
- func (a *App) AddExt(ext IExtension)
- func (a *App) GetExt(extid string) IExtension
- func (a *App) GetExtids() []string
- func (a *App) GetLogger(name string) *slog.Logger
- func (a *App) InjectToCtxMiddleware() gin.HandlerFunc
- func (a *App) RegFileSpace(filespace IFileSpace) error
- func (a *App) StartInit()
- type AuthResId
- type AuthResItem
- type AuthResMgr
- func (m *AuthResMgr) FilterDict(authDict map[AuthResId]bool) map[AuthResId]bool
- func (m *AuthResMgr) GetItem(resid AuthResId) *AuthResItem
- func (m *AuthResMgr) HasRes(resid AuthResId) bool
- func (m *AuthResMgr) PackAllAuthInfo() gin.H
- func (m *AuthResMgr) PackClientDict(ua IUserAuth) gin.H
- func (m *AuthResMgr) PrintAllAuthInfo()
- func (m *AuthResMgr) RegAuthItem(item AuthResItem) error
- type BaseFileSpace
- func (fsp *BaseFileSpace) Ensure(ch *ContextHelper, mode string)
- func (fsp *BaseFileSpace) GetAddr(self IFileSpace, ch *ContextHelper, fssubid string, fspath string) string
- func (fsp *BaseFileSpace) GetFstype() string
- func (fsp *BaseFileSpace) GetRelExt() IExtension
- func (fsp *BaseFileSpace) ModeRes(mode string) AuthResId
- func (fsp *BaseFileSpace) NewFsDriver(ch *ContextHelper, fssubid string) IFsDriver
- func (fsp *BaseFileSpace) NewFsDriverByAddr(fsaddr string) IFsDriver
- func (fsp *BaseFileSpace) RegAuth(folderDesc string, sendClient bool)
- func (fsp *BaseFileSpace) SetRelExt(ext IExtension)
- type BaseFsDriver
- func (*BaseFsDriver) CalcDirSize(self IFsDriver, fspath string) (int64, error)
- func (*BaseFsDriver) CopyAll(self IFsDriver, fspath string, toFspath string) error
- func (fsh *BaseFsDriver) GetRoot() string
- func (*BaseFsDriver) ListDir(self IFsDriver, fspath string, needDirSize bool) ([]fs.FileInfo, error)
- func (*BaseFsDriver) MkdirAll(self IFsDriver, fspath string) error
- func (*BaseFsDriver) MoveAll(self IFsDriver, fspath string, toFspath string) error
- func (fsh *BaseFsDriver) MustAbs(relpath string) string
- func (fsh *BaseFsDriver) MustRel(fullpath string) string
- func (*BaseFsDriver) ReadFile(self IFsDriver, fspath string) ([]byte, error)
- func (*BaseFsDriver) RemoveAll(self IFsDriver, fspath string) error
- func (*BaseFsDriver) Stat(self IFsDriver, fspath string, needDirSize bool) (fs.FileInfo, error)
- func (*BaseFsDriver) WebDownload(self IFsDriver, ch *ContextHelper, fspath string)
- func (*BaseFsDriver) WebSaveUploadedFile(self IFsDriver, ch *ContextHelper, file *multipart.FileHeader, fspath string) error
- func (*BaseFsDriver) WebView(self IFsDriver, ch *ContextHelper, fspath string)
- func (*BaseFsDriver) WriteFile(self IFsDriver, fspath string, data []byte) error
- type ConfItem
- type ConfigManager
- func (m *ConfigManager) Get(k string) any
- func (m *ConfigManager) IsConfKey(k string) bool
- func (m *ConfigManager) PackClientDict() gin.H
- func (m *ConfigManager) PrintConfigs()
- func (m *ConfigManager) RegConfItem(item ConfItem) error
- func (m *ConfigManager) UpdateFromEnv()
- func (m *ConfigManager) UpdateFromMap(obj map[string]any)
- func (m *ConfigManager) UpdateValue(k string, v any) error
- type ContextHelper
- func (ch *ContextHelper) BindJSON(obj any)
- func (ch *ContextHelper) ClientUrl(suburl string) string
- func (ch *ContextHelper) Ensure(resid AuthResId)
- func (ch *ContextHelper) EnsureNoErr(err error)
- func (ch *ContextHelper) FailResp(format string, a ...any)
- func (ch *ContextHelper) FailRespWithStatus(status int, format string, a ...any)
- func (ch *ContextHelper) GetApp() *App
- func (ch *ContextHelper) GetFixSession() sessions.Session
- func (ch *ContextHelper) GetRelExt() IExtension
- func (ch *ContextHelper) GetSession() sessions.Session
- func (ch *ContextHelper) GetSessionId() string
- func (ch *ContextHelper) GetUserAuth() IUserAuth
- func (ch *ContextHelper) Jump(message, jumpurl string, cd int, flag bool)
- func (ch *ContextHelper) Logger() *slog.Logger
- func (ch *ContextHelper) MustBind(obj any)
- func (ch *ContextHelper) OpenFs(fsid string, mode string) IFsDriver
- func (ch *ContextHelper) Redirect(location string)
- func (ch *ContextHelper) SetFailStatus(status int)
- func (ch *ContextHelper) SucResp(ret any)
- func (ch *ContextHelper) UsLog(msg string, args ...any)
- type Extension
- func (r *Extension) ClientUrl(suburl string) string
- func (r *Extension) GET(relativePath string, handlers ...HandlerFunc) gin.IRoutes
- func (r *Extension) GetApp() *App
- func (r *Extension) GetId() string
- func (r *Extension) GetLogger(name string) *slog.Logger
- func (r *Extension) GetRouter() *gin.RouterGroup
- func (r *Extension) GetUserAuth(ch *ContextHelper) IUserAuth
- func (r *Extension) Logger() *slog.Logger
- func (r *Extension) OnBind()
- func (r *Extension) OnInit()
- func (r *Extension) POST(relativePath string, handlers ...HandlerFunc) gin.IRoutes
- func (r *Extension) RegAuth(resid AuthResId, desc string, sendClient bool) error
- func (r *Extension) RegConf(item ConfItem) error
- func (r *Extension) RegFileSpace(filespace IFileSpace)
- func (r *Extension) RegIntConf(key string, defv any, desc string, sendClient bool) error
- func (r *Extension) RegMapConf(key string, defv any, desc string, sendClient bool) error
- func (r *Extension) RegStrConf(key string, defv any, desc string, sendClient bool) error
- func (r *Extension) Res(resource string) AuthResId
- func (r *Extension) ServerUrl(suburl string) string
- type FailRet
- type H
- type HandlerFunc
- type IDiskFsDriver
- type IExtension
- type IFailRet
- type IFileSpace
- type IFsDriver
- type IUserAuth
- type MyRSA
- func (mr *MyRSA) Decrypt(ciphertext string) (string, error)
- func (mr *MyRSA) DumpPrivateKeyBase64() (string, error)
- func (mr *MyRSA) DumpPublicKeyBase64() (string, error)
- func (mr *MyRSA) Encrypt(plaintext string) (string, error)
- func (mr *MyRSA) GenerateKey() error
- func (mr *MyRSA) LoadPrivateKeyBase64(base64key string) error
- func (mr *MyRSA) LoadPublicKeyBase64(base64key string) error
- type PrimaryStringModel
- type PrimaryUintModel
- type SimpleFileSpace
- type SingleFileFsDriver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckConvInt ¶
func CheckConvMap ¶
func CheckConvStr ¶
func DecomposeFsid ¶
func HandleFailRetMiddleware ¶
func LooseCalcFolderSize ¶
func VueHandler ¶
func VueHandler(f http.FileSystem) gin.HandlerFunc
Types ¶
type App ¶
type App struct { ConfMgr *ConfigManager AuthMgr *AuthResMgr Db *gorm.DB WorkSpace IDiskFsDriver FileSpaces map[string]IFileSpace // contains filtered or unexported fields }
func NewApp ¶
func NewApp(r *gin.RouterGroup) *App
func (*App) GetExt ¶
func (a *App) GetExt(extid string) IExtension
func (*App) InjectToCtxMiddleware ¶
func (a *App) InjectToCtxMiddleware() gin.HandlerFunc
a middleware for inject cur app to gin context
type AuthResItem ¶
type AuthResItem struct { // 资源id,统一格式为"extid/resouce[@w][:action]", // 中括号里面是可选的,带有@w表示是白名单权限,默认值为true ResId AuthResId Desc string SendClient bool // indicate who register it ExtId string // default的值其实是看资源里面是否带有@w,这里是缓存起来避免再次计算 Default bool }
AuthResItem need to be declare before use. We assume that all config value are jsonable, because sometime we need to send to client!
type AuthResMgr ¶
type AuthResMgr struct {
// contains filtered or unexported fields
}
全局的 权限资源 管理器,只管资源的注册,不管权限认证
func NewAuthResMgr ¶
func NewAuthResMgr() *AuthResMgr
func (*AuthResMgr) FilterDict ¶
func (m *AuthResMgr) FilterDict(authDict map[AuthResId]bool) map[AuthResId]bool
func (*AuthResMgr) GetItem ¶
func (m *AuthResMgr) GetItem(resid AuthResId) *AuthResItem
func (*AuthResMgr) HasRes ¶
func (m *AuthResMgr) HasRes(resid AuthResId) bool
func (*AuthResMgr) PackAllAuthInfo ¶
func (m *AuthResMgr) PackAllAuthInfo() gin.H
func (*AuthResMgr) PackClientDict ¶
func (m *AuthResMgr) PackClientDict(ua IUserAuth) gin.H
func (*AuthResMgr) PrintAllAuthInfo ¶
func (m *AuthResMgr) PrintAllAuthInfo()
func (*AuthResMgr) RegAuthItem ¶
func (m *AuthResMgr) RegAuthItem(item AuthResItem) error
type BaseFileSpace ¶
type BaseFileSpace struct { Fstype string ResId AuthResId Ext IExtension // contains filtered or unexported fields }
func NewBaseFileSpace ¶
func NewBaseFileSpace(fstype, rootPath string, resid AuthResId) *BaseFileSpace
func (*BaseFileSpace) Ensure ¶
func (fsp *BaseFileSpace) Ensure(ch *ContextHelper, mode string)
func (*BaseFileSpace) GetAddr ¶
func (fsp *BaseFileSpace) GetAddr(self IFileSpace, ch *ContextHelper, fssubid string, fspath string) string
func (*BaseFileSpace) GetFstype ¶
func (fsp *BaseFileSpace) GetFstype() string
func (*BaseFileSpace) GetRelExt ¶
func (fsp *BaseFileSpace) GetRelExt() IExtension
func (*BaseFileSpace) ModeRes ¶
func (fsp *BaseFileSpace) ModeRes(mode string) AuthResId
func (*BaseFileSpace) NewFsDriver ¶
func (fsp *BaseFileSpace) NewFsDriver(ch *ContextHelper, fssubid string) IFsDriver
func (*BaseFileSpace) NewFsDriverByAddr ¶
func (fsp *BaseFileSpace) NewFsDriverByAddr(fsaddr string) IFsDriver
func (*BaseFileSpace) RegAuth ¶
func (fsp *BaseFileSpace) RegAuth(folderDesc string, sendClient bool)
func (*BaseFileSpace) SetRelExt ¶
func (fsp *BaseFileSpace) SetRelExt(ext IExtension)
type BaseFsDriver ¶
type BaseFsDriver struct {
// contains filtered or unexported fields
}
func NewBaseFsDriver ¶
func NewBaseFsDriver(rootPath string, checkExist bool) *BaseFsDriver
func (*BaseFsDriver) CalcDirSize ¶
func (*BaseFsDriver) CalcDirSize(self IFsDriver, fspath string) (int64, error)
func (*BaseFsDriver) CopyAll ¶
func (*BaseFsDriver) CopyAll(self IFsDriver, fspath string, toFspath string) error
func (*BaseFsDriver) GetRoot ¶
func (fsh *BaseFsDriver) GetRoot() string
func (*BaseFsDriver) ListDir ¶
func (*BaseFsDriver) ListDir(self IFsDriver, fspath string, needDirSize bool) ([]fs.FileInfo, error)
读取文件夹内容
func (*BaseFsDriver) MoveAll ¶
func (*BaseFsDriver) MoveAll(self IFsDriver, fspath string, toFspath string) error
func (*BaseFsDriver) MustAbs ¶
func (fsh *BaseFsDriver) MustAbs(relpath string) string
根据相对于 workspace 的相对路径,获得对应的绝对路径
func (*BaseFsDriver) MustRel ¶
func (fsh *BaseFsDriver) MustRel(fullpath string) string
根据相对于 workspace 的相对路径,获得对应的绝对路径
func (*BaseFsDriver) ReadFile ¶
func (*BaseFsDriver) ReadFile(self IFsDriver, fspath string) ([]byte, error)
func (*BaseFsDriver) RemoveAll ¶
func (*BaseFsDriver) RemoveAll(self IFsDriver, fspath string) error
func (*BaseFsDriver) WebDownload ¶
func (*BaseFsDriver) WebDownload(self IFsDriver, ch *ContextHelper, fspath string)
func (*BaseFsDriver) WebSaveUploadedFile ¶
func (*BaseFsDriver) WebSaveUploadedFile(self IFsDriver, ch *ContextHelper, file *multipart.FileHeader, fspath string) error
func (*BaseFsDriver) WebView ¶
func (*BaseFsDriver) WebView(self IFsDriver, ch *ContextHelper, fspath string)
type ConfItem ¶
type ConfItem struct { Key string Default any Desc string SendClient bool // indicate who register it ExtId string // validate input value and convert to the right value. CheckConv func(any) (any, error) }
Config Item need to be declare before use. We assume that all config value are jsonable, because sometime we need to send to client!
type ConfigManager ¶
type ConfigManager struct {
// contains filtered or unexported fields
}
func NewConfigManager ¶
func NewConfigManager() *ConfigManager
func (*ConfigManager) Get ¶
func (m *ConfigManager) Get(k string) any
func (*ConfigManager) IsConfKey ¶
func (m *ConfigManager) IsConfKey(k string) bool
func (*ConfigManager) PackClientDict ¶
func (m *ConfigManager) PackClientDict() gin.H
func (*ConfigManager) PrintConfigs ¶
func (m *ConfigManager) PrintConfigs()
func (*ConfigManager) RegConfItem ¶
func (m *ConfigManager) RegConfItem(item ConfItem) error
func (*ConfigManager) UpdateFromEnv ¶
func (m *ConfigManager) UpdateFromEnv()
func (*ConfigManager) UpdateFromMap ¶
func (m *ConfigManager) UpdateFromMap(obj map[string]any)
func (*ConfigManager) UpdateValue ¶
func (m *ConfigManager) UpdateValue(k string, v any) error
type ContextHelper ¶
func MakeCtxHelper ¶
func MakeCtxHelper(c *gin.Context) *ContextHelper
func (*ContextHelper) BindJSON ¶
func (ch *ContextHelper) BindJSON(obj any)
func (*ContextHelper) ClientUrl ¶
func (ch *ContextHelper) ClientUrl(suburl string) string
func (*ContextHelper) Ensure ¶
func (ch *ContextHelper) Ensure(resid AuthResId)
func (*ContextHelper) EnsureNoErr ¶
func (ch *ContextHelper) EnsureNoErr(err error)
if err happen, stop curent request and return err massage to client
func (*ContextHelper) FailResp ¶
func (ch *ContextHelper) FailResp(format string, a ...any)
func (*ContextHelper) FailRespWithStatus ¶
func (ch *ContextHelper) FailRespWithStatus(status int, format string, a ...any)
func (*ContextHelper) GetApp ¶
func (ch *ContextHelper) GetApp() *App
func (*ContextHelper) GetFixSession ¶
func (ch *ContextHelper) GetFixSession() sessions.Session
func (*ContextHelper) GetRelExt ¶
func (ch *ContextHelper) GetRelExt() IExtension
func (*ContextHelper) GetSession ¶
func (ch *ContextHelper) GetSession() sessions.Session
func (*ContextHelper) GetSessionId ¶
func (ch *ContextHelper) GetSessionId() string
func (*ContextHelper) GetUserAuth ¶
func (ch *ContextHelper) GetUserAuth() IUserAuth
func (*ContextHelper) Jump ¶
func (ch *ContextHelper) Jump(message, jumpurl string, cd int, flag bool)
func (*ContextHelper) Logger ¶
func (ch *ContextHelper) Logger() *slog.Logger
func (*ContextHelper) MustBind ¶
func (ch *ContextHelper) MustBind(obj any)
func (*ContextHelper) Redirect ¶
func (ch *ContextHelper) Redirect(location string)
func (*ContextHelper) SetFailStatus ¶
func (ch *ContextHelper) SetFailStatus(status int)
func (*ContextHelper) SucResp ¶
func (ch *ContextHelper) SucResp(ret any)
func (*ContextHelper) UsLog ¶
func (ch *ContextHelper) UsLog(msg string, args ...any)
type Extension ¶
type Extension struct { ExtId string App *App Router *gin.RouterGroup // contains filtered or unexported fields }
func NewExtension ¶
func (*Extension) GET ¶
func (r *Extension) GET(relativePath string, handlers ...HandlerFunc) gin.IRoutes
func (*Extension) GetRouter ¶
func (r *Extension) GetRouter() *gin.RouterGroup
func (*Extension) GetUserAuth ¶
func (r *Extension) GetUserAuth(ch *ContextHelper) IUserAuth
如果是开发替代默认的权限校验功能的扩展必须实现这个,用户修改 MIKNAS_AUTH_EXTS 的配置即可
func (*Extension) POST ¶
func (r *Extension) POST(relativePath string, handlers ...HandlerFunc) gin.IRoutes
func (*Extension) RegFileSpace ¶
func (r *Extension) RegFileSpace(filespace IFileSpace)
func (*Extension) RegIntConf ¶
func (*Extension) RegMapConf ¶
func (*Extension) RegStrConf ¶
type FailRet ¶
type FailRet struct {
// contains filtered or unexported fields
}
func (*FailRet) MakeRespond ¶
type HandlerFunc ¶
type HandlerFunc func(*ContextHelper)
func UseReqPool ¶
func UseReqPool(key string, cap int) HandlerFunc
type IDiskFsDriver ¶
type IExtension ¶
type IExtension interface { GetApp() *App GetId() string GetRouter() *gin.RouterGroup GetUserAuth(*ContextHelper) IUserAuth ClientUrl(string) string // 注册权限(资源名称,权限描述,是否发送给客户端) RegAuth(AuthResId, string, bool) error OnBind() OnInit() GetLogger(string) *slog.Logger Logger() *slog.Logger Res(string) AuthResId // contains filtered or unexported methods }
type IFailRet ¶
func NewFailRet ¶
type IFileSpace ¶
type IFileSpace interface { GetFstype() string GetRelExt() IExtension SetRelExt(ext IExtension) // mode can be "r" or "w" Ensure(ch *ContextHelper, mode string) NewFsDriver(ch *ContextHelper, fssubid string) IFsDriver NewFsDriverByAddr(fsaddr string) IFsDriver GetAddr(self IFileSpace, ch *ContextHelper, fssubid string, fspath string) string }
type IFsDriver ¶
type IFsDriver interface { Stat(self IFsDriver, fspath string, needDirSize bool) (fs.FileInfo, error) ListDir(self IFsDriver, fspath string, needDirSize bool) ([]fs.FileInfo, error) CalcDirSize(self IFsDriver, fspath string) (int64, error) ReadFile(self IFsDriver, fspath string) ([]byte, error) WriteFile(self IFsDriver, fspath string, data []byte) error MkdirAll(self IFsDriver, fspath string) error RemoveAll(self IFsDriver, fspath string) error MoveAll(self IFsDriver, fspath string, toFspath string) error CopyAll(self IFsDriver, fspath string, toFspath string) error // 请求相关的 WebDownload(self IFsDriver, ch *ContextHelper, fspath string) WebView(self IFsDriver, ch *ContextHelper, fspath string) WebSaveUploadedFile(self IFsDriver, ch *ContextHelper, file *multipart.FileHeader, fspath string) error }
func NewCommFsDriver ¶
func NewSingleFileFsDriver ¶
type IUserAuth ¶
type IUserAuth interface { GetUid() string MustGetUid() string CanAccess(AuthResId) bool Refresh() }
所有需要替代默认权限管理的都需要实现该接口
type MyRSA ¶
type MyRSA struct { PrivKey *rsa.PrivateKey PubKey *rsa.PublicKey }
func MustGenMyRSA ¶
func MustGenMyRSA() MyRSA
func (*MyRSA) DumpPrivateKeyBase64 ¶
Dump private key to base64 string Compared with DumpPrivateKeyBuffer this output:
- Have no header/tailer line
- Key content is merged into one-line format
The output is:
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2y8mEdCRE8siiI7udpge......2QIDAQAB
func (*MyRSA) DumpPublicKeyBase64 ¶
func (*MyRSA) LoadPrivateKeyBase64 ¶
Load private key from base64
func (*MyRSA) LoadPublicKeyBase64 ¶
type PrimaryStringModel ¶
type PrimaryUintModel ¶
type SimpleFileSpace ¶
type SimpleFileSpace struct {
BaseFileSpace
}
只需要单个权限的工作空间
func NewSimpleFileSpace ¶
func NewSimpleFileSpace(fstype, rootPath string, resid AuthResId) *SimpleFileSpace
func (*SimpleFileSpace) Ensure ¶
func (fsp *SimpleFileSpace) Ensure(ch *ContextHelper, mode string)
func (*SimpleFileSpace) RegAuth ¶
func (fsp *SimpleFileSpace) RegAuth(folderDesc string, sendClient bool)
type SingleFileFsDriver ¶
type SingleFileFsDriver struct {
BaseFsDriver
}
单文件的一个Fstype
func (*SingleFileFsDriver) ListDir ¶
func (fsd *SingleFileFsDriver) ListDir(self IFsDriver, fspath string, needDirSize bool) ([]fs.FileInfo, error)
读取文件夹内容
func (*SingleFileFsDriver) MustAbs ¶
func (fsd *SingleFileFsDriver) MustAbs(relpath string) string
func (*SingleFileFsDriver) MustRel ¶
func (fsd *SingleFileFsDriver) MustRel(fullpath string) string