Documentation
¶
Overview ¶
Package api provides HTTP REST API functionality for the Scanorama network scanner. It implements endpoints for scanning, discovery, host management, and system status.
Index ¶
- type Config
- type ErrorResponse
- type PaginatedResponse
- type PaginationParams
- type Server
- func (s *Server) GetAddress() string
- func (s *Server) GetPaginationParams(r *http.Request) PaginationParams
- func (s *Server) GetQueryParam(r *http.Request, key, defaultValue string) string
- func (s *Server) GetQueryParamBool(r *http.Request, key string, defaultValue bool) bool
- func (s *Server) GetQueryParamInt(r *http.Request, key string, defaultValue int) (int, error)
- func (s *Server) GetRouter() *mux.Router
- func (s *Server) IsRunning() bool
- func (s *Server) ParseJSON(r *http.Request, v interface{}) error
- func (s *Server) Start(ctx context.Context) error
- func (s *Server) Stop() error
- func (s *Server) ValidateRequest(r *http.Request) error
- func (s *Server) WriteJSON(w http.ResponseWriter, r *http.Request, statusCode int, data interface{})
- func (s *Server) WritePaginatedResponse(w http.ResponseWriter, r *http.Request, data interface{}, ...)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Host string `yaml:"host" json:"host"`
Port int `yaml:"port" json:"port"`
ReadTimeout time.Duration `yaml:"read_timeout" json:"read_timeout"`
WriteTimeout time.Duration `yaml:"write_timeout" json:"write_timeout"`
IdleTimeout time.Duration `yaml:"idle_timeout" json:"idle_timeout"`
MaxHeaderBytes int `yaml:"max_header_bytes" json:"max_header_bytes"`
EnableCORS bool `yaml:"enable_cors" json:"enable_cors"`
CORSOrigins []string `yaml:"cors_origins" json:"cors_origins"`
RateLimitEnabled bool `yaml:"rate_limit_enabled" json:"rate_limit_enabled"`
RateLimitRequests int `yaml:"rate_limit_requests" json:"rate_limit_requests"`
RateLimitWindow time.Duration `yaml:"rate_limit_window" json:"rate_limit_window"`
AuthEnabled bool `yaml:"auth_enabled" json:"auth_enabled"`
APIKeys []string `yaml:"api_keys" json:"api_keys"`
}
Config holds API server configuration.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns default API server configuration.
type ErrorResponse ¶
type ErrorResponse struct {
Error string `json:"error"`
Timestamp time.Time `json:"timestamp"`
RequestID string `json:"request_id,omitempty"`
}
ErrorResponse represents a standard API error response.
type PaginatedResponse ¶
type PaginatedResponse struct {
Data interface{} `json:"data"`
Pagination struct {
Page int `json:"page"`
PageSize int `json:"page_size"`
TotalItems int64 `json:"total_items"`
TotalPages int `json:"total_pages"`
} `json:"pagination"`
}
PaginatedResponse represents a paginated API response.
type PaginationParams ¶
type PaginationParams struct {
Page int `json:"page"`
PageSize int `json:"page_size"`
Offset int `json:"offset"`
}
PaginationParams represents pagination parameters.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents the API server.
func (*Server) GetAddress ¶
GetAddress returns the server address.
func (*Server) GetPaginationParams ¶
func (s *Server) GetPaginationParams(r *http.Request) PaginationParams
GetPaginationParams extracts pagination parameters from request.
func (*Server) GetQueryParam ¶
GetQueryParam gets a query parameter with optional default value.
func (*Server) GetQueryParamBool ¶
GetQueryParamBool gets a boolean query parameter with optional default value.
func (*Server) GetQueryParamInt ¶
GetQueryParamInt gets an integer query parameter with optional default value.
func (*Server) ValidateRequest ¶
ValidateRequest performs basic request validation.
func (*Server) WriteJSON ¶
func (s *Server) WriteJSON(w http.ResponseWriter, r *http.Request, statusCode int, data interface{})
WriteJSON writes a JSON response.
func (*Server) WritePaginatedResponse ¶
func (s *Server) WritePaginatedResponse( w http.ResponseWriter, r *http.Request, data interface{}, params PaginationParams, totalItems int64, )
WritePaginatedResponse writes a paginated response.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package handlers provides HTTP request handlers for the Scanorama API.
|
Package handlers provides HTTP request handlers for the Scanorama API. |
|
Package middleware provides HTTP middleware functions for the Scanorama API server.
|
Package middleware provides HTTP middleware functions for the Scanorama API server. |