http

package
v0.24.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine struct {
	PORT   string   // The port number for the engine.
	DOMAIN string   // The domain of the engine.
	SUBS   []string // The subdomains of the engine.
	// contains filtered or unexported fields
}

Engine represents an HTTP engine. It is responsible for managing network listeners and the HTTP server for either standard or secure connections, keeping track of its running status and configuration details like port, domain, and subdomains.

func (*Engine) Start

func (e *Engine) Start() error

Start starts the HTTP engine, allowing it to accept incoming connections. This method initiates the listening process on the specified port and handles incoming requests.

Returns: - error: An error if any.

func (*Engine) Stop

func (e *Engine) Stop() error

Stop stops the HTTP engine. It terminates the listening process and stops the server from accepting new connections.

Returns: - error: An error if any.

type HTTPClient

type HTTPClient struct {
	// contains filtered or unexported fields
}

HTTPClient represents an HTTP client. It encapsulates the functionality for sending HTTP requests and receiving responses, handling underlying client and transport configurations.

func NewHTTPClient

func NewHTTPClient() *HTTPClient

NewHTTPClient initializes a new HTTPClient and returns its pointer. This function sets up the HTTP client with a custom transport configuration, including TLS settings and default timeout.

Returns: - *HTTPClient: A pointer to the newly created HTTPClient.

func (*HTTPClient) Send

Send sends an HTTP request and returns the HTTP response. This method constructs and sends an HTTP request based on the provided transport request, handling headers, method, endpoint, and body. It also processes the received HTTP response, extracting status, headers, and body.

Parameters: - req: *generated.Request The HTTP request to be sent.

Returns: - *generated.Response: The HTTP response received.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents an HTTP server that handles both standard and secure connections. It encapsulates the functionality of two engines, one for handling standard HTTP connections and the other for secure HTTPS connections, along with a router for API routing.

func NewServer

func NewServer(cfg *ServerCfg) *Server

NewServer creates a new HTTP server based on the provided configuration. It initializes a standard and, if specified, a secure engine based on the server configuration.

Parameters: - cfg: *ServerCfg Configuration data for the HTTP server.

Returns: - *Server: A new HTTP server. - error: An error if any.

func (*Server) HTTPHandler added in v0.23.24

func (s *Server) HTTPHandler(w http.ResponseWriter, r *http.Request)

HTTPHandler handles HTTP requests and sends back HTTP responses. It processes incoming HTTP requests, creates a corresponding transport request, and uses the router to generate a response. The handler deals with various HTTP methods, reads request bodies if necessary, and writes back responses including headers and status codes.

Parameters: - w: http.ResponseWriter Response writer to send back the HTTP response. - r: *http.Request The incoming HTTP request to be processed.

func (*Server) Register

func (s *Server) Register(api *router.EndPoint)

func (*Server) Start

func (s *Server) Start() error

Start starts the HTTP server, allowing it to accept incoming connections. It checks for any running instances of the server and starts the standard and secure engines.

Returns: - error: An error if any.

func (*Server) Stop

func (s *Server) Stop() error

Stop stops the HTTP server. This method halts the server's operations and stops accepting incoming connections.

Returns: - error: An error if any.

type ServerCfg

type ServerCfg struct {
	DOMAIN string   // The domain of the server.
	SUBS   []string // The subdomains of the server.
	HTTP   string   // The port number for HTTP connections.
	HTTPS  string   // The port number for HTTPS connections.
}

ServerCfg holds configuration data for the HTTP server. This structure includes details such as the server's domain, subdomains, and port numbers for both HTTP and HTTPS connections.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL