http

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package http is a pgSCV http helper

Package http is a pgSCV http helper

Index

Constants

View Source
const (
	// Code 200
	StatusOK = http.StatusOK
	// Code 400
	StatusBadRequest = http.StatusBadRequest
	// Code 401
	StatusUnauthorized = http.StatusUnauthorized
	// Code 404
	StatusNotFound = http.StatusNotFound
)

Status code

Variables

This section is empty.

Functions

func TestFileServer

func TestFileServer(_ *testing.T, dir string) *httptest.Server

TestFileServer create http test server

func TestServer

func TestServer(t *testing.T, code int, response string) *httptest.Server

TestServer create http test server

Types

type AuthConfig

type AuthConfig struct {
	EnableAuth bool   // flag tells about authentication should be enabled
	Username   string `yaml:"username"` // username used for basic authentication
	Password   string `yaml:"password"` // password used for basic authentication
	EnableTLS  bool   // flag tells about TLS should be enabled
	Keyfile    string `yaml:"keyfile"`  // path to key file
	Certfile   string `yaml:"certfile"` // path to certificate file
}

AuthConfig defines configuration settings for authentication.

func (AuthConfig) Validate

func (cfg AuthConfig) Validate() (bool, bool, error)

Validate check authentication options of AuthConfig and returns toggle flags.

type Client

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

Client defines local wrapper on standard http.Client.

func NewClient

func NewClient(cfg ClientConfig) *Client

NewClient creates new HTTP client.

func (*Client) Do

func (cl *Client) Do(req *http.Request) (*http.Response, error)

Do wraps a standard http.Do method which sends an HTTP request and returns an HTTP response.

func (*Client) EnableTLSInsecure

func (cl *Client) EnableTLSInsecure()

EnableTLSInsecure enables insecure TLS transport for HTTP client.

func (*Client) Get

func (cl *Client) Get(url string) (*http.Response, error)

Get wraps a standard http.Get method which issues a GET to the specified URL.

type ClientConfig

type ClientConfig struct {
	Timeout time.Duration
}

ClientConfig defines initial configuration when creating Client.

type Server

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

Server defines HTTP server.

func NewServer

func NewServer(cfg ServerConfig,
	handlerMetrics func(http.ResponseWriter, *http.Request),
	targetsMetrics func(http.ResponseWriter, *http.Request),
) *Server

NewServer creates new HTTP server instance.

func (*Server) Serve

func (s *Server) Serve() error

Serve method starts listening and serving requests.

type ServerConfig

type ServerConfig struct {
	Addr string
	AuthConfig
}

ServerConfig defines HTTP server configuration.

Jump to

Keyboard shortcuts

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