notice

package
v5.0.2-beta9 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2023 License: AGPL-3.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Succeed         = 1
	Failed          = 0
	Unauthenticated = -1
	Forbid          = -2
)
View Source
const (
	StateSuccess = 1
	StateFailure = 0
)

Variables

View Source
var (
	ErrUserNotOnline     = errors.New(`通知错误:用户不在线`)
	ErrMsgTypeNotAccept  = errors.New(`通知错误:不接受这种消息类型`)
	ErrClientIDNotOnline = errors.New(`通知错误:ClientID不在线`)
	ErrForcedExit        = errors.New(`Forced exit`)
)
View Source
var (
	// DefaultNoticer 默认noticer
	// state > 0 为成功;否则为失败
	DefaultNoticer Noticer = func(message interface{}, state int, progs ...*Progress) error {
		if len(progs) > 0 && progs[0] != nil {
			message = `[ ` + tplfunc.NumberFormat(progs[0].CalcPercent().Percent, 2) + `% ] ` + fmt.Sprint(message)
		}
		if state > 0 {
			log.Info(message)
		} else {
			log.Error(message)
		}
		return nil
	}

	CustomOutputNoticer CustomWithWriter = func(wOut io.Writer, wErr io.Writer) Noticer {
		return func(message interface{}, state int, progs ...*Progress) error {
			if len(progs) > 0 && progs[0] != nil {
				message = `[ ` + tplfunc.NumberFormat(progs[0].CalcPercent().Percent, 2) + `% ] ` + fmt.Sprint(message)
			}
			if state > 0 {
				fmt.Fprintln(wOut, message)
			} else {
				fmt.Fprintln(wErr, message)
			}
			return nil
		}
	}
)
View Source
var NoticeMessageChanSize = 3

Functions

func Clear

func Clear()

func CloseClient

func CloseClient(user string, clientID string) bool

func CloseMessage

func CloseMessage(user string, types ...string)

func Default

func Default() *userNotices

func Initialize

func Initialize()

func NewUserNotices

func NewUserNotices(debug bool) *userNotices

func OnClose

func OnClose(fn ...func(user string)) *userNotices

func OnOpen

func OnOpen(fn ...func(user string)) *userNotices

func OpenMessage

func OpenMessage(user string, types ...string)

func Recv

func Recv(user string, clientID string) <-chan *Message

func Send

func Send(user string, message *Message) error

func SetDebug

func SetDebug(on bool)

func Stdout

func Stdout(message *Message)

Types

type Control

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

func (*Control) Exited

func (c *Control) Exited() *Control

func (*Control) IsExited

func (c *Control) IsExited() bool

func (*Control) ListenContextAndTimeout

func (c *Control) ListenContextAndTimeout(ctx context.Context, timeouts ...time.Duration) *Control

type CustomWithWriter

type CustomWithWriter func(wOut io.Writer, wErr io.Writer) Noticer

type HTTPNoticerConfig

type HTTPNoticerConfig struct {
	User     string
	Type     string
	ClientID string
	ID       interface{}
	IsExited IsExited
	Timeout  time.Duration
	Mode     string // element / notify
}

func NewHTTPNoticerConfig

func NewHTTPNoticerConfig() *HTTPNoticerConfig

func (*HTTPNoticerConfig) Noticer

func (c *HTTPNoticerConfig) Noticer(ctx context.Context) Noticer

func (*HTTPNoticerConfig) SetClientID

func (c *HTTPNoticerConfig) SetClientID(clientID string) *HTTPNoticerConfig

func (*HTTPNoticerConfig) SetID

func (c *HTTPNoticerConfig) SetID(id interface{}) *HTTPNoticerConfig

func (*HTTPNoticerConfig) SetIsExited

func (c *HTTPNoticerConfig) SetIsExited(isExited IsExited) *HTTPNoticerConfig

func (*HTTPNoticerConfig) SetMode

func (c *HTTPNoticerConfig) SetMode(mode string) *HTTPNoticerConfig

func (*HTTPNoticerConfig) SetTimeout

func (*HTTPNoticerConfig) SetType

func (c *HTTPNoticerConfig) SetType(typ string) *HTTPNoticerConfig

func (*HTTPNoticerConfig) SetUser

func (c *HTTPNoticerConfig) SetUser(user string) *HTTPNoticerConfig

type IsExited

type IsExited interface {
	IsExited() bool
}

func NewControlWithContext

func NewControlWithContext(ctx context.Context, timeout time.Duration) IsExited

type Message

type Message struct {
	ClientID string      `json:"client_id" xml:"client_id"`
	ID       interface{} `json:"id" xml:"id"`
	Type     string      `json:"type" xml:"type"`
	Title    string      `json:"title" xml:"title"`
	Status   int         `json:"status" xml:"status"`
	Content  interface{} `json:"content" xml:"content"`
	Mode     string      `json:"mode" xml:"mode"` //显示模式:notify/element/modal
	Progress *Progress   `json:"progress" xml:"progress"`
}

func NewMessage

func NewMessage() *Message

func NewMessageWithValue

func NewMessageWithValue(typ string, title string, content interface{}, status ...int) *Message

func (*Message) CalcPercent

func (m *Message) CalcPercent() *Message

func (*Message) SetClientID

func (m *Message) SetClientID(clientID string) *Message

func (*Message) SetContent

func (m *Message) SetContent(content interface{}) *Message

func (*Message) SetID

func (m *Message) SetID(id interface{}) *Message

func (*Message) SetMode

func (m *Message) SetMode(mode string) *Message

func (*Message) SetProgress

func (m *Message) SetProgress(progress *Progress) *Message

func (*Message) SetProgressValue

func (m *Message) SetProgressValue(finish int64, total int64) *Message

func (*Message) SetStatus

func (m *Message) SetStatus(status int) *Message

func (*Message) SetTitle

func (m *Message) SetTitle(title string) *Message

func (*Message) SetType

func (m *Message) SetType(t string) *Message

type NProgressor

type NProgressor interface {
	Send(message interface{}, statusCode int) error
	Success(message interface{}) error
	Failure(message interface{}) error
	Add(n int64) NProgressor
	Done(n int64) NProgressor
	AutoComplete(on bool) NProgressor
	Complete() NProgressor
}

type Notice

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

func NewNotice

func NewNotice() *Notice

func (*Notice) CloseClient

func (a *Notice) CloseClient(clientID string)

func (*Notice) CountClient

func (a *Notice) CountClient() int

func (*Notice) OpenClient

func (a *Notice) OpenClient(clientID string)

type NoticeAndProgress

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

func NewP

func NewP(eCtx echo.Context, noticeType string, user string, ctx context.Context) *NoticeAndProgress

func NewWithProgress

func NewWithProgress(noticer Noticer, progresses ...*Progress) *NoticeAndProgress

func (*NoticeAndProgress) Add

func (*NoticeAndProgress) AutoComplete

func (a *NoticeAndProgress) AutoComplete(on bool) NProgressor

func (*NoticeAndProgress) Complete

func (a *NoticeAndProgress) Complete() NProgressor

func (*NoticeAndProgress) Done

func (a *NoticeAndProgress) Done(n int64) NProgressor

func (*NoticeAndProgress) Failure

func (a *NoticeAndProgress) Failure(message interface{}) error

func (*NoticeAndProgress) Send

func (a *NoticeAndProgress) Send(message interface{}, statusCode int) error

func (*NoticeAndProgress) Success

func (a *NoticeAndProgress) Success(message interface{}) error

type Noticer

type Noticer func(message interface{}, state int, progress ...*Progress) error

func New

func New(eCtx echo.Context, noticeType string, user string, ctx context.Context) Noticer

func NewNoticer

func NewNoticer(ctx context.Context, config *HTTPNoticerConfig) Noticer

func (Noticer) WithProgress

func (noticer Noticer) WithProgress(progresses ...*Progress) *NoticeAndProgress

type OnlineUser

type OnlineUser struct {
	User string
	*Notice
}

func NewOnlineUser

func NewOnlineUser(user string) *OnlineUser

func OpenClient

func OpenClient(user string) (oUser *OnlineUser, clientID string)

func (*OnlineUser) Recv

func (oUser *OnlineUser) Recv(clientID string) <-chan *Message

func (*OnlineUser) Send

func (oUser *OnlineUser) Send(message *Message, openDebug ...bool) error

type OnlineUsers

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

func NewOnlineUsers

func NewOnlineUsers() *OnlineUsers

func (*OnlineUsers) Clear

func (o *OnlineUsers) Clear()

func (*OnlineUsers) Delete

func (o *OnlineUsers) Delete(user string)

func (*OnlineUsers) GetOk

func (o *OnlineUsers) GetOk(user string, noLock ...bool) (*OnlineUser, bool)

func (*OnlineUsers) Set

func (o *OnlineUsers) Set(user string, oUser *OnlineUser)

type Progress

type Progress struct {
	Total    int64   `json:"total" xml:"total"`
	Finish   int64   `json:"finish" xml:"finish"`
	Percent  float64 `json:"percent" xml:"percent"`
	Complete bool    `json:"complete" xml:"complete"`
	// contains filtered or unexported fields
}

func NewProgress

func NewProgress() *Progress

func (*Progress) CalcPercent

func (p *Progress) CalcPercent() *Progress

func (*Progress) IsExited

func (p *Progress) IsExited() bool

func (*Progress) SetControl

func (p *Progress) SetControl(control IsExited) *Progress

Jump to

Keyboard shortcuts

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