base

package
v3.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxMetadataLength defines the max length of the metadata bytes field
	// for the credit-class & credit-batch.
	MaxMetadataLength = 256

	// MaxNoteLength defines the max length for note fields.
	MaxNoteLength = 512
)

Variables

View Source
var (
	RegexCreditTypeAbbrev = `[A-Z]{1,3}` //nolint:gosec
	RegexClassID          = fmt.Sprintf(`%s[0-9]{2,}`, RegexCreditTypeAbbrev)
	RegexProjectID        = fmt.Sprintf(`%s-[0-9]{3,}`, RegexClassID)
	RegexBatchDenom       = fmt.Sprintf(`%s-[0-9]{8}-[0-9]{8}-[0-9]{3,}`, RegexProjectID)
	RegexJurisdiction     = `([A-Z]{2})(?:-([A-Z0-9]{1,3})(?: ([a-zA-Z0-9 \-]{1,64}))?)?`
)

Functions

func ExponentToPrefix

func ExponentToPrefix(exponent uint32) (string, error)

ExponentToPrefix returns a denom prefix for a given exponent. Returns error if the exponent is not supported.

func FormatBatchDenom

func FormatBatchDenom(projectID string, batchSeqNo uint64, startDate, endDate *time.Time) (string, error)

FormatBatchDenom formats the unique denomination for a credit batch. This format may evolve over time, but will maintain backwards compatibility.

The current version has the format: <project-id>-<start_date>-<end_date>-<batch_sequence>

<project-id> is the unique identifier of the project (see FormatProjectID) <start-date> is the start date of the credit batch with the format YYYYMMDD <end-date> is the end date of the credit batch with the format YYYYMMDD <batch-sequence> is the sequence number of the credit batch, padded to at least three digits

e.g. C01-001-20190101-20200101-001

func FormatClassID

func FormatClassID(creditTypeAbbreviation string, classSeqNo uint64) string

FormatClassID formats the unique identifier for a new credit class, based on the credit type abbreviation and the credit class sequence number. This format may evolve over time, but will maintain backwards compatibility.

The current version has the format: <credit-type-abbrev><class-sequence>

<credit-type-abbrev> is the unique identifier of the credit type <class-sequence> is the sequence number of the credit class, padded to at least three digits

e.g. C01

func FormatProjectID

func FormatProjectID(classID string, projectSeqNo uint64) string

FormatProjectID formats the unique identifier for a new project, based on the credit class id and project sequence number. This format may evolve over time, but will maintain backwards compatibility.

The current version has the format: <class-id>-<project-sequence>

<class-id> is the unique identifier of the credit class (see FormatClassID) <project-sequence> is the sequence number of the project, padded to at least three digits

e.g. C01-001

func GetClassIDFromBatchDenom

func GetClassIDFromBatchDenom(denom string) string

GetClassIDFromBatchDenom returns the credit class ID in a batch denom.

func GetClassIDFromProjectID

func GetClassIDFromProjectID(projectID string) string

GetClassIDFromProjectID returns the credit class ID in a project ID.

func GetCreditTypeAbbrevFromClassID

func GetCreditTypeAbbrevFromClassID(classID string) string

GetCreditTypeAbbrevFromClassID returns the credit type abbreviation in a credit class id

func GetProjectIDFromBatchDenom

func GetProjectIDFromBatchDenom(denom string) string

GetProjectIDFromBatchDenom returns the credit project ID in a batch denom.

func ValidateBatchDenom

func ValidateBatchDenom(denom string) error

ValidateBatchDenom validates a batch denomination conforms to the format described in FormatBatchDenom. The return is nil if the denom is valid.

func ValidateClassID

func ValidateClassID(classID string) error

ValidateClassID validates a class ID conforms to the format described in FormatClassID. The return is nil if the ID is valid.

func ValidateCreditTypeAbbreviation

func ValidateCreditTypeAbbreviation(abbr string) error

ValidateCreditTypeAbbreviation validates a credit type abbreviation, ensuring it is only 1-3 uppercase letters. The return is nil if the abbreviation is valid.

func ValidateJurisdiction

func ValidateJurisdiction(jurisdiction string) error

ValidateJurisdiction checks that the country and region conform to ISO 3166 and the postal code is valid. This is a simple regex check and doesn't check that the country or subdivision codes actually exist. This is because the codes could change at short notice and we don't want to hardfork to keep up-to-date with that information. The return is nil if the jurisdiction is valid.

func ValidateProjectID

func ValidateProjectID(projectID string) error

ValidateProjectID validates a project ID conforms to the format described in FormatProjectID. The return is nil if the ID is valid.

Types

This section is empty.

Directories

Path Synopsis
types
v1
Package v1 is a reverse proxy.
Package v1 is a reverse proxy.
v1alpha1
Package v1alpha1 is a reverse proxy.
Package v1alpha1 is a reverse proxy.

Jump to

Keyboard shortcuts

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