core

package
v0.0.0-...-118bb3a Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(c *fiber.Ctx) error

func AuthMiddleware2

func AuthMiddleware2(db *gorm.DB, JWTSecret string) fiber.Handler

AuthMiddleware 认证中间件

func AwakeModules

func AwakeModules(app *App)

AwakeModules 模块初始化

func DestroySession

func DestroySession(c *fiber.Ctx) error

DestroySession 销毁用户认证信息

func GetSession

func GetSession(c *fiber.Ctx) (bool, uint)

GetSession 获取用户认证信息

func HasPermission

func HasPermission(permissionCode string, userFunc func(c *fiber.Ctx) *models.User) fiber.Handler

HasPermission 权限检查中间件

func InitAuthRouters

func InitAuthRouters()

InitAuthRouters 初始化管理员路由

func InitPublicRouters

func InitPublicRouters()

InitPublicRouters 初始化公共路由

func IsDevelopment

func IsDevelopment() bool

IsDevelopment 返回是否为开发环境

func IsSecureMode

func IsSecureMode() bool

IsSecureMode 返回是否为安全模式

func LoadConfig

func LoadConfig() error

func RegisterModule

func RegisterModule(module Module, priority int)

RegisterModule 注册模块

func SessionSetup

func SessionSetup(dbDriver string, db *sql.DB, dsn, tableName string)

SessionSetup 初始化session存储

func SetSessionExpiration

func SetSessionExpiration(c *fiber.Ctx, duration time.Duration) error

SetSessionExpiration 设置session过期时间

func SkipAuthRoute

func SkipAuthRoute(path string)

SkipAuthRoute 添加不需要认证的路由

func StoreSession

func StoreSession(c *fiber.Ctx, userID uint) error

StoreSession 存储用户认证信息

func UpdateDatabaseConfig

func UpdateDatabaseConfig(newConfig DatabaseConfig)

func UpdateFTPConfig

func UpdateFTPConfig(newConfig FTPConfig)

func UpdateServerConfig

func UpdateServerConfig(newConfig ServerConfig)

Types

type App

type App struct {
	FiberApp        *fiber.App
	DB              *gorm.DB
	DBs             []*gorm.DB
	Config          *Config
	RouterPublic    fiber.Router
	RouterPublicApi fiber.Router
	RouterApi       fiber.Router
	RouterAdmin     fiber.Router
}

func NewApp

func NewApp() *App

func (*App) CurrentUser

func (a *App) CurrentUser(c *fiber.Ctx) *models.User

Current 获取当前用户

func (*App) HasPermission

func (a *App) HasPermission(permissionCode string) fiber.Handler

func (*App) IsInitializedModule

func (a *App) IsInitializedModule(module string) bool

如果模块已初始化,则跳过

func (*App) Start

func (a *App) Start(dbs []*gorm.DB, fiberApp *fiber.App)

type AppConfig

type AppConfig struct {
	IsDev    bool `toml:"is_dev"`    // 是否为开发环境
	IsSecure bool `toml:"is_secure"` // 是否启用安全模式
}

type AuthConfig

type AuthConfig struct {
	JWTSecret   string `toml:"jwt_secret"`
	TokenExpire int    `toml:"token_expire"`
}

type BaseModule

type BaseModule struct {
	App *App
}

func (*BaseModule) AddAuthRouters

func (m *BaseModule) AddAuthRouters() error

func (*BaseModule) AddPublicRouters

func (m *BaseModule) AddPublicRouters() error

func (*BaseModule) Awake

func (m *BaseModule) Awake(a *App) error

func (*BaseModule) Start

func (m *BaseModule) Start() error

type Config

type Config struct {
	App       AppConfig      `toml:"app"`
	Server    ServerConfig   `toml:"server"`
	Database  DatabaseConfig `toml:"database"`
	JSONPaths JSONPathConfig `toml:"json_paths"`
	FTP       FTPConfig      `toml:"ftp"`
	Auth      AuthConfig     `toml:"auth"`
}

func GetConfig

func GetConfig() Config

type DatabaseConfig

type DatabaseConfig struct {
	Driver          string `toml:"driver"`
	DSN             string `toml:"dsn"`
	MaxOpenConns    int    `toml:"max_open_conns"`
	MaxIdleConns    int    `toml:"max_idle_conns"`
	ConnMaxLifetime int64  `toml:"conn_max_lifetime"`
}

func GetDatabaseConfig

func GetDatabaseConfig() DatabaseConfig

type FTPConfig

type FTPConfig struct {
	Host       string `toml:"host"`
	Port       string `toml:"port"`
	User       string `toml:"user"`
	Password   string `toml:"password"`
	APKPath    string `toml:"apk_path"`
	ZIPPath    string `toml:"zip_path"`
	LogDir     string `toml:"log_dir"`
	MaxLogSize int64  `toml:"max_log_size"`
}

func GetFTPConfig

func GetFTPConfig() FTPConfig

type FiberSession

type FiberSession struct {
	K string `gorm:"column:k;primaryKey"` // key
	V string `gorm:"column:v;not null"`   // value
	E int64  `gorm:"column:e;default:0"`  // expiry
}

FiberSession Fiber默认的会话表结构

func (FiberSession) TableName

func (FiberSession) TableName() string

TableName 设置表名

type JSONPathConfig

type JSONPathConfig struct {
	ServerList string `toml:"server_list"`
	LastServer string `toml:"last_server"`
	ServerInfo string `toml:"server_info"`
	NoticeList string `toml:"notice_list"`
	NoticeNum  string `toml:"notice_num"`
}

func GetJSONPathConfig

func GetJSONPathConfig() JSONPathConfig

type Module

type Module interface {
	Awake(*App) error
	Start() error
	AddPublicRouters() error
	AddAuthRouters() error
}

type SQLiteStorage

type SQLiteStorage struct {
	// contains filtered or unexported fields
}

SQLiteStorage 实现 fiber.Storage 接口

func NewSQLiteStorage

func NewSQLiteStorage(dsn string) (*SQLiteStorage, error)

NewSQLiteStorage 创建新的SQLite存储

func (*SQLiteStorage) Close

func (s *SQLiteStorage) Close() error

Close 关闭存储

func (*SQLiteStorage) Delete

func (s *SQLiteStorage) Delete(key string) error

Delete 删除会话数据

func (*SQLiteStorage) Get

func (s *SQLiteStorage) Get(key string) ([]byte, error)

Get 获取会话数据

func (*SQLiteStorage) Reset

func (s *SQLiteStorage) Reset() error

Reset 重置存储

func (*SQLiteStorage) Set

func (s *SQLiteStorage) Set(key string, val []byte, exp time.Duration) error

Set 设置会话数据

type ServerConfig

type ServerConfig struct {
	Host         string             `toml:"host"`
	Port         int                `toml:"port"`
	Output       string             `toml:"output"`
	ScriptPath   string             `toml:"script_path"`
	StaticPaths  []StaticPathConfig `toml:"static_paths"`
	UserDataPath string             `toml:"user_data_path"`
	CDNPath      string             `toml:"cdn_path"`
	CDN2Path     string             `toml:"cdn2_path"`
}

func GetServerConfig

func GetServerConfig() ServerConfig

type StaticPathConfig

type StaticPathConfig struct {
	Route string `toml:"route"`
	Path  string `toml:"path"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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