Documentation
¶
Index ¶
- func MustUser(c fiber.Ctx) auth.ContextUser
- type APIError
- type AdminCreateUserRequest
- type AdminResetPasswordRequest
- type AdminTokenItem
- type AdminUserItem
- type AuditLogItem
- type AuditLogPage
- type ChangePasswordRequest
- type CreateAPITokenRequest
- type CreateAPITokenResponse
- type CreateMyTokenRequest
- type CreatePointRequest
- type CreateSettingRequest
- type LoginWebRequest
- type LoginWebResponse
- type Server
- func (s *Server) AdminCreateUser(c fiber.Ctx) error
- func (s *Server) AdminDeleteUser(c fiber.Ctx) error
- func (s *Server) AdminKickSession(c fiber.Ctx) error
- func (s *Server) AdminListAuditLogs(c fiber.Ctx) error
- func (s *Server) AdminListSessions(c fiber.Ctx) error
- func (s *Server) AdminListTokens(c fiber.Ctx) error
- func (s *Server) AdminListUsers(c fiber.Ctx) error
- func (s *Server) AdminResetUserPassword(c fiber.Ctx) error
- func (s *Server) AdminRevokeToken(c fiber.Ctx) error
- func (s *Server) ChangeMyPassword(c fiber.Ctx) error
- func (s *Server) CreateAPITokenByPassword(c fiber.Ctx) error
- func (s *Server) CreateMyAPIToken(c fiber.Ctx) error
- func (h *Server) CreatePoint(c fiber.Ctx) error
- func (h *Server) CreateSetting(c fiber.Ctx) error
- func (h *Server) DeleteSettingByID(c fiber.Ctx) error
- func (h *Server) GetSettingByID(c fiber.Ctx) error
- func (h *Server) GetSettingByName(c fiber.Ctx) error
- func (s *Server) KickMySession(c fiber.Ctx) error
- func (s *Server) ListMyAuditLogs(c fiber.Ctx) error
- func (s *Server) ListMySessions(c fiber.Ctx) error
- func (s *Server) ListMyTokens(c fiber.Ctx) error
- func (s *Server) ListOnlineChanel(c fiber.Ctx) error
- func (h *Server) ListSettings(c fiber.Ctx) error
- func (s *Server) LoginWeb(c fiber.Ctx) error
- func (s *Server) Logout(c fiber.Ctx) error
- func (s *Server) MaintenanceOverview(c fiber.Ctx) error
- func (s *Server) RevokeMyAllTokens(c fiber.Ctx) error
- func (s *Server) RevokeMyTokenByJTI(c fiber.Ctx) error
- func (s *Server) Route(app *fiber.App) *fiber.App
- func (s *Server) ShowMe(c fiber.Ctx) error
- func (s *Server) StartAuditRetentionJob(stop <-chan struct{})
- func (h *Server) UpdateSettingByID(c fiber.Ctx) error
- func (h *Server) UpsertSettingValueByName(c fiber.Ctx) error
- func (s *Server) Version(c fiber.Ctx) error
- type SessionItem
- type TokenInfo
- type UpdateSettingRequest
- type UpsertSettingByNameRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AdminCreateUserRequest ¶
type AdminCreateUserRequest struct {
Username string `json:"username"`
Password string `json:"password"`
}
AdminCreateUserRequest creates a user. AdminCreateUserRequest 创建用户请求体。
type AdminResetPasswordRequest ¶
type AdminResetPasswordRequest struct {
NewPassword string `json:"new_password"`
}
AdminResetPasswordRequest is request body for resetting password. AdminResetPasswordRequest 是重置密码请求体。
type AdminTokenItem ¶
type AdminTokenItem struct {
JTI string `json:"jti"`
UserID uint `json:"user_id"`
Username string `json:"username"`
Type models.TokenType `json:"type"`
Name string `json:"name,omitempty"`
IssuedAt time.Time `json:"issued_at"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
LastSeenAt *time.Time `json:"last_seen_at,omitempty"`
IdleTimeoutSeconds int `json:"idle_timeout_seconds"`
RevokedAt *time.Time `json:"revoked_at,omitempty"`
RevokedBy *uint `json:"revoked_by,omitempty"`
}
AdminTokenItem is token info for admin. AdminTokenItem 是管理员查看的 token 信息。
type AdminUserItem ¶
type AdminUserItem struct {
ID uint `json:"id"`
Username string `json:"username"`
IsRoot bool `json:"is_root"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
AdminUserItem is user list item. AdminUserItem 是用户列表项。
type AuditLogItem ¶
type AuditLogItem struct {
ID uint `json:"id"`
UserID uint `json:"user_id"`
Username string `json:"username"`
Action string `json:"action"`
Resource string `json:"resource"`
Method string `json:"method"`
Path string `json:"path"`
Detail string `json:"detail,omitempty"`
IP string `json:"ip,omitempty"`
UserAgent string `json:"user_agent,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
AuditLogItem is response item for audit log query. AuditLogItem 是审计日志查询的返回项。
type AuditLogPage ¶
type AuditLogPage struct {
Total int64 `json:"total"`
Page int `json:"page"`
Size int `json:"size"`
Items []AuditLogItem `json:"items"`
}
AuditLogPage is paged response. AuditLogPage 是分页响应。
type ChangePasswordRequest ¶
type ChangePasswordRequest struct {
OldPassword string `json:"old_password"`
NewPassword string `json:"new_password"`
}
ChangePasswordRequest is request body for changing password. ChangePasswordRequest 是修改密码的请求体。
type CreateAPITokenRequest ¶
type CreateAPITokenRequest struct {
Username string `json:"username"`
Password string `json:"password"`
Name string `json:"name,omitempty"`
}
CreateAPITokenRequest is request body for creating a permanent API token. CreateAPITokenRequest 是创建永久 API Token 的请求体。
type CreateAPITokenResponse ¶
type CreateAPITokenResponse struct {
Token string `json:"token"`
JTI string `json:"jti"`
Type string `json:"type"`
Name string `json:"name,omitempty"`
}
CreateAPITokenResponse is response for API token creation. CreateAPITokenResponse 是 API Token 创建响应。
type CreateMyTokenRequest ¶
type CreateMyTokenRequest struct {
Name string `json:"name,omitempty"`
}
CreateMyTokenRequest is request body for creating API token. CreateMyTokenRequest 是创建 API Token 的请求体。
type CreatePointRequest ¶
type CreatePointRequest struct {
TypeKey string `json:"type_key" example:"sampling_interval_sec"`
Model string `json:"model" example:"model"` // int|string|bool
Point []models.DeveltypePointBase `json:"Point"` // 10 / "abc" / true
}
CreateSettingRequest 创建 setting 请求 CreateSettingRequest is request body for create.
type CreateSettingRequest ¶
type CreateSettingRequest struct {
Name string `json:"name" example:"sampling_interval_sec"`
ValueType string `json:"value_type" example:"int"` // int|string|bool
Value json.RawMessage `json:"value" example:"10"` // 10 / "abc" / true
}
CreateSettingRequest 创建 setting 请求 CreateSettingRequest is request body for create.
type LoginWebRequest ¶
LoginWebRequest is request body for web login. LoginWebRequest 是 Web 登录的请求体。
type LoginWebResponse ¶
type LoginWebResponse struct {
Token string `json:"token"`
JTI string `json:"jti"`
IdleTimeoutSeconds int `json:"idle_timeout_seconds"`
Type string `json:"type"`
}
LoginWebResponse is response for web login. LoginWebResponse 是 Web 登录的响应。
type Server ¶
Server holds dependencies for HTTP handlers. Server 保存 HTTP handler 依赖项。
func (*Server) AdminCreateUser ¶
AdminCreateUser creates a new user (root only). AdminCreateUser 创建新用户(仅 root)。
@Summary Create user / 创建用户 @Description Root creates a normal user. @Description root 创建普通用户。 @Tags admin @Accept json @Produce json @Security BearerAuth @Param body body AdminCreateUserRequest true "request / 请求" @Success 200 {object} response.Envelope[AdminUserItem] @Failure 409 {object} response.Envelope[any] @Router /api/v1/admin/users [post]
func (*Server) AdminDeleteUser ¶
AdminDeleteUser deletes a user (root only), but cannot delete root. AdminDeleteUser 删除用户(仅 root),但不能删除 root。
@Summary Delete user / 删除用户 @Description Root deletes a user, but root itself is protected. @Description root 删除用户,但 root 自身受保护不可删除。 @Tags admin @Produce json @Security BearerAuth @Param id path int true "user id / 用户ID" @Success 200 {object} response.Envelope[any] @Failure 403 {object} response.Envelope[any] @Router /api/v1/admin/users/{id} [delete]
func (*Server) AdminKickSession ¶
AdminKickSession revokes any web session by jti (root only). AdminKickSession root 按 jti 撤销任意 Web 会话。
@Summary Kick a web session / 踢掉 Web 会话 @Tags admin @Produce json @Security BearerAuth @Param jti path string true "session jti / 会话标识" @Success 200 {object} response.Envelope[any] @Router /api/v1/admin/sessions/{jti} [delete]
func (*Server) AdminListAuditLogs ¶
AdminListAuditLogs lists audit logs for all users (root only). AdminListAuditLogs root 查询所有用户审计日志。
@Summary List audit logs (admin) / 查询审计日志(管理员) @Description Root can query audit logs of all users with pagination and time range filter. @Description root 用户可分页查询全部审计日志,并支持时间范围过滤。 @Tags audit @Produce json @Security BearerAuth @Param page query int false "page / 页码" default(1) @Param page_size query int false "page size / 每页数量" default(20) @Param from query string false "start time (RFC3339 or YYYY-MM-DD) / 开始时间" @Param to query string false "end time (RFC3339 or YYYY-MM-DD) / 结束时间" @Param user_id query int false "filter by user_id / 按用户ID过滤(可选)" @Success 200 {object} response.Envelope[AuditLogPage] @Router /api/v1/admin/audit/logs [get]
func (*Server) AdminListSessions ¶
AdminListSessions lists all web sessions (root only). AdminListSessions 列出所有 Web 会话(仅 root)。
@Summary List all web sessions / 列出所有 Web 会话 @Tags admin @Produce json @Security BearerAuth @Success 200 {object} response.Envelope[[]SessionItem] @Router /api/v1/admin/sessions [get]
func (*Server) AdminListTokens ¶
AdminListTokens lists all tokens (root only). AdminListTokens root 列出所有 token。
@Summary List all tokens / 列出所有 Token @Tags admin @Produce json @Security BearerAuth @Success 200 {object} response.Envelope[[]AdminTokenItem] @Router /api/v1/admin/tokens [get]
func (*Server) AdminListUsers ¶
AdminListUsers lists users (root only). AdminListUsers 列出用户(仅 root)。
@Summary List users / 列出用户 @Description Root user lists all users. @Description root 用户查看所有用户。 @Tags admin @Produce json @Security BearerAuth @Success 200 {object} response.Envelope[[]AdminUserItem] @Router /api/v1/admin/users [get]
func (*Server) AdminResetUserPassword ¶
AdminResetUserPassword resets any user's password (root only). AdminResetUserPassword root 重置任意用户密码。
@Summary Reset user password / 重置用户密码 @Tags admin @Accept json @Produce json @Security BearerAuth @Param id path int true "user id / 用户ID" @Param body body AdminResetPasswordRequest true "request / 请求" @Success 200 {object} response.Envelope[any] @Router /api/v1/admin/users/{id}/password [put]
func (*Server) AdminRevokeToken ¶
AdminRevokeToken revokes any token by jti (root only). AdminRevokeToken root 按 jti 撤销任意 token。
@Summary Revoke token / 撤销 Token @Tags admin @Produce json @Security BearerAuth @Param jti path string true "token jti / token 标识" @Success 200 {object} response.Envelope[any] @Router /api/v1/admin/tokens/{jti} [delete]
func (*Server) ChangeMyPassword ¶
ChangeMyPassword lets a normal user change their own password. ChangeMyPassword 允许普通用户自助修改自己的密码。
@Summary Change my password / 修改我的密码 @Description User changes their own password by providing old_password and new_password. @Description 用户提供旧密码与新密码,自助修改密码。 @Tags me @Accept json @Produce json @Security BearerAuth @Param body body ChangePasswordRequest true "request / 请求" @Success 200 {object} response.Envelope[any] @Failure 400 {object} response.Envelope[any] @Failure 401 {object} response.Envelope[any] @Router /api/v1/me/password [put]
func (*Server) CreateAPITokenByPassword ¶
CreateAPITokenByPassword creates a permanent API token by username+password.
@Summary Create API token by password / 通过密码创建 API Token @Description Create a permanent API token for subsequent authenticated API calls. @Description 通过用户名密码创建永久 API Token,用于后续需要鉴权的 API。 @Tags auth @Accept json @Produce json @Param body body CreateAPITokenRequest true "request / 请求" @Success 200 {object} response.Envelope[CreateAPITokenResponse] @Failure 400 {object} response.Envelope[any] @Failure 401 {object} response.Envelope[any] @Router /api/v1/auth/token [post]
func (*Server) CreateMyAPIToken ¶
CreateMyAPIToken creates permanent API token for current user. CreateMyAPIToken 为当前用户创建永久 API Token。
@Summary Create my API token / 创建我的 API Token @Description Create a permanent API token for the current user. @Description 为当前用户创建永久 API Token。 @Tags me @Accept json @Produce json @Security BearerAuth @Param body body CreateMyTokenRequest true "request / 请求" @Success 200 {object} response.Envelope[CreateAPITokenResponse] @Router /api/v1/me/tokens [post]
func (*Server) CreatePoint ¶
CreatePoint @Summary Create point @Tags Point @Accept json @Produce json @Param body body CreatePointRequest true "create point" @Success 201 {object} models.point @Failure 400 {object} APIError @Failure 409 {object} APIError @Failure 500 {object} APIError @Router /api/v1/point [post]
func (*Server) CreateSetting ¶
CreateSetting @Summary Create setting @Tags Setting @Accept json @Produce json @Param body body CreateSettingRequest true "create setting" @Success 201 {object} models.Setting @Failure 400 {object} APIError @Failure 409 {object} APIError @Failure 500 {object} APIError @Router /api/v1/settings [post]
func (*Server) DeleteSettingByID ¶
DeleteSettingByID @Summary Delete setting by id @Description Delete a setting by UUID id. @Tags Setting @Produce json @Param id path string true "setting id (uuid)" @Success 204 @Failure 404 {object} APIError @Failure 500 {object} APIError @Router /api/v1/settings/{id} [delete]
func (*Server) GetSettingByID ¶
GetSettingByID @Summary Get setting by id @Description Get a setting by UUID id. @Tags Setting @Produce json @Param id path string true "setting id (uuid)" @Success 200 {object} models.Setting @Failure 404 {object} APIError @Failure 500 {object} APIError @Router /api/v1/settings/{id} [get]
func (*Server) GetSettingByName ¶
GetSettingByName @Summary Get setting by name @Description Get a setting by unique name. @Tags Setting @Produce json @Param name path string true "setting name" @Success 200 {object} models.Setting @Failure 404 {object} APIError @Failure 500 {object} APIError @Router /api/v1/settings/by-name/{name} [get]
func (*Server) KickMySession ¶
KickMySession revokes a web session by jti. KickMySession 按 jti 踢掉指定 Web 会话。
@Summary Kick my session / 踢掉我的会话 @Tags me @Produce json @Security BearerAuth @Param jti path string true "session jti / 会话标识" @Success 200 {object} response.Envelope[any] @Failure 404 {object} response.Envelope[any] @Router /api/v1/me/sessions/{jti} [delete]
func (*Server) ListMyAuditLogs ¶
ListMyAuditLogs lists audit logs for current user. ListMyAuditLogs 列出当前用户的审计日志。
@Summary List my audit logs / 查看我的审计日志 @Description Normal user can only view their own audit logs. @Description 普通用户只能查看自己的审计日志。 @Tags audit @Produce json @Security BearerAuth @Param page query int false "page / 页码" default(1) @Param page_size query int false "page size / 每页数量" default(20) @Param from query string false "start time (RFC3339 or YYYY-MM-DD) / 开始时间" @Param to query string false "end time (RFC3339 or YYYY-MM-DD) / 结束时间" @Success 200 {object} response.Envelope[AuditLogPage] @Router /api/v1/me/audit/logs [get]
func (*Server) ListMySessions ¶
ListMySessions lists active web sessions for current user. ListMySessions 列出当前用户 Web 会话列表。
@Summary List my web sessions / 列出我的 Web 会话 @Description List active web sessions (type=web, not revoked). @Description 列出有效 Web 会话(type=web 且未撤销)。 @Tags me @Produce json @Security BearerAuth @Success 200 {object} response.Envelope[[]TokenInfo] @Router /api/v1/me/sessions [get]
func (*Server) ListMyTokens ¶
ListMyTokens lists tokens of current user. ListMyTokens 列出当前用户的 token。
@Summary List my tokens / 列出我的 Token @Description List tokens (web sessions + api tokens) of current user. @Description 列出当前用户的 Token(Web 会话 + API Token)。 @Tags me @Produce json @Security BearerAuth @Success 200 {object} response.Envelope[[]TokenInfo] @Router /api/v1/me/tokens [get]
func (*Server) ListOnlineChanel ¶
ListMyTokens lists tokens of current user. ListMyTokens 列出当前用户的 token。
@Summary List my tokens / 列出我的 Token @Description List tokens (web sessions + api tokens) of current user. @Description 列出当前用户的 Token(Web 会话 + API Token)。 @Tags me @Produce json @Security BearerAuth @Success 200 {object} response.Envelope[[]TokenInfo] @Router /api/channel [get]
func (*Server) ListSettings ¶
ListSettings @Summary List settings @Description List all settings @Tags Setting @Produce json @Success 200 {array} models.Setting @Failure 500 {object} APIError @Router /api/v1/settings [get]
func (*Server) LoginWeb ¶
LoginWeb handles web login and returns a "web" session token.
@Summary Web login / Web 登录 @Description Create a web session token with sliding idle timeout. @Description 创建带滑动空闲超时的 Web 会话 Token。 @Tags auth @Accept json @Produce json @Param body body LoginWebRequest true "login request / 登录请求" @Success 200 {object} response.Envelope[LoginWebResponse] @Failure 400 {object} response.Envelope[any] @Failure 401 {object} response.Envelope[any] @Router /api/v1/auth/login [post]
func (*Server) Logout ¶
Logout revokes current token.
@Summary Logout / 注销 @Description Revoke current token (web session or api token). @Description 撤销当前 Token(Web 会话或 API Token)。 @Tags auth @Produce json @Security BearerAuth @Success 200 {object} response.Envelope[any] @Failure 401 {object} response.Envelope[any] @Router /api/v1/auth/logout [post]
func (*Server) RevokeMyAllTokens ¶
RevokeMyAllTokens revokes all tokens of current user. RevokeMyAllTokens 撤销当前用户的全部 token。
@Summary Revoke all my tokens / 撤销我所有 Token @Description Self-service revoke all tokens without admin. @Description 普通用户自助撤销自己所有 Token(不走管理员)。 @Tags me @Produce json @Security BearerAuth @Success 200 {object} response.Envelope[any] @Router /api/v1/me/tokens [delete]
func (*Server) RevokeMyTokenByJTI ¶
RevokeMyTokenByJTI revokes one token of current user. RevokeMyTokenByJTI 撤销当前用户指定 token。
@Summary Revoke my token / 撤销我的指定 Token @Tags me @Produce json @Security BearerAuth @Param jti path string true "token jti / token 标识" @Success 200 {object} response.Envelope[any] @Failure 404 {object} response.Envelope[any] @Router /api/v1/me/tokens/{jti} [delete]
func (*Server) ShowMe ¶
ShowMe Show current User info. ShowMe 显示当前用户信息。
@Summary List my tokens / 列出我的 Token @Description List tokens (web sessions + api tokens) of current user. @Description 列出当前用户的 Token(Web 会话 + API Token)。 @Tags me @Produce json @Security BearerAuth @Success 200 {object} response.Envelope[[]TokenInfo] @Router /api/v1/me [get]
func (*Server) StartAuditRetentionJob ¶
func (s *Server) StartAuditRetentionJob(stop <-chan struct{})
StartAuditRetentionJob starts periodic cleanup according to retention policy. StartAuditRetentionJob 根据保留策略启动周期性清理任务。
func (*Server) UpdateSettingByID ¶
Patch by id @Summary Update setting by id @Tags Setting @Accept json @Produce json @Param id path string true "setting id (uuid)" @Param body body UpdateSettingRequest true "update setting" @Success 200 {object} models.Setting @Failure 400 {object} APIError @Failure 404 {object} APIError @Failure 500 {object} APIError @Router /api/v1/settings/{id} [patch]
func (*Server) UpsertSettingValueByName ¶
UpsertSettingValueByName @Summary Upsert setting by name @Description Create if missing; otherwise update value (and optionally value_type). @Description value must match value_type: int|string|bool. @Tags Setting @Accept json @Produce json @Param name path string true "setting name" @Param body body UpsertSettingByNameRequest true "upsert payload" @Success 200 {object} models.Setting @Failure 400 {object} APIError @Failure 500 {object} APIError @Router /api/v1/settings/by-name/{name} [put]
type SessionItem ¶
type SessionItem struct {
JTI string `json:"jti"`
UserID uint `json:"user_id"`
Username string `json:"username"`
IssuedAt time.Time `json:"issued_at"`
LastSeenAt *time.Time `json:"last_seen_at,omitempty"`
IdleTimeoutSeconds int `json:"idle_timeout_seconds"`
RevokedAt *time.Time `json:"revoked_at,omitempty"`
}
SessionItem is web session info. SessionItem 是 Web 会话信息。
type TokenInfo ¶
type TokenInfo struct {
JTI string `json:"jti"`
Type models.TokenType `json:"type"`
Name string `json:"name,omitempty"`
IssuedAt time.Time `json:"issued_at"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
LastSeenAt *time.Time `json:"last_seen_at,omitempty"`
IdleTimeoutSeconds int `json:"idle_timeout_seconds"`
RevokedAt *time.Time `json:"revoked_at,omitempty"`
}
TokenInfo describes token metadata. TokenInfo 描述 token 元数据。
type UpdateSettingRequest ¶
type UpdateSettingRequest struct {
ValueType *string `json:"value_type" example:"bool"`
Value json.RawMessage `json:"value" example:"true"`
}
UpdateSettingRequest 更新 setting 请求 UpdateSettingRequest is request body for update.
type UpsertSettingByNameRequest ¶
type UpsertSettingByNameRequest struct {
ValueType string `json:"value_type" example:"bool"` // int|string|bool
Value json.RawMessage `json:"value" example:"true"` // 10 / "abc" / true
}
UpsertSettingByNameRequest 按 name 写入/更新(value 支持 int/string/bool) UpsertSettingByNameRequest upserts a setting by name (value supports int/string/bool).