server

package
v0.0.0-...-5ab47d9 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APIGroupNVD = "/nvd"

	APIPathGetCVE = "/cve"
	APIPathGetCPE = "/cpe"

	APIPathReady = "/readiness"

	// Status... are variables that shows the status for API
	// Since api returns 200 for both 'found' and 'not_found' instead of 404,
	// it should be another field to inform the status from DB
	StatusFound    = "found"
	StatusNotFound = "not_found"
	StatusError    = "error"

	// Qs... are keys of query string that are valid for API
	QsCveId          = "cveId"
	QsCpeName        = "cpeName"
	QsCpeMatchStr    = "cpeMatchString"
	QsKeyword        = "keywordSearch"
	QsKeywordExact   = "keywordExactMatch"
	QsStartIndex     = "startIndex"
	QsResultsPerPage = "resultsPerPage"
)
View Source
const (
	// CVEResultsPerPage is the default resultsPerPage for NVD CVE API
	CVEResultsPerPage = 2000

	// CPEResultsPerPage is the default resultsPerPage for NVD CPE API
	// The document declares with 5000 while it is actually 10000
	CPEResultsPerPage = 10000
)

Variables

View Source
var (
	// CVEQSKeys is the keys of query string. It's expected to provide one of them for CVE API
	CVEQSKeys = []string{QsCveId, QsCpeName, QsKeyword}

	// CPEQSKeys is the keys of query string. It's expected to provide one of them for CPE API
	CPEQSKeys = []string{QsCpeMatchStr, QsCpeName, QsKeyword}
)
View Source
var ErrStop = errors.New("stop server")

Functions

func MetricMiddleware

func MetricMiddleware() gin.HandlerFunc

func MetricRegister

func MetricRegister(registerer prometheus.Registerer)

MetricRegister register metrics when server starts

func MetricRegisterOn

func MetricRegisterOn(registerer prometheus.Registerer)

MetricRegisterOn register needed promutheus metrics on given registerer

func MetricUnRegister

func MetricUnRegister(registerer prometheus.Registerer)

MetricUnRegister unregister metrics when server shutdown

func MetricUnRegisterFrom

func MetricUnRegisterFrom(registerer prometheus.Registerer)

MetricUnRegisterFrom unregister metrics from registerer

Types

type Controller

type Controller interface {
	Register(*gin.RouterGroup, ...gin.HandlerFunc)
}

Controller is the interface to implement a router group which is registered to *gin.Engine with Register function

type NvdController

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

NvdController is the controller to handle requests from asking NVD information

func NewNvdController

func NewNvdController(subGrpName string, dbCli NvdDB) (*NvdController, error)

NewNvdController initializes controller, and the return instance provides what the handler needs (E.g., db and queue client)

func (NvdController) Register

func (h NvdController) Register(grp *gin.RouterGroup, hdlFuncs ...gin.HandlerFunc)

Register implements Controller interface to register group of Routes to gin Engine

type NvdDB

type NvdDB interface {
	db.DB
	db.NvdCveDB
	db.NvdCpeDB
}

NvdDB defines the interface that NvdController needs to handle requests

type Options

type Options func(*Server) error

func AccessLogger

func AccessLogger(logger *zap.Logger) Options

func Controllers

func Controllers(cs ...Controller) Options

func ErrorLogger

func ErrorLogger(logger *zap.Logger) Options

func Registry

func Registry(reg *prometheus.Registry) Options

type Server

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

func New

func New(lisAddr, metricsAddr string, opts ...Options) (*Server, error)

func (*Server) FullyStopped

func (s *Server) FullyStopped()

FullyStopped wait for server to be fully killed, which is use in testing to avoid data race in metrics

func (*Server) Start

func (s *Server) Start(ctx context.Context)

Start starts the server and wait for stop signal

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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