Documentation ¶
Index ¶
- Constants
- Variables
- func Clear()
- func CloseClient(user string, clientID string) bool
- func CloseMessage(user string, types ...string)
- func Default() *userNotices
- func GetClientID(eCtx echo.Context) string
- func GetNoticeID(eCtx echo.Context) string
- func GetNoticeMode(eCtx echo.Context) string
- func Initialize()
- func IsOnline(user string) bool
- func NewUserNotices(debug bool) *userNotices
- func OnClose(fn ...func(user string)) *userNotices
- func OnOpen(fn ...func(user string)) *userNotices
- func OnlineStatus(users ...string) map[string]bool
- func OpenMessage(user string, types ...string)
- func Recv(user string, clientID string) <-chan *Message
- func Send(user string, message *Message) error
- func SetClientID(clientID string) func(*HTTPNoticerConfig)
- func SetDebug(on bool)
- func SetID(id interface{}) func(*HTTPNoticerConfig)
- func SetIsExited(isExited IsExited) func(*HTTPNoticerConfig)
- func SetMode(mode string) func(*HTTPNoticerConfig)
- func SetTimeout(timeout time.Duration) func(*HTTPNoticerConfig)
- func SetType(typ string) func(*HTTPNoticerConfig)
- func SetUser(user string) func(*HTTPNoticerConfig)
- func Stdout(message *Message)
- func ToReadCloser(r io.Reader) io.ReadCloser
- func ToWriteCloser(w io.Writer) io.WriteCloser
- type Control
- type CustomWithWriter
- type HTTPNoticerConfig
- func (c *HTTPNoticerConfig) Noticer(ctx context.Context) Noticer
- func (c *HTTPNoticerConfig) SetClientID(clientID string) *HTTPNoticerConfig
- func (c *HTTPNoticerConfig) SetID(id interface{}) *HTTPNoticerConfig
- func (c *HTTPNoticerConfig) SetIsExited(isExited IsExited) *HTTPNoticerConfig
- func (c *HTTPNoticerConfig) SetMode(mode string) *HTTPNoticerConfig
- func (c *HTTPNoticerConfig) SetTimeout(t time.Duration) *HTTPNoticerConfig
- func (c *HTTPNoticerConfig) SetType(typ string) *HTTPNoticerConfig
- func (c *HTTPNoticerConfig) SetUser(user string) *HTTPNoticerConfig
- type IsExited
- type Message
- func (m *Message) Release()
- func (m *Message) SetClientID(clientID string) *Message
- func (m *Message) SetContent(content interface{}) *Message
- func (m *Message) SetID(id interface{}) *Message
- func (m *Message) SetMode(mode string) *Message
- func (m *Message) SetProgress(progress *Progress) *Message
- func (m *Message) SetStatus(status int) *Message
- func (m *Message) SetTitle(title string) *Message
- func (m *Message) SetType(t string) *Message
- type MessageWithStatus
- type NProgressor
- type Notice
- type NoticeAndProgress
- func (a *NoticeAndProgress) Add(n int64) NProgressor
- func (a *NoticeAndProgress) AutoComplete(on bool) NProgressor
- func (a *NoticeAndProgress) Callback(total int64, exec func(callback func(strLen int)) error) error
- func (a *NoticeAndProgress) Complete() NProgressor
- func (a *NoticeAndProgress) Done(n int64) NProgressor
- func (a *NoticeAndProgress) Failure(message interface{}) error
- func (p *NoticeAndProgress) ProxyReader(r io.Reader) io.ReadCloser
- func (p *NoticeAndProgress) ProxyWriter(w io.Writer) io.WriteCloser
- func (a *NoticeAndProgress) Reset()
- func (a *NoticeAndProgress) Send(message interface{}, statusCode int) error
- func (a *NoticeAndProgress) Success(message interface{}) error
- type Noticer
- type Notifier
- type OnlineUser
- type OnlineUsers
- type Progress
- func (p *Progress) Add(n int64) *Progress
- func (p *Progress) AutoComplete(on bool) *Progress
- func (p *Progress) CalcPercent() *Progress
- func (p *Progress) Callback(total int64, exec func(callback func(strLen int)) error) error
- func (p *Progress) CloneInfo() ProgressInfo
- func (p *Progress) Complete() bool
- func (p *Progress) CopyToInfo(to *ProgressInfo)
- func (p *Progress) Done(n int64) int64
- func (p *Progress) Finish() int64
- func (p *Progress) IsExited() bool
- func (p *Progress) Percent() float64
- func (p *Progress) Reset()
- func (p *Progress) SetComplete() *Progress
- func (p *Progress) SetControl(control IsExited) *Progress
- func (p *Progress) SetPercent(percent float64) *Progress
- func (p *Progress) Total() int64
- type ProgressInfo
- type Progressor
Constants ¶
View Source
const ( ModeElement = `element` ModeNotify = `notify` ModeModal = `modal` ModeDash = `-` )
View Source
const ( Succeed = 1 Failed = 0 Unauthenticated = -1 Forbid = -2 )
View Source
const ( StateSuccess = 1 StateFailure = 0 )
View Source
const AnyClientID = `any`
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 CloseClient ¶
func CloseMessage ¶
func GetClientID ¶ added in v5.2.6
func GetNoticeID ¶ added in v5.2.6
func GetNoticeMode ¶ added in v5.2.6
func Initialize ¶
func Initialize()
func NewUserNotices ¶
func NewUserNotices(debug bool) *userNotices
func OnlineStatus ¶
func OpenMessage ¶
func SetClientID ¶ added in v5.2.5
func SetClientID(clientID string) func(*HTTPNoticerConfig)
func SetID ¶ added in v5.2.5
func SetID(id interface{}) func(*HTTPNoticerConfig)
func SetIsExited ¶ added in v5.2.5
func SetIsExited(isExited IsExited) func(*HTTPNoticerConfig)
func SetMode ¶ added in v5.2.5
func SetMode(mode string) func(*HTTPNoticerConfig)
func SetTimeout ¶ added in v5.2.5
func SetTimeout(timeout time.Duration) func(*HTTPNoticerConfig)
func SetType ¶ added in v5.2.5
func SetType(typ string) func(*HTTPNoticerConfig)
func SetUser ¶ added in v5.2.5
func SetUser(user string) func(*HTTPNoticerConfig)
func ToReadCloser ¶ added in v5.2.6
func ToReadCloser(r io.Reader) io.ReadCloser
func ToWriteCloser ¶ added in v5.2.6
func ToWriteCloser(w io.Writer) io.WriteCloser
Types ¶
type HTTPNoticerConfig ¶
type HTTPNoticerConfig struct { User string Type string // Topic 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 (c *HTTPNoticerConfig) SetTimeout(t time.Duration) *HTTPNoticerConfig
func (*HTTPNoticerConfig) SetType ¶
func (c *HTTPNoticerConfig) SetType(typ string) *HTTPNoticerConfig
func (*HTTPNoticerConfig) SetUser ¶
func (c *HTTPNoticerConfig) SetUser(user string) *HTTPNoticerConfig
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 *ProgressInfo `json:"progress" xml:"progress"` }
func NewMessage ¶
func NewMessage() *Message
func NewMessageWithValue ¶
func (*Message) SetClientID ¶
func (*Message) SetContent ¶
func (*Message) SetProgress ¶
type MessageWithStatus ¶ added in v5.2.6
type MessageWithStatus struct { Message interface{} Status int }
type NProgressor ¶
type NProgressor interface { Notifier Progressor }
type Notice ¶
type Notice struct {
// contains filtered or unexported fields
}
func (*Notice) CloseClient ¶
func (*Notice) CountClient ¶
func (*Notice) OpenClient ¶
type NoticeAndProgress ¶
type NoticeAndProgress struct {
// contains filtered or unexported fields
}
func NewP ¶
func NewP(eCtx echo.Context, noticeType string, user string, ctx context.Context, opts ...func(*HTTPNoticerConfig)) *NoticeAndProgress
func NewWithProgress ¶
func NewWithProgress(noticer Noticer, progresses ...*Progress) *NoticeAndProgress
func (*NoticeAndProgress) Add ¶
func (a *NoticeAndProgress) Add(n int64) NProgressor
func (*NoticeAndProgress) AutoComplete ¶
func (a *NoticeAndProgress) AutoComplete(on bool) NProgressor
func (*NoticeAndProgress) Callback ¶ added in v5.1.2
func (a *NoticeAndProgress) Callback(total int64, exec func(callback func(strLen int)) error) error
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) ProxyReader ¶ added in v5.2.6
func (p *NoticeAndProgress) ProxyReader(r io.Reader) io.ReadCloser
func (*NoticeAndProgress) ProxyWriter ¶ added in v5.2.6
func (p *NoticeAndProgress) ProxyWriter(w io.Writer) io.WriteCloser
func (*NoticeAndProgress) Reset ¶ added in v5.2.6
func (a *NoticeAndProgress) Reset()
func (*NoticeAndProgress) Send ¶
func (a *NoticeAndProgress) Send(message interface{}, statusCode int) error
func (*NoticeAndProgress) Success ¶
func (a *NoticeAndProgress) Success(message interface{}) error
type Noticer ¶
func MakeNoticer ¶ added in v5.2.6
func NewNoticer ¶
func NewNoticer(ctx context.Context, config *HTTPNoticerConfig) Noticer
func (Noticer) WithProgress ¶
func (noticer Noticer) WithProgress(progresses ...*Progress) *NoticeAndProgress
type OnlineUser ¶
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
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) OnlineStatus ¶
func (o *OnlineUsers) OnlineStatus(users ...string) map[string]bool
func (*OnlineUsers) Set ¶
func (o *OnlineUsers) Set(user string, oUser *OnlineUser)
type Progress ¶
type Progress struct {
// contains filtered or unexported fields
}
func NewProgress ¶
func NewProgress() *Progress
func (*Progress) AutoComplete ¶ added in v5.1.1
func (*Progress) CalcPercent ¶
func (*Progress) CloneInfo ¶ added in v5.2.6
func (p *Progress) CloneInfo() ProgressInfo
func (*Progress) CopyToInfo ¶ added in v5.2.6
func (p *Progress) CopyToInfo(to *ProgressInfo)
func (*Progress) SetComplete ¶ added in v5.1.1
func (*Progress) SetControl ¶
func (*Progress) SetPercent ¶ added in v5.2.6
type ProgressInfo ¶ added in v5.2.6
type Progressor ¶ added in v5.2.6
type Progressor interface { Add(n int64) NProgressor Done(n int64) NProgressor AutoComplete(on bool) NProgressor Complete() NProgressor Reset() ProxyReader(r io.Reader) io.ReadCloser ProxyWriter(w io.Writer) io.WriteCloser Callback(total int64, exec func(callback func(strLen int)) error) error }
Click to show internal directories.
Click to hide internal directories.