http

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: GPL-3.0 Imports: 35 Imported by: 0

Documentation

Overview

Package http implements the HTTP server handlers for different resource endpoints

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMaxQueryWindow     = errors.New("maximum query window exceeded")
	ErrMalformedTimeStamp = errors.New("malformed timestamp")
)

Functions

func Querier

func Querier[T any](ctx context.Context, dbConn *sql.DB, query Query, logger *slog.Logger) ([]T, error)

Querier queries the DB and return the response.

func VerifyOwnership

func VerifyOwnership(
	ctx context.Context,
	user string,
	clusterIDs []string,
	uuids []string,
	starts []int64,
	db *sql.DB,
	logger *slog.Logger,
) bool

VerifyOwnership returns true if user is the owner of queried units.

Types

type CEEMSServer

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

CEEMSServer struct implements HTTP server for stats.

func New added in v0.2.0

func New(c *Config) (*CEEMSServer, func(), error)

New creates new CEEMSServer struct instance.

func (*CEEMSServer) Shutdown

func (s *CEEMSServer) Shutdown(ctx context.Context) error

Shutdown server.

func (*CEEMSServer) Start

func (s *CEEMSServer) Start() error

Start launches CEEMS HTTP server godoc

@title			CEEMS API
@version		1.0
@description	OpenAPI specification (OAS) for the CEEMS REST API.
@description
@description	See the Interactive Docs to try CEEMS API methods without writing code, and get
@description	the complete schema of resources exposed by the API.
@description
@description	If basic auth is enabled, all the endpoints require authentication.
@description
@description	All the endpoints, except `health`, `swagger`, `debug` and `demo`,
@description	must send a user-agent header.
@description
@description				Timestamps must be specified in milliseconds, unless otherwise specified.

@contact.name				Mahendra Paipuri
@contact.url				https://github.com/mahendrapaipuri/ceems/issues
@contact.email				mahendra.paipuri@gmail.com

@license.name				GPL-3.0 license
@license.url				https://www.gnu.org/licenses/gpl-3.0.en.html

@securityDefinitions.basic	BasicAuth

@externalDocs.url			https://mahendrapaipuri.github.io/ceems/

type Config

type Config struct {
	Logger *slog.Logger
	Web    WebConfig
	DB     db.Config
}

Config makes a server config.

type Query

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

Query builder struct.

type Response

type Response[T any] struct {
	Status    string    `json:"status"`
	Data      []T       `json:"data"`
	ErrorType errorType `json:"errorType,omitempty"`
	Error     string    `json:"error,omitempty"`
	Warnings  []string  `json:"warnings,omitempty"`
}

Response defines the response model of CEEMSAPIServer.

type WebConfig

type WebConfig struct {
	Addresses        []string
	WebSystemdSocket bool
	WebConfigFile    string
	RoutePrefix      string                  `yaml:"route_prefix"`
	MaxQueryPeriod   model.Duration          `yaml:"max_query"`
	RequestsLimit    int                     `yaml:"requests_limit"`
	URL              string                  `yaml:"url"`
	HTTPClientConfig config.HTTPClientConfig `yaml:",inline"`
}

WebConfig makes HTTP web config from CLI args.

func (*WebConfig) UnmarshalYAML added in v0.5.2

func (c *WebConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

Directories

Path Synopsis
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.

Jump to

Keyboard shortcuts

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