Documentation ¶
Index ¶
- Constants
- Variables
- func Clear()
- func CloseClient(user string, clientID string) bool
- func CloseMessage(user string, types ...string)
- func Default() *userNotices
- func Initialize()
- func NewUserNotices(debug bool) *userNotices
- func OnClose(fn ...func(user string)) *userNotices
- func OnOpen(fn ...func(user string)) *userNotices
- func OpenMessage(user string, types ...string)
- func Recv(user string, clientID string) <-chan *Message
- func Send(user string, message *Message) error
- func SetDebug(on bool)
- func Stdout(message *Message)
- 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) CalcPercent() *Message
- 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) SetProgressValue(finish int64, total int64) *Message
- func (m *Message) SetStatus(status int) *Message
- func (m *Message) SetTitle(title string) *Message
- func (m *Message) SetType(t string) *Message
- type NProgressor
- type Notice
- type NoticeAndProgress
- func (a *NoticeAndProgress) Add(n int64) NProgressor
- func (a *NoticeAndProgress) AutoComplete(on bool) NProgressor
- func (a *NoticeAndProgress) Complete() NProgressor
- func (a *NoticeAndProgress) Done(n int64) NProgressor
- func (a *NoticeAndProgress) Failure(message interface{}) error
- func (a *NoticeAndProgress) Send(message interface{}, statusCode int) error
- func (a *NoticeAndProgress) Success(message interface{}) error
- type Noticer
- type OnlineUser
- type OnlineUsers
- type Progress
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 CloseClient ¶
func CloseMessage ¶
func Initialize ¶
func Initialize()
func NewUserNotices ¶
func NewUserNotices(debug bool) *userNotices
func OpenMessage ¶
Types ¶
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 (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 *Progress `json:"progress" xml:"progress"` }
func NewMessage ¶
func NewMessage() *Message
func NewMessageWithValue ¶
func (*Message) CalcPercent ¶
func (*Message) SetClientID ¶
func (*Message) SetContent ¶
func (*Message) SetProgress ¶
func (*Message) SetProgressValue ¶
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 (*Notice) CloseClient ¶
func (*Notice) CountClient ¶
func (*Notice) OpenClient ¶
type NoticeAndProgress ¶
type NoticeAndProgress struct {
// contains filtered or unexported fields
}
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) 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 ¶
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 ¶ added in v3.6.3
func (oUser *OnlineUser) Recv(clientID string) <-chan *Message
func (*OnlineUser) Send ¶ added in v3.6.3
func (oUser *OnlineUser) Send(message *Message) error
type OnlineUsers ¶ added in v3.6.3
type OnlineUsers struct {
// contains filtered or unexported fields
}
func NewOnlineUsers ¶ added in v3.6.3
func NewOnlineUsers() *OnlineUsers
func (*OnlineUsers) Clear ¶ added in v3.6.3
func (o *OnlineUsers) Clear()
func (*OnlineUsers) Delete ¶ added in v3.6.3
func (o *OnlineUsers) Delete(user string)
func (*OnlineUsers) GetOk ¶ added in v3.6.3
func (o *OnlineUsers) GetOk(user string, noLock ...bool) (*OnlineUser, bool)
func (*OnlineUsers) Set ¶ added in v3.6.3
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 (*Progress) SetControl ¶
Click to show internal directories.
Click to hide internal directories.