server

package
v0.0.0-...-3657bf1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Standalone elementType = iota
	Block
	Inline
)
View Source
const MAX_UPLOAD_SIZE = 1000000
View Source
const SAFE_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

Variables

View Source
var H1RE = regexp.MustCompile(`^\s*# (.*)\n`)
View Source
var TimeoutError = errors.New("timeout waiting for future")

Functions

func DbGetPackageLatestVersion

func DbGetPackageLatestVersion(name string) (string, error)

func DbPutFile

func DbPutFile(id string, version *Version) error

func DbPutPackage

func DbPutPackage(name string, packageInfo *PackageInfo, expireTime time.Time) error

func DbPutVersion

func DbPutVersion(name string, versionRaw string, version *Version, expireTime time.Time) error

func DbPutVulnerability

func DbPutVulnerability(vulnerability Vulnerability) error

func HasMatchingVersion

func HasMatchingVersion(versions []string, constraint *semver.Constraints) bool

func Migrate

func Migrate(migrations []Migration)

func PanicRecovery

func PanicRecovery(handler http.Handler) http.Handler

func ReadConfig

func ReadConfig(path string)

func RenderNode

func RenderNode(node Node) string

func RenderText

func RenderText(node Node) string

func SendError

func SendError(subj string, body string)

func Serve

func Serve(publicFs fs.FS)

func SetupDb

func SetupDb()

func UpdateVulnerabilities

func UpdateVulnerabilities()

func WriteHtml

func WriteHtml(node Node, writer http.ResponseWriter)

func WriteHtmlWithStatus

func WriteHtmlWithStatus(node Node, status int, writer http.ResponseWriter)

Types

type AppConfig

type AppConfig struct {
	Database DbConfig
	Mail     MailConfig
	Pages    PagesConfig
	Server   ServerConfig
}
var Config AppConfig

type Data

type Data interface{}

type DbConfig

type DbConfig struct {
	Source string
}

type Dist

type Dist struct {
	FileCount    int   `json:"fileCount"`
	UnpackedSize int64 `json:"unpackedSize"`
}

type DistTags

type DistTags struct {
	Latest string `json:"latest"`
}

type Element

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

func H

func H(h string, p ...interface{}) *Element

func (*Element) Add

func (t *Element) Add(params ...interface{}) *Element

func (*Element) Attr

func (t *Element) Attr(key, value string) *Element

func (*Element) WriteTextTo

func (t *Element) WriteTextTo(b *strings.Builder)

func (*Element) WriteTo

func (t *Element) WriteTo(b *strings.Builder, indent int)

type ElementAttr

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

func Attr

func Attr(key, value string) ElementAttr

type FilePerformer

type FilePerformer struct{}

func (FilePerformer) Get

func (p FilePerformer) Get(id string) Data

func (FilePerformer) Perform

func (p FilePerformer) Perform(id string) Result

func (FilePerformer) Put

func (p FilePerformer) Put(id string, data Data)

type FileRow

type FileRow struct {
	Id      string
	Content string
}

type Future

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

THREAD SAFE

func NewFuture

func NewFuture() *Future

func NewFutureResolved

func NewFutureResolved(result Result) *Future

func (*Future) Await

func (f *Future) Await() Result

func (*Future) AwaitTimeout

func (f *Future) AwaitTimeout(d time.Duration) Result

func (*Future) Resolve

func (f *Future) Resolve(result Result) *Future

type IntEntries

type IntEntries []IntEntry

func (IntEntries) Len

func (l IntEntries) Len() int

func (IntEntries) Less

func (l IntEntries) Less(i, j int) bool

Less sorts descending

func (IntEntries) Swap

func (l IntEntries) Swap(i, j int)

type IntEntry

type IntEntry struct {
	Key   string
	Value int
}

type MailConfig

type MailConfig struct {
	Server   string
	Username string
	Password string
	ErrorTo  string `toml:"error_to"`
}

type Migration

type Migration struct {
	Name string
	Sql  string
}

type MigrationRow

type MigrationRow struct {
	Name string
	Time time.Time
}

type Node

type Node interface {
	WriteTo(b *strings.Builder, indent int)

	// mainly for multipart mail
	WriteTextTo(b *strings.Builder)
}

func ErrorView

func ErrorView(title string, err string, trace string) Node

func HomeView

func HomeView() Node

func Layout

func Layout(title string, content Node) Node

func PageView

func PageView(page Page) Node

func RenderTabs

func RenderTabs(tabs []Tab) Node

func VersionView

func VersionView(version *Version) Node

func WaitView

func WaitView(name string) Node

type NpmUser

type NpmUser struct {
	Name  string `json:"name"`
	Email string `json:"email"`
}

type PackageInfo

type PackageInfo struct {
	Name     string                 `json:"name"`
	DistTags DistTags               `json:"dist-tags"`
	Versions map[string]VersionInfo `json:"versions"`
	Time     map[string]time.Time   `json:"time"`
}

func DbGetPackage

func DbGetPackage(name string) (*PackageInfo, error)

func GetPackageInfo

func GetPackageInfo(name string) (*PackageInfo, error)

func GetPackageInfoRegistry

func GetPackageInfoRegistry(name string) (*PackageInfo, error)

func (*PackageInfo) GatherDependencies

func (p *PackageInfo) GatherDependencies(versionRaw string) (*Version, error)

func (*PackageInfo) LatestTime

func (p *PackageInfo) LatestTime() time.Time

func (*PackageInfo) LatestVersion

func (p *PackageInfo) LatestVersion() VersionInfo

func (*PackageInfo) MaxVersion

func (p *PackageInfo) MaxVersion(constraintRaw string) (VersionInfo, error)

type PackageInfoPerformer

type PackageInfoPerformer struct{}

func (PackageInfoPerformer) Get

func (p PackageInfoPerformer) Get(name string) Data

func (PackageInfoPerformer) Perform

func (p PackageInfoPerformer) Perform(name string) Result

func (PackageInfoPerformer) Put

func (p PackageInfoPerformer) Put(name string, data Data)

type PackageRow

type PackageRow struct {
	Name          string
	Info          string
	LatestVersion string `db:"latest_version"`
}

type Page

type Page struct {
	Title   string
	Content string
}

func GetPage

func GetPage(path string) (Page, error)

type PagesConfig

type PagesConfig struct {
	Path    string
	Buttons []string
}

type Result

type Result struct {
	Data  Data
	Error error
}

type SemverSpec

type SemverSpec struct {
	Vulnerable []string `json:"vulnerable"`
}

type ServerConfig

type ServerConfig struct {
	Port int
}

type Severity

type Severity string
const (
	Low      Severity = "low"
	Medium   Severity = "medium"
	High     Severity = "high"
	Critical Severity = "critical"
)

type SmartPerformer

type SmartPerformer interface {
	Get(key string) Data
	Put(key string, data Data)
	Perform(key string) Result
}

type SmartWorkPool

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

THREAD SAFE, because all the fields are thread safe

func NewSmartWorkPool

func NewSmartWorkPool(performer SmartPerformer) *SmartWorkPool

func (*SmartWorkPool) ProcessKey

func (s *SmartWorkPool) ProcessKey(key string) *Future

func (*SmartWorkPool) Start

func (s *SmartWorkPool) Start(n int)

type Stats

type Stats struct {
	Packages           int                `json:"packages"`
	Versions           int                `json:"versions"`
	Files              int                `json:"files"`
	DiskSpace          int64              `json:"diskSpace"`
	VulnerabilityStats VulnerabilityStats `json:"vulnerabilityStats"`
}

type Tab

type Tab struct {
	Title   string
	Id      string
	Content Node
}

type TextNode

type TextNode string

func (TextNode) WriteTextTo

func (t TextNode) WriteTextTo(b *strings.Builder)

func (TextNode) WriteTo

func (t TextNode) WriteTo(b *strings.Builder, indent int)

type UnsafeRawContent

type UnsafeRawContent string

func (UnsafeRawContent) WriteTextTo

func (t UnsafeRawContent) WriteTextTo(b *strings.Builder)

func (UnsafeRawContent) WriteTo

func (t UnsafeRawContent) WriteTo(b *strings.Builder, indent int)

type Version

type Version struct {
	Info            VersionInfo         `json:"info"`
	Time            time.Time           `json:"time"`
	Dependencies    map[string][]string `json:"dependencies"`
	Publishers      map[string]int      `json:"publishers"`
	Vulnerabilities []Vulnerability     `json:"vulnerabilities"`
	Stats           Stats               `json:"stats"`
	Errors          []string            `json:"error"`
}

func DbGetFile

func DbGetFile(id string) (*Version, error)

func DbGetVersion

func DbGetVersion(name string, versionRaw string) (*Version, error)

func GetFile

func GetFile(id string) (*Version, error)

func GetVersion

func GetVersion(name string, version string) (*Version, error)

func NewVersion

func NewVersion(versionInfo VersionInfo, time time.Time) *Version

func (*Version) GatherVulnerabilities

func (v *Version) GatherVulnerabilities() error

type VersionInfo

type VersionInfo struct {
	Name            string            `json:"name"`
	Version         string            `json:"version"`
	Description     string            `json:"description"`
	Homepage        interface{}       `json:"homepage"`
	License         interface{}       `json:"license"`
	Dependencies    map[string]string `json:"dependencies"`
	DevDependencies map[string]string `json:"devDependencies"`
	NpmUser         NpmUser           `json:"_npmUser"`
	Dist            Dist              `json:"dist"`
	Os              []string          `json:"os"`
	Cpu             []string          `json:"cpu"`
}

func (VersionInfo) GatherDependencies

func (p VersionInfo) GatherDependencies(parent *Version, alsoDev bool)

func (VersionInfo) GetPublisher

func (v VersionInfo) GetPublisher() string

func (VersionInfo) MatchPlatform

func (p VersionInfo) MatchPlatform(os string, cpu string) bool

type VersionPerformer

type VersionPerformer struct{}

func (VersionPerformer) Get

func (p VersionPerformer) Get(key string) Data

func (VersionPerformer) Perform

func (p VersionPerformer) Perform(key string) Result

func (VersionPerformer) Put

func (p VersionPerformer) Put(key string, data Data)

type VersionRow

type VersionRow struct {
	Name    string
	Version string
	Content string
}

type Vulnerability

type Vulnerability struct {
	Id              string     `json:"id"`
	PackageManager  string     `json:"packageManager"`
	PackageName     string     `json:"packageName"`
	Title           string     `json:"title"`
	PublicationTime time.Time  `json:"publicationTime"`
	Semver          SemverSpec `json:"semver"`
	Severity        Severity   `json:"severity"`
}

func DbGetVulnerabilitiesForPackages

func DbGetVulnerabilitiesForPackages(packages []string) ([]Vulnerability, error)

func DbLastVulnerability

func DbLastVulnerability() (*Vulnerability, error)

func GetVulnerabilities

func GetVulnerabilities(page int) ([]Vulnerability, error)

type VulnerabilityResponse

type VulnerabilityResponse struct {
	Status          string          `json:"status"`
	Vulnerabilities []Vulnerability `json:"vulnerabilities"`
}

type VulnerabilityRow

type VulnerabilityRow struct {
	Id              string
	Name            string
	Title           string
	PublicationTime string `db:"publication_time"`
	Semver          []byte
	Severity        string
}

type VulnerabilityStats

type VulnerabilityStats struct {
	LowCount      int `json:"lowCount"`
	MediumCount   int `json:"mediumCount"`
	HighCount     int `json:"highCount"`
	CriticalCount int `json:"criticalCount"`
}

func GetVulnerabilityStats

func GetVulnerabilityStats(vulnerabilities []Vulnerability) VulnerabilityStats

Jump to

Keyboard shortcuts

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