forked from purpleworks/delibird
/
courier.go
34 lines (28 loc) · 814 Bytes
/
courier.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package delibird
import (
"fmt"
"reflect"
)
// Courier is the interface representing the standardized methods to
// parse shipment tracking html
type Courier interface {
// Parse html to tracking object
Parse(invoice string) (Track, *ApiError)
// Courier code
Code() string
// Courier name
Name() string
}
var courierMap = map[string]Courier{}
// NewCourier creates courier object by courier company code
func NewCourier(name string) (Courier, *ApiError) {
if value, ok := courierMap[name]; ok {
courier := reflect.New(reflect.TypeOf(value).Elem()).Interface().(Courier)
return courier, nil
}
return nil, NewApiError(NoCode, fmt.Sprintf("%v is not supported.", name))
}
// RegisterCourier register new courier
func RegisterCourier(name string, courier Courier) {
courierMap[name] = courier
}