Documentation
¶
Overview ¶
Package domain holds the entities, value objects and signal rules of Arnakoff. It is pure Go: no I/O, no clock and no logging (ADR 0002).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidDomain means the input is not a domain name or a web URL. ErrInvalidDomain = errors.New("invalid domain") // ErrUnsupportedScheme means the input is a URL whose scheme is neither // http nor https. ErrUnsupportedScheme = fmt.Errorf("%w: unsupported URL scheme", ErrInvalidDomain) // ErrIPAddress means the host is an IP address, not a domain name. ErrIPAddress = fmt.Errorf("%w: IP address", ErrInvalidDomain) )
Domain errors. ErrUnsupportedScheme and ErrIPAddress also match ErrInvalidDomain with errors.Is.
Functions ¶
func FormatDate ¶
FormatDate formats t as a French date, JJ/MM/AAAA, in t's own location. The caller picks the location (Europe/Paris for user-facing dates): the domain loads no time zone data.
Types ¶
type Domain ¶ added in v0.2.0
type Domain struct {
// contains filtered or unexported fields
}
Domain is a normalised domain name: lower case, A-labels, no final dot. The zero value is not a valid domain.
func ParseDomain ¶ added in v0.2.0
ParseDomain normalises a domain name or a web URL, as a user would paste it, into a Domain. A URL keeps its host only: credentials before the host are dropped, as a browser does ("https://amf-france.org@exemple.com" is exemple.com). Only http and https URLs are accepted, and IP addresses are reported with ErrIPAddress.
func (Domain) Registrable ¶ added in v0.2.0
Registrable returns the public suffix plus one label, the part a registrant controls: "groupe-ytria.com" for www.groupe-ytria.com, "atos-limited.co.uk" for www.atos-limited.co.uk. Private suffixes of the Public Suffix List count, so arnaque.github.io is its own registrable domain.
type Level ¶
type Level int
Level is the severity of a signal. Levels are ordered: a greater Level is more severe, so levels compare with the usual operators. The zero value is not a valid level.
const ( // LevelInfo is a neutral fact worth knowing. LevelInfo Level = iota + 1 // LevelAttention is a heuristic that calls for a check before acting. LevelAttention // LevelAlert is a fact an authority published, such as a blacklist entry. LevelAlert )
Signal levels, from the least to the most severe.
type Report ¶
type Report struct {
// contains filtered or unexported fields
}
Report is the result of checking one input: its signals, most severe first, and the state of each source consulted. A Report is immutable: its accessors return copies.
func NewReport ¶
func NewReport(input string, signals []Signal, sources []SourceState) Report
NewReport builds the report for the normalised input. Signals are sorted by level, most severe first; signals of equal level keep their order. The slices are copied, the caller's are left untouched.
func (Report) Sources ¶
func (r Report) Sources() []SourceState
Sources returns a copy of the state of each source.
type Signal ¶
type Signal struct {
// Code is the stable snake_case identifier of the rule, such as
// "amf_blacklist". It is part of the public contract.
Code string
// Level is the severity of the signal.
Level Level
// Message is one factual French sentence stating what was observed.
Message string
// Advice is an optional French sentence telling the user what to do.
Advice string
// Source is the upstream source the fact comes from.
Source Source
// SourceURL is the public page where the fact can be checked.
SourceURL string
// ObservedAt is when the fact was read from the source.
ObservedAt time.Time
}
Signal is one sourced fact about a checked input. Every field but Advice is set: a signal without its source and observation date is not published.
type Source ¶
type Source string
Source names an upstream data source, as shown to users ("AMF", "SIRENE").
type SourceState ¶
type SourceState struct {
Source Source
Status SourceStatus
}
SourceState is the status of one source in a report.
type SourceStatus ¶
type SourceStatus int
SourceStatus tells how a source took part in a check. The zero value is not a valid status.
const ( // SourceOK means the source was consulted. SourceOK SourceStatus = iota + 1 // of a signal from it proves nothing. SourceUnavailable // SourceNotApplicable means the source does not cover this input type. SourceNotApplicable )
Source statuses.
func (SourceStatus) String ¶
func (s SourceStatus) String() string
String returns the status's stable French code: "ok", "indisponible" or "non applicable".