sys

package
v2.0.0-beta3 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const QNameParam = "qname"

Variables

This section is empty.

Functions

func JWTMiddleware

func JWTMiddleware(cfg *jwt.Config, checkOTP bool) wool.Middleware

Types

type AuthActions

type AuthActions struct {
	AuthService AuthService
	// contains filtered or unexported fields
}

func NewAuthActions

func NewAuthActions(authService AuthService, logger *slog.Logger) *AuthActions

func (*AuthActions) OTP

func (a *AuthActions) OTP(c wool.Ctx) error

func (*AuthActions) Refresh

func (a *AuthActions) Refresh(c wool.Ctx) error

func (*AuthActions) SignIn

func (a *AuthActions) SignIn(c wool.Ctx) error

type AuthDTO

type AuthDTO struct {
	ClientID string `json:"client_id,omitempty" validate:"required,uuid4"`
}

type AuthService

type AuthService interface {
	SignInByCredentials(ctx context.Context, username, password string) (Session, error)
	SignInByOTP(ctx context.Context, username, password string) (Session, error)
	SignInByRefreshToken(ctx context.Context, refreshToken string) (Session, error)
}

func NewAuthService

func NewAuthService(
	userRepo repository.ReadRepository[*entity.SysUser],
	client redis.UniversalClient,
	signer jwt.Signer,
	cfgJWT *jwt.Config,
) AuthService

type CreateChatDTO

type CreateChatDTO struct {
	TelegramID int64           `json:"telegram_id,omitempty" validate:"required"`
	Type       entity.ChatType `json:"type,omitempty" validate:"required,oneof=private group supergroup channel"`
	Title      string          `json:"title,omitempty" validate:"omitempty,max=254"`
	Username   string          `json:"username,omitempty" validate:"omitempty,max=254"`
	FirstName  string          `json:"first_name,omitempty" validate:"omitempty,max=254"`
	LastName   string          `json:"last_name,omitempty" validate:"omitempty,max=254"`
	Broadcast  []string        `json:"broadcast,omitempty" validate:"omitempty,dive,uuid4"`
	Blocked    bool            `json:"blocked,omitempty"`
	Deleted    bool            `json:"deleted,omitempty"`
}

type CreateJobDTO

type CreateJobDTO struct {
	CronExpr string         `json:"cron_expr,omitempty" validate:"required,min=9,max=254"`
	Name     entity.JobName `json:"name,omitempty" validate:"required,max=254"`
	Payload  any            `json:"payload,omitempty" validate:"required,dive"`
	Options  []JobOptionDTO `json:"options,omitempty" validate:"omitempty,dive"`
	Enabled  bool           `json:"enabled,omitempty"`
}

func (*CreateJobDTO) UnmarshalJSON

func (dto *CreateJobDTO) UnmarshalJSON(data []byte) error

type CreateSiteDTO

type CreateSiteDTO struct {
	Domain    string   `json:"domain,omitempty" validate:"required,fqdn"`
	Favicon   string   `json:"favicon,omitempty" validate:"required,url"`
	Languages []string `json:"languages,omitempty" validate:"required,min=1,dive,bcp47_language_tag"`
	Title     string   `json:"title,omitempty" validate:"required,max=254"`
	Enabled   bool     `json:"enabled,omitempty"`
}

type DailyStats

type DailyStats struct {
	Queue     string `json:"queue"`
	Processed int    `json:"processed"`
	Succeeded int    `json:"succeeded"`
	Failed    int    `json:"failed"`
	Date      string `json:"date"`
}

type FeedPayloadDTO

type FeedPayloadDTO struct {
	SiteID string `json:"site_id,omitempty" validate:"required,uuid4"`
	Link   string `json:"link,omitempty" validate:"required,url"`
}

type JobOptionDTO

type JobOptionDTO struct {
	Type  entity.JobOptionType `json:"type,omitempty" validate:"required,max=50"`
	Value string               `json:"value,omitempty" validate:"required"`
}

type MediaDTO

type MediaDTO struct {
	URL  string           `json:"url,omitempty" validate:"required,url"`
	Type entity.MediaType `json:"type,omitempty" validate:"required,max=10"`
	Meta map[string]any   `json:"meta,omitempty"`
}

type OtpDTO

type OtpDTO struct {
	Password string `json:"password,omitempty" validate:"required,numeric,len=6"`
}

type QueueActions

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

func NewQueueActions

func NewQueueActions(redisConnOpt asynq.RedisConnOpt) *QueueActions

func (*QueueActions) Close

func (a *QueueActions) Close() error

func (*QueueActions) Delete

func (a *QueueActions) Delete(c wool.Ctx) error

func (*QueueActions) Pause

func (a *QueueActions) Pause(c wool.Ctx) error

func (*QueueActions) Resume

func (a *QueueActions) Resume(c wool.Ctx) error

type QueueInfo

type QueueInfo struct {
	// Name of the queue.
	Queue string `json:"queue"`
	// Total number of bytes the queue and its tasks require to be stored in redis.
	MemoryUsage int64 `json:"memory_usage_bytes"`
	// Total number of tasks in the queue.
	Size int `json:"size"`
	// Totoal number of groups in the queue.
	Groups int `json:"groups"`
	// Latency of the queue in milliseconds.
	LatencyMillisec int64 `json:"latency_msec"`
	// Latency duration string for display purpose.
	DisplayLatency string `json:"display_latency"`

	// Number of tasks in each state.
	Active      int `json:"active"`
	Pending     int `json:"pending"`
	Aggregating int `json:"aggregating"`
	Scheduled   int `json:"scheduled"`
	Retry       int `json:"retry"`
	Archived    int `json:"archived"`
	Completed   int `json:"completed"`

	// Total number of tasks processed during the given date.
	// The number includes both succeeded and failed tasks.
	Processed int `json:"processed"`
	// Breakdown of processed tasks.
	Succeeded int `json:"succeeded"`
	Failed    int `json:"failed"`
	// Paused indicates whether the queue is paused.
	// If true, tasks in the queue will not be processed.
	Paused bool `json:"paused"`
	// Time when this snapshot was taken.
	Timestamp time.Time `json:"timestamp"`
}

type RefreshTokenDTO

type RefreshTokenDTO struct {
	RefreshToken string `json:"refresh_token" validate:"required,uuid4"`
}

type SSE

type SSE struct {
	*sse.Event
	// contains filtered or unexported fields
}

func NewSSE

func NewSSE(redisConnOpt asynq.RedisConnOpt, logger *slog.Logger) *SSE

func (*SSE) Auth

func (a *SSE) Auth(c wool.Ctx) error

func (*SSE) Listen

func (a *SSE) Listen(done <-chan struct{})

func (*SSE) Middleware

func (a *SSE) Middleware(next wool.Handler) wool.Handler

type SchedulerEntry

type SchedulerEntry struct {
	ID            string          `json:"id"`
	Spec          string          `json:"spec"`
	JobName       string          `json:"job_name"`
	JobPayload    json.RawMessage `json:"job_payload"`
	Opts          []string        `json:"options"`
	NextEnqueueAt time.Time       `json:"next_enqueue_at"`
	// This field is omitted if there were no previous enqueue events.
	PrevEnqueueAt *time.Time `json:"prev_enqueue_at,omitempty"`
}

type Session

type Session struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

type SignInDTO

type SignInDTO struct {
	Username string `json:"username,omitempty" validate:"required,min=3,max=254"`
	Password string `json:"password,omitempty" validate:"required,min=8,max=64"`
}

type SitemapPayloadDTO

type SitemapPayloadDTO struct {
	SiteID     string  `json:"site_id,omitempty" validate:"required,uuid4"`
	Link       string  `json:"link,omitempty" validate:"required,url"`
	Lang       *string `json:"lang,omitempty" validate:"omitempty,bcp47_language_tag"`
	MatchLoc   *string `json:"match_loc,omitempty" validate:"omitempty,max=500"`
	SearchLoc  *string `json:"search_loc,omitempty" validate:"omitempty,max=500"`
	SearchLink *string `json:"search_link,omitempty" validate:"omitempty,max=500"`
	Index      *bool   `json:"index,omitempty"`
	StopOnDup  *bool   `json:"stop_on_dup,omitempty"`
}

type StatsResponse

type StatsResponse struct {
	Queues           []*QueueInfo             `json:"queues,omitempty"`
	DailyStats       map[string][]*DailyStats `json:"daily_stats,omitempty"`
	SchedulerEntries []*SchedulerEntry        `json:"scheduler_entries,omitempty"`
}

type Sys

type Sys struct {
	Logger         *slog.Logger
	CfgJWT         *jwt.Config
	SSE            *SSE
	AuthActions    *AuthActions
	QueueActions   *QueueActions
	ArticleActions *ArticleActions
	SiteCRUD       action.CRUD
	ChatCRUD       action.CRUD
	JobCRUD        action.CRUD
	DirUI          *string
}

func (*Sys) Listen

func (s *Sys) Listen(done <-chan struct{})

func (*Sys) Register

func (s *Sys) Register(mux *wool.Wool)

type UpdateArticleDTO

type UpdateArticleDTO struct {
	Lang       string      `json:"lang,omitempty" validate:"omitempty,bcp47_language_tag"`
	Title      string      `json:"title,omitempty" validate:"omitempty,max=254"`
	ShortDesc  *string     `json:"short_desc,omitempty" validate:"omitempty,max=500"`
	LongDesc   *string     `json:"long_desc,omitempty"`
	Media      *[]MediaDTO `json:"media,omitempty" validate:"omitempty,dive"`
	Categories *[]string   `json:"categories,omitempty" validate:"omitempty,dive,min=1,max=254"`
}

type UpdateChatDTO

type UpdateChatDTO struct {
	Broadcast *[]string `json:"broadcast,omitempty" validate:"omitempty,dive,uuid4"`
	Blocked   *bool     `json:"blocked,omitempty"`
}

type UpdateJobDTO

type UpdateJobDTO struct {
	CronExpr string          `json:"cron_expr,omitempty" validate:"omitempty,min=9,max=254"`
	Name     entity.JobName  `json:"name,omitempty" validate:"omitempty,max=254"`
	Payload  any             `json:"payload,omitempty" validate:"omitempty,dive"`
	Options  *[]JobOptionDTO `json:"options,omitempty" validate:"omitempty,dive"`
	Enabled  *bool           `json:"enabled,omitempty"`
}

func (*UpdateJobDTO) UnmarshalJSON

func (dto *UpdateJobDTO) UnmarshalJSON(data []byte) error

type UpdateSiteDTO

type UpdateSiteDTO struct {
	Domain    string   `json:"domain,omitempty" validate:"omitempty,fqdn"`
	Favicon   string   `json:"favicon,omitempty" validate:"required,url"`
	Languages []string `json:"languages,omitempty" validate:"omitempty,dive,bcp47_language_tag"`
	Title     string   `json:"title,omitempty" validate:"omitempty,max=254"`
	Enabled   *bool    `json:"enabled,omitempty"`
}

type UserClaims

type UserClaims struct {
	jwt.UserClaims
}

func GetClaims

func GetClaims(c wool.Ctx) UserClaims

func (UserClaims) Valid

func (c UserClaims) Valid() error

Jump to

Keyboard shortcuts

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