Documentation

Overview

    Package api contains the main API to Brawler.

    Index

    Constants

    View Source
    const (
    	ErrorRestAPI       = "Rest API Error"
    	ErrorRumbleParser  = "Rumble Parser Error"
    	ErrorRumbleRuntime = "Rumble Runtime Error"
    )

      Error types for Brawler API

      Variables

      View Source
      var DefaultLogLevel = rumble.LogLevel(rumble.Info)

        DefaultLogLevel is the default log level which is used by every new engine

        View Source
        var EngineSinkDirectories = "sinks"

          EngineSinkDirectories contains initialisation sinks for new engines. All .ram files will be loaded from <EngineSinkDirectories>/<engine name>

          View Source
          var EventSourceEngineCheckTime int64 = 5

            EventSourceEngineCheckTime is the time in seconds an event source waits until it checks again for available engines.

            View Source
            var LogSize = 50

              LogSize is the log size for each created processor

              View Source
              var NewLogWriter = func(engine string) LogWriter {
              	return &MemoryLogWriter{datautil.NewRingBuffer(LogSize)}
              }

                NewLogWriter returns a new log writer instance and is called when a new engine is created.

                View Source
                var ProcessorWorkerCount = 4

                  ProcessorWorkerCount is the worker count for each created processor

                  View Source
                  var Result rumble.LogLevel = "Result"

                    Result is a special log level indicating a result of a manually entered command

                    Functions

                    func EngineExists

                    func EngineExists(name string) bool

                      EngineExists checks if a given engine exists.

                      func GetEngineNames

                      func GetEngineNames() []string

                        GetEngineNames returns all available engine names.

                        func GetEventSourceNames

                        func GetEventSourceNames() []string

                          GetEventSourceNames returns all registered event sources.

                          func RegisterEventSource

                          func RegisterEventSource(name string, engine string) brawler.EventPublisher

                            RegisterEventSource registers a new event source which can inject external events into a Brawler engine. If the engine name is empty then the events are injected into all known engines. It returns an EventPublisher object which should be used by the event source to inject events.

                            func RunRumbleCode

                            func RunRumbleCode(procName, codeName, code string, wg *sync.WaitGroup) (string, error)

                              RunRumbleCode executes a given piece of Rumble code on a named processor. Can receive an optional WaitGroup which is called once all code has finished processing.

                              Types

                              type BrawlerEngine

                              type BrawlerEngine struct {
                              	Proc           engine.Processor           // Actual processor which load rules and processes events
                              	Log            LogWriter                  // Log of the processor
                              	LogLevel       rumble.LogLevel            // LogLevel of this engine
                              	RootVars       parser.VarsScope           // Root variable scope of the engine
                              	EchoNilResults bool                       // Flag if nil results should be echoed (used for consoles)
                              	Sinks          map[string]*parser.ASTNode // Loaded Rumble sinks
                              	// contains filtered or unexported fields
                              }

                                BrawlerEngine is used to define a processing unit in the API.

                                func GetEngine

                                func GetEngine(name string, reset bool) *BrawlerEngine

                                  GetEngine returns a BrawlerEngine of a certain namme. The engine is created if it does not exist. If the reset flag is set then all current loaded sinks are discarded and the default sinks are loaded again.

                                  func (*BrawlerEngine) AddLogMessage

                                  func (re *BrawlerEngine) AddLogMessage(m *LogMessage)

                                    AddLogMessage adds a log message to the log if it meets the current log level of the engine.

                                    func (*BrawlerEngine) DefaultRootMonitorErrorObserver

                                    func (re *BrawlerEngine) DefaultRootMonitorErrorObserver(rm *engine.RootMonitor)

                                      DefaultRootMonitorErrorObserver is the default observer for root monitor errors. The observer logs all encountered errors in the engine's log.

                                      func (*BrawlerEngine) String

                                      func (re *BrawlerEngine) String() string

                                        String returns a string representation of the engine.

                                        type LogMessage

                                        type LogMessage struct {
                                        	MonitorID uint64
                                        	Level     rumble.LogLevel
                                        	Msg       string
                                        }

                                          LogMessage models a single log message

                                          func (*LogMessage) String

                                          func (lm *LogMessage) String() string

                                          type LogWriter

                                          type LogWriter interface {
                                          
                                          	/*
                                          	   Add adds a new log message.
                                          	*/
                                          	Add(*LogMessage)
                                          
                                          	/*
                                          	   Slice returns the contents of the current log as a slice.
                                          	*/
                                          	Slice() []*LogMessage
                                          
                                          	/*
                                          		Resets the current log.
                                          	*/
                                          	Reset()
                                          
                                          	/*
                                          		Size returns the current log size.
                                          	*/
                                          	Size() int
                                          
                                          	/*
                                          		String returns the current log as a string.
                                          	*/
                                          	String() string
                                          }

                                            LogWriter models the log writer for a BrawlerEngine

                                            type MemoryLogWriter

                                            type MemoryLogWriter struct {
                                            	*datautil.RingBuffer
                                            }

                                              MemoryLogWriter is a log writer which writes into a ring buffer in memory.

                                              func (*MemoryLogWriter) Add

                                              func (lw *MemoryLogWriter) Add(m *LogMessage)

                                                Add adds a new log message.

                                                func (*MemoryLogWriter) Reset

                                                func (lw *MemoryLogWriter) Reset()

                                                  Reset resets the current log.

                                                  func (*MemoryLogWriter) Size

                                                  func (lw *MemoryLogWriter) Size() int

                                                    Size returns the current log size.

                                                    func (*MemoryLogWriter) Slice

                                                    func (lw *MemoryLogWriter) Slice() []*LogMessage

                                                      Slice returns the contents of the current log as a slice.

                                                      func (*MemoryLogWriter) String

                                                      func (lw *MemoryLogWriter) String() string

                                                        String returns the current log as a string.

                                                        Directories

                                                        Path Synopsis
                                                        web
                                                        Package web contains general REST API definitions.
                                                        Package web contains general REST API definitions.
                                                        v1
                                                        Package v1 contains Brawler REST API Version 1.
                                                        Package v1 contains Brawler REST API Version 1.