base

package module
v0.49.3 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: Apache-2.0 Imports: 13 Imported by: 52

README

moov-io/base

GoDoc Build Status Go Report Card Apbasee 2 licensed

Package github.com/moov-io/base implements core libraries used in multiple Moov projects. Refer to each projects documentation for more details.

Getting Started

You can either clone down the code (git clone git@github.com:moov-io/base.git) or grab the modules into your cache (go get -u github.com/moov-io/base).

Configuration

Environmental Variable Description Default
KUBERNETES_SERVICE_ACCOUNT_FILEPATH Filepath to Kubernetes service account /var/run/secrets/kubernetes.io

Getting Help

channel info
Twitter @moov You can follow Moov.io's Twitter feed to get updates on our project(s). You can also tweet us questions or just share blogs or stories.
GitHub Issue If you are able to reproduce a problem please open a GitHub Issue under the specific project that caused the error.
moov-io slack Join our slack channel to have an interactive discussion about the development of the project.

Supported and Tested Platforms

  • 64-bit Linux (Ubuntu, Debian), macOS, and Windows

Contributing

Yes please! Please review our Contributing guide and Code of Conduct to get started!

This project uses Go Modules and uses Go 1.14 or higher. See Golang's install instructions for help setting up Go. You can download the source code and we offer tagged and released versions as well. We highly recommend you use a tagged release for production.

License

Apbasee License 2.0 See LICENSE for details.

Documentation

Overview

Package base implements core libraries used in multiple Moov projects. Refer to each projects documentation for more details.

Index

Constants

View Source
const (
	// ISO8601Format represents an ISO 8601 format with timezone
	ISO8601Format = "2006-01-02T15:04:05Z07:00"
)

Variables

View Source
var ConfigDefaults embed.FS
View Source
var MySQLMigrations embed.FS
View Source
var SpannerMigrations embed.FS

Functions

func Has added in v0.8.0

func Has(list error, err error) bool

Has takes in a (potential) list of errors, and an error to check for. If any of the errors in the list have the same type as the error to check, it returns true. If the "list" isn't actually a list (typically because it is nil), or no errors in the list match the other error it returns false. So it can be used as an easy way to check for a particular kind of error.

func ID added in v0.7.0

func ID() string

ID creates a new random string for Moov systems. Do not assume anything about these ID's other than they are non-empty strings.

func Match added in v0.8.0

func Match(errA, errB error) bool

Match takes in two errors and compares them, returning true if they match and false if they don't The matching is done by basic equality for simple errors (i.e. defined by errors.New) and by type for other errors. If errA is wrapped with an error supporting the UnwrappableError interface it will also unwrap it and then recursively compare the unwrapped error with errB.

Types

type ErrorList added in v0.3.0

type ErrorList []error

ErrorList represents an array of errors which is also an error itself.

func (*ErrorList) Add added in v0.3.0

func (e *ErrorList) Add(err error)

Add appends err onto the ErrorList. Errors are kept in append order.

func (ErrorList) Empty added in v0.3.0

func (e ErrorList) Empty() bool

Empty no errors to return

func (ErrorList) Err added in v0.3.0

func (e ErrorList) Err() error

Err returns the first error (or nil).

func (ErrorList) Error added in v0.3.0

func (e ErrorList) Error() string

Error implements the error interface

func (ErrorList) MarshalJSON added in v0.3.0

func (e ErrorList) MarshalJSON() ([]byte, error)

MarshalJSON marshals error list

func (ErrorList) Print added in v0.3.0

func (e ErrorList) Print(w io.Writer)

Print formats the ErrorList into a string written to w. If ErrorList contains multiple errors those after the first are indented.

type ParseError added in v0.3.0

type ParseError struct {
	Line   int    // Line number where the error occurred
	Record string // Name of the record type being parsed
	Err    error  // The actual error
}

ParseError is returned for parsing reader errors. The first line is 1.

func (ParseError) Error added in v0.3.0

func (e ParseError) Error() string

func (ParseError) Unwrap added in v0.8.0

func (e ParseError) Unwrap() error

Unwrap implements the UnwrappableError interface for ParseError

type Time

type Time struct {
	time.Time
	// contains filtered or unexported fields
}

Time is an time.Time struct that encodes and decodes in ISO 8601.

ISO 8601 is usable by a large array of libraries whereas RFC 3339 support isn't often part of language standard libraries.

Time also assists in calculating processing days that meet the US Federal Reserve Banks processing days.

For holidays falling on Saturday, Federal Reserve Banks and Branches will be open the preceding Friday. For holidays falling on Sunday, all Federal Reserve Banks and Branches will be closed the following Monday. ACH and FedWire payments are not processed on weekends or the following US holidays.

Holiday Schedule: https://www.frbservices.org/about/holiday-schedules

All logic is based on ET(Eastern) time as defined by the Federal Reserve https://www.frbservices.org/resources/resource-centers/same-day-ach/fedach-processing-schedule.html

func NewTime

func NewTime(t time.Time) Time

NewTime wraps a time.Time value in Moov's base.Time struct. If you need the underlying time.Time value call .Time:

The time zone will be changed to UTC.

func Now

func Now(location *time.Location) Time

Now returns a Time object with the current clock time set.

func (Time) AddBankingDay added in v0.2.0

func (t Time) AddBankingDay(d int) Time

AddBankingDay takes an integer for the number of valid banking days to add and returns a Time. Negative values and large values (over 500 days) will not modify the Time.

func (Time) AddBankingTime added in v0.49.0

func (t Time) AddBankingTime(hours, minutes, seconds int) Time

AddBankingTime increments t by the hours, minutes, and seconds provided but keeps the final time within 9am to 5pm in t's Location.

func (Time) AddBusinessDay added in v0.31.0

func (t Time) AddBusinessDay(d int) Time

AddBusinessDay takes an integer for the number of valid business days to add and returns a Time. Negative values and large values (over 500 days) will not modify the Time.

func (Time) Equal

func (t Time) Equal(other Time) bool

Equal compares two Time values. Time values are considered equal if they both truncate to the same year/month/day and hour/minute/second.

func (Time) GetHoliday added in v0.36.0

func (t Time) GetHoliday() *cal.Holiday

func (Time) IsBankingDay added in v0.2.0

func (t Time) IsBankingDay() bool

IsBankingDay checks the rules around holidays (i.e. weekends) to determine if the given day is a banking day.

func (Time) IsBusinessDay added in v0.30.0

func (t Time) IsBusinessDay() bool

IsBusinessDay is defined as Mondays through Fridays except federal holidays. Source: https://www.federalreserve.gov/Pubs/regcc/regcc.htm

func (Time) IsHoliday added in v0.28.1

func (t Time) IsHoliday() bool

func (Time) IsWeekend added in v0.2.0

func (t Time) IsWeekend() bool

IsWeekend reports whether the given date falls on a weekend.

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON returns JSON for the given Time

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON unpacks a JSON string to populate a Time instance

type UnwrappableError added in v0.8.0

type UnwrappableError interface {
	Error() string
	Unwrap() error
}

UnwrappableError is an interface for errors that wrap another error with some extra context The interface allows these errors to get automatically unwrapped by the Match function

Directories

Path Synopsis
Package admin implements an http.Server which can be used for operations and monitoring tools.
Package admin implements an http.Server which can be used for operations and monitoring tools.
Package http implements a core suite of HTTP functions for use inside Moov.
Package http implements a core suite of HTTP functions for use inside Moov.
bind
Package bind returns well known HTTP local bind addresses for Moov services.
Package bind returns well known HTTP local bind addresses for Moov services.

Jump to

Keyboard shortcuts

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