Documentation
¶
Index ¶
- Variables
- func APIKeyMiddleware(apiKey string) func(http.Handler) http.Handler
- func BasicAuthMiddleware(username, password string) func(http.Handler) http.Handler
- func GetAPIHandlers(customBaseAPIPath ...string) map[string]http.HandlerFunc
- func GetFiberHandler(customBaseAPIPath ...string) func(*fiber.Ctx) error
- func GetSecuredAPIHandlers(m *Monigo, customBaseAPIPath ...string) map[string]http.HandlerFunc
- func GetSecuredStaticHandler(m *Monigo) http.HandlerFunc
- func GetSecuredUnifiedHandler(m *Monigo, customBaseAPIPath ...string) http.HandlerFunc
- func GetStaticHandler() http.HandlerFunc
- func GetUnifiedHandler(customBaseAPIPath ...string) http.HandlerFunc
- func IPWhitelistMiddleware(allowedIPs []string) func(http.Handler) http.Handler
- func LoggingMiddleware() func(http.Handler) http.Handler
- func RateLimitMiddleware(requests int, window time.Duration) func(http.Handler) http.Handler
- func RegisterAPIHandlers(mux *http.ServeMux, customBaseAPIPath ...string)
- func RegisterDashboardHandlers(mux *http.ServeMux, customBaseAPIPath ...string)
- func RegisterSecuredAPIHandlers(mux *http.ServeMux, m *Monigo, customBaseAPIPath ...string)
- func RegisterSecuredDashboardHandlers(mux *http.ServeMux, m *Monigo, customBaseAPIPath ...string)
- func RegisterSecuredStaticHandlers(mux *http.ServeMux, m *Monigo)
- func RegisterStaticHandlers(mux *http.ServeMux)
- func StartDashboard(port int) error
- func StartDashboardWithCustomPath(port int, customBaseAPIPath string) error
- func StartSecuredDashboard(m *Monigo) error
- func TraceFunction(f func())
- func TraceFunctionWithArgs(f interface{}, args ...interface{})
- func TraceFunctionWithReturn(f interface{}, args ...interface{}) interface{}
- func TraceFunctionWithReturns(f interface{}, args ...interface{}) []interface{}
- type Cache
- type Monigo
- type MonigoBuilder
- func (b *MonigoBuilder) Build() *Monigo
- func (b *MonigoBuilder) WithAPIMiddleware(middleware ...func(http.Handler) http.Handler) *MonigoBuilder
- func (b *MonigoBuilder) WithAuthFunction(authFunc func(*http.Request) bool) *MonigoBuilder
- func (b *MonigoBuilder) WithCustomBaseAPIPath(path string) *MonigoBuilder
- func (b *MonigoBuilder) WithDashboardMiddleware(middleware ...func(http.Handler) http.Handler) *MonigoBuilder
- func (b *MonigoBuilder) WithDataPointsSyncFrequency(frequency string) *MonigoBuilder
- func (b *MonigoBuilder) WithMaxCPUUsage(usage float64) *MonigoBuilder
- func (b *MonigoBuilder) WithMaxGoRoutines(routines int) *MonigoBuilder
- func (b *MonigoBuilder) WithMaxMemoryUsage(usage float64) *MonigoBuilder
- func (b *MonigoBuilder) WithPort(port int) *MonigoBuilder
- func (b *MonigoBuilder) WithRetentionPeriod(period string) *MonigoBuilder
- func (b *MonigoBuilder) WithServiceName(serviceName string) *MonigoBuilder
- func (b *MonigoBuilder) WithTimeZone(timeZone string) *MonigoBuilder
- type MonigoInt
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func APIKeyMiddleware ¶ added in v1.1.0
APIKeyMiddleware creates an API key authentication middleware Usage: monigo.APIKeyMiddleware("your-secret-api-key")
func BasicAuthMiddleware ¶ added in v1.1.0
BasicAuthMiddleware creates a basic authentication middleware Usage: monigo.BasicAuthMiddleware("admin", "password")
func GetAPIHandlers ¶ added in v1.1.0
func GetAPIHandlers(customBaseAPIPath ...string) map[string]http.HandlerFunc
GetAPIHandlers returns a map of API handlers that can be registered to any HTTP router This provides maximum flexibility for integration with different router libraries
func GetFiberHandler ¶ added in v1.1.0
GetFiberHandler returns a Fiber-compatible handler that handles both API and static files This is specifically designed for Fiber framework integration
func GetSecuredAPIHandlers ¶ added in v1.1.0
func GetSecuredAPIHandlers(m *Monigo, customBaseAPIPath ...string) map[string]http.HandlerFunc
GetSecuredAPIHandlers returns a map of API handlers with middleware support
func GetSecuredStaticHandler ¶ added in v1.1.0
func GetSecuredStaticHandler(m *Monigo) http.HandlerFunc
GetSecuredStaticHandler returns the static file handler with middleware support
func GetSecuredUnifiedHandler ¶ added in v1.1.0
func GetSecuredUnifiedHandler(m *Monigo, customBaseAPIPath ...string) http.HandlerFunc
GetSecuredUnifiedHandler returns a unified handler with middleware support for both API and static files This is the recommended way to integrate MoniGo with security middleware
func GetStaticHandler ¶ added in v1.1.0
func GetStaticHandler() http.HandlerFunc
GetStaticHandler returns the static file handler function This can be used to register static file serving to any HTTP router
func GetUnifiedHandler ¶ added in v1.1.0
func GetUnifiedHandler(customBaseAPIPath ...string) http.HandlerFunc
GetUnifiedHandler returns a unified handler that handles both API and static files This is the recommended way to integrate MoniGo with any HTTP router
func IPWhitelistMiddleware ¶ added in v1.1.0
IPWhitelistMiddleware creates an IP whitelist middleware Usage: monigo.IPWhitelistMiddleware([]string{"127.0.0.1", "192.168.1.0/24"})
func LoggingMiddleware ¶ added in v1.1.0
LoggingMiddleware creates a request logging middleware
func RateLimitMiddleware ¶ added in v1.1.0
RateLimitMiddleware creates a simple rate limiting middleware Usage: monigo.RateLimitMiddleware(100, time.Minute) // 100 requests per minute
func RegisterAPIHandlers ¶ added in v1.1.0
RegisterAPIHandlers registers only the API handlers to the provided HTTP mux This is useful when developers want to handle static file serving themselves
func RegisterDashboardHandlers ¶ added in v1.1.0
RegisterDashboardHandlers registers all dashboard handlers (both API and static files) to the provided HTTP mux This allows developers to integrate MoniGo dashboard into their existing HTTP server
func RegisterSecuredAPIHandlers ¶ added in v1.1.0
RegisterSecuredAPIHandlers registers only the API handlers with middleware support to the provided HTTP mux This is useful when developers want to handle static file serving themselves but need API security
func RegisterSecuredDashboardHandlers ¶ added in v1.1.0
RegisterSecuredDashboardHandlers registers all dashboard handlers with middleware support to the provided HTTP mux This allows developers to integrate MoniGo dashboard with security middleware into their existing HTTP server
func RegisterSecuredStaticHandlers ¶ added in v1.1.0
RegisterSecuredStaticHandlers registers only the static file handlers with middleware support to the provided HTTP mux This is useful when developers want to handle API routing themselves but need static file security
func RegisterStaticHandlers ¶ added in v1.1.0
RegisterStaticHandlers registers only the static file handlers to the provided HTTP mux This is useful when developers want to handle API routing themselves
func StartDashboard ¶
StartDashboard starts the dashboard on the specified port
func StartDashboardWithCustomPath ¶ added in v1.1.0
StartDashboardWithCustomPath starts the dashboard on the specified port with a custom API path
func StartSecuredDashboard ¶ added in v1.1.0
StartSecuredDashboard starts the dashboard with middleware support
func TraceFunction ¶ added in v0.0.2
func TraceFunction(f func())
TraceFunction traces the function This is the original function maintained for backward compatibility
func TraceFunctionWithArgs ¶ added in v1.1.0
func TraceFunctionWithArgs(f interface{}, args ...interface{})
TraceFunctionWithArgs traces a function with parameters and captures the metrics This function uses reflection to call functions with arbitrary signatures Example usage:
func processUser(userID string) { ... }
monigo.TraceFunctionWithArgs(processUser, "123")
func TraceFunctionWithReturn ¶ added in v1.1.0
func TraceFunctionWithReturn(f interface{}, args ...interface{}) interface{}
TraceFunctionWithReturn traces a function with parameters and return values Returns the first result of the function call (for backward compatibility) Example usage:
func calculateTotal(items []Item) int { ... }
result := monigo.TraceFunctionWithReturn(calculateTotal, items)
func TraceFunctionWithReturns ¶ added in v1.1.0
func TraceFunctionWithReturns(f interface{}, args ...interface{}) []interface{}
TraceFunctionWithReturns traces a function with parameters and return values Returns all results of the function call as a slice of interface{} Example usage:
func processData(data []byte) (Result, error) { ... }
results := monigo.TraceFunctionWithReturns(processData, data)
result := results[0].(Result)
err := results[1].(error)
Types ¶
type Monigo ¶
type Monigo struct {
ServiceName string `json:"service_name"` // Mandatory field ex. "backend", "OrderAPI", "PaymentService", etc.
DashboardPort int `json:"dashboard_port"` // Default is 8080
DataPointsSyncFrequency string `json:"db_sync_frequency"` // Default is 5 Minutes
DataRetentionPeriod string `json:"retention_period"` // Default is 7 Day
TimeZone string `json:"time_zone"` // Default is Local
GoVersion string `json:"go_version"` // Dynamically set from runtime.Version()
ServiceStartTime time.Time `json:"service_start_time"` // Dynamically setting it based on the service start time
ProcessId int32 `json:"process_id"` // Dynamically set from os.Getpid()
MaxCPUUsage float64 `json:"max_cpu_usage"` // Default is 95%, You can set it to 100% if you want to monitor 100% CPU usage
MaxMemoryUsage float64 `json:"max_memory_usage"` // Default is 95%, You can set it to 100% if you want to monitor 100% Memory usage
MaxGoRoutines int `json:"max_go_routines"` // Default is 100, You can set it to any number based on your service
CustomBaseAPIPath string `json:"custom_base_api_path"` // Custom base API path for integration with existing routers
// Security and Middleware Configuration
DashboardMiddleware []func(http.Handler) http.Handler `json:"-"` // Middleware chain for dashboard access (static files)
APIMiddleware []func(http.Handler) http.Handler `json:"-"` // Middleware chain for API endpoints
AuthFunction func(*http.Request) bool `json:"-"` // Simple authentication function for dashboard access
}
Monigo is the main struct to start the monigo service
func (*Monigo) GetGoRoutinesStats ¶ added in v0.0.2
func (m *Monigo) GetGoRoutinesStats() models.GoRoutinesStatistic
GetGoRoutinesStats get back the Go routines stats from the core package
func (*Monigo) GetRuningPort ¶ added in v1.2.0
GetRuningPort returns the running port
func (*Monigo) Initialize ¶ added in v1.1.0
Initialize initializes the monigo service without starting the dashboard This is useful when you want to integrate MoniGo with your existing HTTP server
func (*Monigo) MonigoInstanceConstructor ¶ added in v0.0.2
MonigoInstanceConstructor is the constructor for the Monigo struct
func (*Monigo) MonigoInstanceConstructorWithoutPort ¶ added in v1.1.0
func (m *Monigo) MonigoInstanceConstructorWithoutPort()
MonigoInstanceConstructorWithoutPort is the constructor for the Monigo struct without port binding This is used for router integration where we don't want MoniGo to bind to any port
type MonigoBuilder ¶ added in v1.2.0
type MonigoBuilder struct {
// contains filtered or unexported fields
}
MonigoBuilder is the builder for the Monigo struct
func NewBuilder ¶ added in v1.2.0
func NewBuilder() *MonigoBuilder
NewBuilder creates a new instance of the MonigoBuilder
func (*MonigoBuilder) Build ¶ added in v1.2.0
func (b *MonigoBuilder) Build() *Monigo
Build builds the Monigo struct
func (*MonigoBuilder) WithAPIMiddleware ¶ added in v1.2.0
func (b *MonigoBuilder) WithAPIMiddleware(middleware ...func(http.Handler) http.Handler) *MonigoBuilder
WithAPIMiddleware sets the API middleware
func (*MonigoBuilder) WithAuthFunction ¶ added in v1.2.0
func (b *MonigoBuilder) WithAuthFunction(authFunc func(*http.Request) bool) *MonigoBuilder
WithAuthFunction sets the custom authentication function
func (*MonigoBuilder) WithCustomBaseAPIPath ¶ added in v1.2.0
func (b *MonigoBuilder) WithCustomBaseAPIPath(path string) *MonigoBuilder
WithCustomBaseAPIPath sets the custom base API path
func (*MonigoBuilder) WithDashboardMiddleware ¶ added in v1.2.0
func (b *MonigoBuilder) WithDashboardMiddleware(middleware ...func(http.Handler) http.Handler) *MonigoBuilder
WithDashboardMiddleware sets the dashboard middleware
func (*MonigoBuilder) WithDataPointsSyncFrequency ¶ added in v1.2.0
func (b *MonigoBuilder) WithDataPointsSyncFrequency(frequency string) *MonigoBuilder
WithDataPointsSyncFrequency sets the data points sync frequency
func (*MonigoBuilder) WithMaxCPUUsage ¶ added in v1.2.0
func (b *MonigoBuilder) WithMaxCPUUsage(usage float64) *MonigoBuilder
WithMaxCPUUsage sets the max CPU usage
func (*MonigoBuilder) WithMaxGoRoutines ¶ added in v1.2.0
func (b *MonigoBuilder) WithMaxGoRoutines(routines int) *MonigoBuilder
WithMaxGoRoutines sets the max Go routines
func (*MonigoBuilder) WithMaxMemoryUsage ¶ added in v1.2.0
func (b *MonigoBuilder) WithMaxMemoryUsage(usage float64) *MonigoBuilder
WithMaxMemoryUsage sets the max memory usage
func (*MonigoBuilder) WithPort ¶ added in v1.2.0
func (b *MonigoBuilder) WithPort(port int) *MonigoBuilder
WithPort sets the dashboard port
func (*MonigoBuilder) WithRetentionPeriod ¶ added in v1.2.0
func (b *MonigoBuilder) WithRetentionPeriod(period string) *MonigoBuilder
WithRetentionPeriod sets the data retention period
func (*MonigoBuilder) WithServiceName ¶ added in v1.2.0
func (b *MonigoBuilder) WithServiceName(serviceName string) *MonigoBuilder
WithServiceName sets the service name
func (*MonigoBuilder) WithTimeZone ¶ added in v1.2.0
func (b *MonigoBuilder) WithTimeZone(timeZone string) *MonigoBuilder
WithTimeZone sets the time zone
type MonigoInt ¶
type MonigoInt interface {
Start() error // Start the monigo service with dashboard
Initialize() error // Initialize monigo without starting dashboard
GetGoRoutinesStats() models.GoRoutinesStatistic // Print the Go routines stats
}
MonigoInt is the interface to start the monigo service