Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
Services []Service
)
Functions ¶
This section is empty.
Types ¶
type Additional ¶
type Additional struct {
Name string `json:"name"`
RegexGroupName string `json:"regex_group_name"`
Lookups []Lookup `json:"lookup"`
}
Additional describes lookup values that may be encoded into the tracking number.
type CheckDigit ¶
type CheckDigit interface {
// Generate calculates a check digit
Generate(seed string) (string, error)
// Validate accepts the serial number and check digit portions of a tracking
// number and validates the serial number.
Validate(serial, code string) bool
}
CheckDigit provides an interface for all check digit algorithms.
func NewMod7 ¶
func NewMod7() CheckDigit
func NewMod10 ¶
func NewMod10(em, om int) CheckDigit
func NewMod3736 ¶
func NewMod3736() CheckDigit
func NewNoop ¶
func NewNoop() CheckDigit
NewNoop instantiates a check digit algorithm that always passes.
func NewS10 ¶
func NewS10(weightings []int, exists []string) CheckDigit
func NewSumProductWithWeightingsAndModulo ¶
func NewSumProductWithWeightingsAndModulo(weightings []int, m1, m2 int) CheckDigit
type CheckDigitOpts ¶
type CheckDigitOpts struct {
Name string `json:"name"`
EvensMultiplier int `json:"evens_multiplier"`
OddsMultiplier int `json:"odds_multiplier"`
Weightings []int `json:"weightings"`
Modulo1 int `json:"modulo1"`
Modulo2 int `json:"modulo2"`
}
CheckDigitOpts contains the configuration values for check digit validations
type Courier ¶
type Courier struct {
Name string `json:"name"`
CourierCode string `json:"courier_code"`
Services []Service `json:"tracking_numbers"`
}
Courier is the data from a single json file
type Lookup ¶
type Lookup struct {
Matches string `json:"matches"`
MatchesRegex RegexParser `json:"matches_regex"`
Name string `json:"name"`
Description string `json:"description"`
CountryCode string `json:"country_code"`
CountryShortCode string `json:"country_short_code"`
Country string `json:"country"`
Courier string `json:"courier"`
CourierURL string `json:"courier_url"`
UPUReferenceURL string `json:"upu_reference_url"`
}
type PrependIf ¶
type PrependIf struct {
Regex RegexParser `json:"matches_regex"`
Content string `json:"content"`
}
PrependIf contains the definition for tracking number prefixes that may be required to validate properly.
type RegexParser ¶
RegexParser is a helper type to convert the PCRE regex to compatible Regex.
func (*RegexParser) UnmarshalJSON ¶
func (r *RegexParser) UnmarshalJSON(buf []byte) error
type Service ¶
type Service struct {
ID string `json:"id"`
Name string `json:"name"`
CourierName string `json:"-"` // from flattening courier json file
CourierCode string `json:"-"` // from flattening courier json file
Description string `json:"description"`
TrackingURL string `json:"tracking_url"`
Regex RegexParser `json:"regex"`
Validation `json:"validation,omitempty"`
// Test numbers drive the package level tests.
TestNumbers struct {
Valid []string `json:"valid"`
Invalid []string `json:"invalid"`
} `json:"test_numbers"`
Additional []Additional `json:"additional,omitempty"`
Partners []struct {
Description string `json:"description"`
PartnerType string `json:"partner_type"`
PartnerID string `json:"partner_id"`
Validation struct {
MatchesAll []struct {
RegexGroupName string `json:"regex_group_name"`
Matches string `json:"matches"`
} `json:"matches_all"`
} `json:"validation"`
} `json:"partners,omitempty"`
}
Service is a single service from a courier json file. Couriers may provide more than one service with uniquely formatted tracking numbers.
type SumProductWithWeightingsAndModulo ¶
func (*SumProductWithWeightingsAndModulo) Generate ¶
func (sp *SumProductWithWeightingsAndModulo) Generate(s string) (string, error)
func (*SumProductWithWeightingsAndModulo) Validate ¶
func (sp *SumProductWithWeightingsAndModulo) Validate(s, cd string) bool
type Validation ¶
type Validation struct {
CheckDigitOpts `json:"checksum"`
Validator CheckDigit `json:"-"`
Additional struct {
// Exists verifies a portions of the additional data extracted matches
// an entry in the corresponding list of lookups defined with the
// service.
Exists []string `json:"exists"`
} `json:"additional"`
// SerialNumberFormat conditionally modifies the serial number prior
// to validating.
SerialNumberFormat struct {
PrependIf PrependIf `json:"prepend_if"`
} `json:"serial_number_format"`
}
Validation defines the validations to be applied to a tracking number.
func (*Validation) SetValidator ¶
func (val *Validation) SetValidator()
SetValidator applies the appropriate validation function for check digits.