kargo

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2018 License: GPL-3.0 Imports: 5 Imported by: 0

README

LogoKargo

GoDoc Build Status Coverage Status

Kargo determines carrier of the tracking number barcode and checks if that tracking number barcode is valid by matching the format and calculating checksum validity. Feel free to create pull requests and issues.

Package supports

  • UPS
  • FedEx Express
  • FedEx Ground "96"
  • USPS IMpb
  • USPS UPU S10
  • USPS 20

But more on the way

  • DHL

Install

go get github.com/unicod3/kargo

Usage and Examples

Kargo's usage is pretty straight forward, supply a tracking number and get the Package struct

package main

import (
	"fmt"
	"github.com/unicod3/kargo"
)

func main() {
	pkg, err := kargo.Identify("1Z999AA10123456784")
	if err != nil {
		fmt.Println(err)
	}

	var trackingNumber string = pkg.TrackingNumber
	var carrier string = pkg.Carrier
	var isValid bool = pkg.IsValid
	fmt.Printf("Tracking Number: %v, Carrier: %v, Is Valid: %t",
		trackingNumber, carrier, isValid)
}

Output: Tracking Number: 1Z999AA10123456784, Carrier: UPS, Is Valid: true

For more examples please check out the test files.

Running the tests

You can run tests with standard test tool of Go:

go test -v 

Changelog

Version 1.1.2

  • Added support for USPS; IMpb, UPU S10, 20 character barcodes
  • Removed the unnecessary prefix from filenames
  • Improved the tests

Version 1.0.1

  • Fix stringutils package dependency issue

Version 1.0.0

  • Initial release

License

GNU General Public License v3.0 - see LICENSE for more details

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Reverse added in v1.0.1

func Reverse(s string) string

Types

type CarrierFactory

type CarrierFactory interface {
	GetCarrierName() string
	GetPackage() *Package
	Match() bool
	Validate() bool
}

CarrierFactory handles the validation of tracking number for carrier

type FedExExpress

type FedExExpress struct {
	*Package
}

FedExExpress defines a struct for Fedex Express packages

func NewFedExExpress

func NewFedExExpress(p *Package) *FedExExpress

NewFedExExpress initializes a new FedExExpress struct with package value

func (*FedExExpress) GetCarrierName

func (f *FedExExpress) GetCarrierName() string

GetCarrierName Implements the CarrierFactory interface method Retuns the name of carrier

func (*FedExExpress) GetPackage

func (f *FedExExpress) GetPackage() *Package

GetPackage Implements the CarrierFactory interface method Returns the package that carrier holds

func (*FedExExpress) Match

func (f *FedExExpress) Match() bool

Match Implements the CarrierFactory interface method Retuns the name of carrier struct with package value

func (*FedExExpress) Validate

func (f *FedExExpress) Validate() bool

Validate Implements the CarrierFactory interface method Checks whether is a package belongs to that carrier

type FedExGround96

type FedExGround96 struct {
	*Package
}

FedExGround96 defines a struct for Fedex Ground packages

func NewFedExGround96

func NewFedExGround96(p *Package) *FedExGround96

NewFedExGround96 initializes a new FedExGround96 struct with package value

func (*FedExGround96) GetCarrierName

func (f *FedExGround96) GetCarrierName() string

GetCarrierName Implements the CarrierFactory interface method Retuns the name of carrier

func (*FedExGround96) GetPackage

func (f *FedExGround96) GetPackage() *Package

GetPackage Implements the CarrierFactory interface method Returns the package that carrier holds

func (*FedExGround96) Match

func (f *FedExGround96) Match() bool

Match Implements the CarrierFactory interface method Retuns the name of carrier struct with package value

func (*FedExGround96) Validate

func (f *FedExGround96) Validate() bool

Validate Implements the CarrierFactory interface method Checks whether is a package belongs to that carrier

type Package

type Package struct {
	Carrier        string
	TrackingNumber string
	IsValid        bool
}

Package is the base struct of all carriers

func Identify

func Identify(trackingNumber string) (*Package, error)

Identify investigates the carriers and checks if the tracking number is valid for one of them

func NewPackage

func NewPackage(trackingNumber string) (*Package, error)

NewPackage initializes a new Package struct with a Tracking Number value

type UPS

type UPS struct {
	*Package
}

UPS is a carrier that have package struct

func NewUPS

func NewUPS(p *Package) *UPS

NewUPS initialize a new UPS struct with package value

func (*UPS) GetCarrierName

func (u *UPS) GetCarrierName() string

GetCarrierName Implements the CarrierFactory interface method Retuns the name of carrier struct with package value

func (*UPS) GetPackage

func (u *UPS) GetPackage() *Package

GetPackage Implements the CarrierFactory interface method Returns the package that carrier holds

func (*UPS) Match

func (u *UPS) Match() bool

Match Implements the CarrierFactory interface method Retuns the name of carrier struct with package value

func (*UPS) Validate

func (u *UPS) Validate() bool

Validate Implements the CarrierFactory interface method Checks whether is a package belongs to that carrier

type USPS20 added in v1.1.2

type USPS20 struct {
	*Package
}

USPS20 is a carrier that have package struct

func NewUSPS20 added in v1.1.2

func NewUSPS20(p *Package) *USPS20

NewUSPS20 initialize a new USPS20 struct with package value

func (*USPS20) GetCarrierName added in v1.1.2

func (u *USPS20) GetCarrierName() string

GetCarrierName Implements the CarrierFactory interface method Retuns the name of carrier struct with package value

func (*USPS20) GetPackage added in v1.1.2

func (u *USPS20) GetPackage() *Package

GetPackage Implements the CarrierFactory interface method Returns the package that carrier holds

func (*USPS20) Match added in v1.1.2

func (u *USPS20) Match() bool

Match Implements the CarrierFactory interface method Retuns the name of carrier struct with package value

func (*USPS20) Validate added in v1.1.2

func (u *USPS20) Validate() bool

Validate Implements the CarrierFactory interface method Checks whether is a package belongs to that carrier

type USPSIMpb added in v1.1.2

type USPSIMpb struct {
	*Package
}

USPSIMpb is a carrier that have package struct

func NewUSPSIMpb added in v1.1.2

func NewUSPSIMpb(p *Package) *USPSIMpb

NewUSPSIMpb initialize a new USPSIMpb struct with package value

func (*USPSIMpb) GetCarrierName added in v1.1.2

func (u *USPSIMpb) GetCarrierName() string

GetCarrierName Implements the CarrierFactory interface method Retuns the name of carrier struct with package value

func (*USPSIMpb) GetPackage added in v1.1.2

func (u *USPSIMpb) GetPackage() *Package

GetPackage Implements the CarrierFactory interface method Returns the package that carrier holds

func (*USPSIMpb) Match added in v1.1.2

func (u *USPSIMpb) Match() bool

Match Implements the CarrierFactory interface method Retuns the name of carrier struct with package value

func (*USPSIMpb) Validate added in v1.1.2

func (u *USPSIMpb) Validate() bool

Validate Implements the CarrierFactory interface method Checks whether is a package belongs to that carrier

type USPSS10 added in v1.1.2

type USPSS10 struct {
	*Package
}

USPS10 is a carrier that have package struct

func NewUSPSS10 added in v1.1.2

func NewUSPSS10(p *Package) *USPSS10

NewUSPSS10 initialize a new NewUSPSS10 struct with package value

func (*USPSS10) GetCarrierName added in v1.1.2

func (u *USPSS10) GetCarrierName() string

GetCarrierName Implements the CarrierFactory interface method Retuns the name of carrier struct with package value

func (*USPSS10) GetPackage added in v1.1.2

func (u *USPSS10) GetPackage() *Package

GetPackage Implements the CarrierFactory interface method Returns the package that carrier holds

func (*USPSS10) Match added in v1.1.2

func (u *USPSS10) Match() bool

Match Implements the CarrierFactory interface method Retuns the name of carrier struct with package value

func (*USPSS10) Validate added in v1.1.2

func (u *USPSS10) Validate() bool

Validate Implements the CarrierFactory interface method Checks whether is a package belongs to that carrier

Jump to

Keyboard shortcuts

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