Documentation ¶
Overview ¶
This file convert from freeswitch 1.10.9 switch_log.c
Index ¶
- Variables
- func Debugf(format string, v ...any)
- func Errorf(format string, v ...any)
- func Fatalf(format string, v ...any)
- func Infof(format string, v ...any)
- func Noticef(format string, v ...any)
- func Warnf(format string, v ...any)
- type Command
- type ConnHandler
- type Connection
- func (conn *Connection) Api(ctx context.Context, cmd string, args ...string) (string, error)
- func (conn *Connection) BgApi(ctx context.Context, cmd string, args ...string) (string, error)
- func (conn *Connection) Close()
- func (conn *Connection) Execute(ctx context.Context, app string, uuid string, params ...string) (string, error)
- func (conn *Connection) ExecuteLooped(ctx context.Context, app string, uuid string, loops uint, params ...string) (string, error)
- func (conn *Connection) ExecuteLoopedSync(ctx context.Context, app string, uuid string, loops uint, params ...string) (string, error)
- func (conn *Connection) ExecuteSync(ctx context.Context, app string, uuid string, params ...string) (string, error)
- func (conn *Connection) Fslog(ctx context.Context, lv FslogLevel)
- func (conn *Connection) HandleEvents(ctx context.Context) error
- func (conn *Connection) MustSendOK(ctx context.Context, cmd string, args ...string)
- func (conn *Connection) Plain(ctx context.Context, ens []ev_name.EventName, subs []string)
- func (conn *Connection) Send(ctx context.Context, cmd string, args ...string) (string, error)
- func (conn *Connection) SendBytes(ctx context.Context, buf []byte) (string, error)
- func (conn *Connection) SendEvent(ctx context.Context, en ev_name.EventName, headers map[string]string, ...) error
- type Event
- func (e Event) API() (string, string)
- func (e Event) App() (string, string)
- func (e Event) BgCommand() (string, string)
- func (e Event) BgJob() string
- func (e Event) BgJobResponse() string
- func (e Event) CallDirection() string
- func (e Event) Callee() string
- func (e Event) Caller() string
- func (e Event) CoreIP() string
- func (e Event) CoreNetworkAddr() string
- func (e Event) CoreUuid() string
- func (e Event) CurrentApp() (string, string)
- func (e Event) Digits() string
- func (e Event) DigitsSource() string
- func (e Event) ErrOrRes() (raw string, err error)
- func (e Event) EventContent() string
- func (e Event) FireTime() FireTime
- func (e Event) Get(header string) string
- func (e Event) GetRaw(header string) string
- func (e Event) GetTextBody() string
- func (e Event) Name() ev_name.EventName
- func (e Event) Sequence() string
- func (e Event) SipFrom() string
- func (e Event) SipTo() string
- func (e Event) String() string
- func (e Event) Uuid() string
- type EventType
- type FireTime
- type Fslog
- type FslogLevel
- type Level
- type Logger
- type Option
- func WithAutoRedial(strategy RedoStrategy) Option
- func WithDefaultAutoRedial() Option
- func WithDialTimeout(t time.Duration) Option
- func WithHeartBeat(t time.Duration) Option
- func WithLogLevel(lv Level) Option
- func WithLogOutput(w io.Writer) Option
- func WithLogPrefix(s string) Option
- func WithLogger(logger Logger) Option
- func WithMaxRetries(n int) Option
- func WithNetDelay(t time.Duration) Option
- func WithSendReplyCap(n int) Option
- type Options
- type RedoStrategy
Constants ¶
This section is empty.
Variables ¶
var ErrMismatchEventType = errors.New("mismatch event type")
Functions ¶
Types ¶
type Command ¶
type ConnHandler ¶
type ConnHandler interface { OnConnect(*Connection) OnDisconnect(*Connection, Event) OnEvent(context.Context, *Connection, Event) OnFslog(context.Context, *Connection, Fslog) OnClose(*Connection) }
type Connection ¶
type Connection struct { // reset when connection auto redial Handler ConnHandler Address string Password string // contains filtered or unexported fields }
func Dial ¶ added in v0.0.2
func Dial(addr, passwd string, handler ConnHandler, options ...Option) (*Connection, error)
Create a new event socket connection and take a ConnectionHandler interface. This will create a new 'event callback' goroutine this goroutine will exit when call goesl.*Connection.Close()
func (*Connection) Api ¶
Send API command to FreeSWITCH by event socket, already start with `api ` get result in param `h` by calling method, esl.Event.GetTextBody(), result maybe start withh `-ERR `. NOTE: do not use block API such as orignate here, which will block fs from sending other events(e.g. HEARTBEAT, further make esl client automatic redial), so use (*Connection).BgApi
func (*Connection) BgApi ¶
`bgapi` command will never response error, so just care Connection error handle This is a better way to use `api bgapi uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` instead of `bgapi ` and wait for job uuid
func (*Connection) Close ¶
func (conn *Connection) Close()
Close the connection and make event callback exit as soon as possible ignore all errors here because may the connection already lost
Close is protected by sync.Once, so you can call this for twice or more
func (*Connection) Execute ¶
func (conn *Connection) Execute(ctx context.Context, app string, uuid string, params ...string) (string, error)
Execute an app on leg `uuid` suggest: use RepJustCareError
func (*Connection) ExecuteLooped ¶
func (conn *Connection) ExecuteLooped(ctx context.Context, app string, uuid string, loops uint, params ...string) (string, error)
Execute an app on leg `uuid` and for `loops` times suggest: use RepJustCareError
func (*Connection) ExecuteLoopedSync ¶
func (conn *Connection) ExecuteLoopedSync(ctx context.Context, app string, uuid string, loops uint, params ...string, ) (string, error)
Execute an app on leg `uuid` and for `loops` times, this app will not be interrupted util finish. suggest: use RepJustCareError
func (*Connection) ExecuteSync ¶
func (conn *Connection) ExecuteSync(ctx context.Context, app string, uuid string, params ...string) (string, error)
Execute an app on leg `uuid`, this app will not be interrupted util finish. suggest: use RepJustCareError
func (*Connection) Fslog ¶ added in v0.0.4
func (conn *Connection) Fslog(ctx context.Context, lv FslogLevel)
func (*Connection) HandleEvents ¶
func (conn *Connection) HandleEvents(ctx context.Context) error
Receive events and handle them by `goesl.ConnectionHandler` if error returned is not `os.ErrClosed` or `context.ErrCanceled` that means unexpected error occurred. To distingush that, you can use: `errors.Is(err, net.ErrClosed) || errors.Is(err, context.Canceled)`
func (*Connection) MustSendOK ¶
func (conn *Connection) MustSendOK(ctx context.Context, cmd string, args ...string)
must send and receive command, or fatal the process
type Event ¶
type Event struct { Type EventType // contains filtered or unexported fields }
func (Event) BgJobResponse ¶ added in v0.0.3
func (Event) CallDirection ¶ added in v0.0.3
func (Event) CoreNetworkAddr ¶ added in v0.0.3
func (Event) CurrentApp ¶ added in v0.0.3
current app and data
func (Event) DigitsSource ¶ added in v0.0.3
func (Event) EventContent ¶ added in v0.0.4
func (Event) Get ¶
Get retrieves the value of header from Event header or (if not found) from Event body. The value is returned unescaped and is empty if not found anywhere.
func (Event) GetTextBody ¶
type Fslog ¶ added in v0.0.4
type Fslog struct { Content string File string UserData string Func string Line int Level FslogLevel }
func Event2Fslog ¶ added in v0.0.4
type FslogLevel ¶ added in v0.0.4
type FslogLevel int
var ( FslogLevel_DEBUG10 FslogLevel = 110 // SWITCH_LOG_DEBUG10 FslogLevel_DEBUG9 FslogLevel = 109 // SWITCH_LOG_DEBUG9 FslogLevel_DEBUG8 FslogLevel = 108 // SWITCH_LOG_DEBUG8 FslogLevel_DEBUG7 FslogLevel = 107 // SWITCH_LOG_DEBUG7 FslogLevel_DEBUG6 FslogLevel = 106 // SWITCH_LOG_DEBUG6 FslogLevel_DEBUG5 FslogLevel = 105 // SWITCH_LOG_DEBUG5 FslogLevel_DEBUG4 FslogLevel = 104 // SWITCH_LOG_DEBUG4 FslogLevel_DEBUG3 FslogLevel = 103 // SWITCH_LOG_DEBUG3 FslogLevel_DEBUG2 FslogLevel = 102 // SWITCH_LOG_DEBUG2 FslogLevel_DEBUG1 FslogLevel = 101 // SWITCH_LOG_DEBUG1 FslogLevel_DEBUG FslogLevel = 7 // SWITCH_LOG_DEBUG FslogLevel_INFO FslogLevel = 6 // SWITCH_LOG_INFO FslogLevel_NOTICE FslogLevel = 5 // SWITCH_LOG_NOTICE FslogLevel_WARNING FslogLevel = 4 // SWITCH_LOG_WARNING FslogLevel_ERROR FslogLevel = 3 // SWITCH_LOG_ERROR FslogLevel_CRIT FslogLevel = 2 // SWITCH_LOG_CRIT FslogLevel_ALERT FslogLevel = 1 // SWITCH_LOG_ALERT FslogLevel_CONSOLE FslogLevel = 0 // SWITCH_LOG_CONSOLE FslogLevel_DISABLE FslogLevel = -1 // SWITCH_LOG_DISABLE FslogLevel_INVALID FslogLevel = 64 // SWITCH_LOG_INVALID FslogLevel_UNINIT FslogLevel = 1000 // SWITCH_LOG_UNINIT )
func FslogString2Level ¶ added in v0.0.4
func FslogString2Level(s string) FslogLevel
func (FslogLevel) String ¶ added in v0.0.4
func (lv FslogLevel) String() string
type Level ¶ added in v0.0.2
type Level int
Level defines the priority of a log message. When a logger is configured with a level, any log message with a lower log level (smaller by integer comparison) will not be output.
The levels of logs.
type Logger ¶ added in v0.0.2
type Logger interface { Debugf(format string, v ...any) Infof(format string, v ...any) Noticef(format string, v ...any) Warnf(format string, v ...any) Errorf(format string, v ...any) Fatalf(format string, v ...any) }
Logger is a logger interface that output logs with a format.
type Option ¶ added in v0.0.2
type Option struct {
// contains filtered or unexported fields
}
func WithAutoRedial ¶ added in v0.0.2
func WithAutoRedial(strategy RedoStrategy) Option
need to pay attention that the `strategy` should handle that time.Duration is empty
func WithDefaultAutoRedial ¶ added in v0.0.2
func WithDefaultAutoRedial() Option
func WithDialTimeout ¶ added in v0.0.2
func WithHeartBeat ¶ added in v0.0.2
Set heartbeat interval time duration only take effect when set with `WithAutoRedial` event receiver regards connection lost when `heartbeat_interval + net_delay > time_wait`
func WithLogLevel ¶ added in v0.0.2
Set logger level, ONLY set level of internal logger if a user defined logger, do nothing
func WithLogOutput ¶ added in v0.0.2
Set logger output file, only set output file of set internal logger if a user defined logger, do nothing
func WithLogPrefix ¶ added in v0.0.3
func WithLogger ¶ added in v0.0.2
func WithNetDelay ¶ added in v0.0.2
Set max network delay time duration used as connection write timeout, event callback ticker timeout suggest range: 1*time.Second <= t <= 5*time.Second valid range: 100*time.Milliseconds <= t <= 10*time.Second