Documentation
¶
Index ¶
- Constants
- func AesCbcDecrypt(cipherText, key, iv []byte) (plainText []byte)
- func AesCbcEncrypt(plainText, key, iv []byte) (cipherText []byte)
- func AesEcbDecrypt(cipherText, key []byte) (plainText []byte)
- func AesEcbEncrypt(plainText, key []byte) (cipherText []byte)
- func AppPath() string
- func ApproxEqualUnitNo(original, proposed string) bool
- func Catch(err *error)
- func DesEcbDecrypt(cipherText, key []byte) (plainText []byte)
- func DesEcbEncrypt(plainText, key []byte) (cipherText []byte)
- func DisableMockHTTPClient()
- func GetField(object interface{}, fieldName string) interface{}
- func MockConf()
- func MockHTTPClientError(err error)
- func MockHTTPClientRespBody(body string)
- func MockHTTPClientRespBodyFromFile(mockFile string)
- func MockStaticUnixMilli(t int64)
- func Must(err error)
- func NormalizeTrainNo(trainNo string) (results []string)
- func NormalizeUnitNo(unitNo string) string
- func PKCS7Padding(input []byte, blockSize int) (buf []byte)
- func PKCS7Unpadding(padded []byte) []byte
- func PrettyPrint(obj interface{})
- func ReadMockFile(mockFile string) (content []byte)
- func SetCookies(req *http.Request, cookies []*http.Cookie)
- func StructDecode(src interface{}, dest interface{}) error
- func UnixMilli(args ...time.Time) int64
- type AdapterConf
- type Duration
- type GenerationRule
- type GlobalConf
- type HTTPRequester
- type RequestConf
- type ScheduleConf
Examples ¶
Constants ¶
const (
ContentType = "application/json"
)
const (
// ISODate is the date layout defined in ISO 8601 or RFC 3339.
ISODate = "2006-01-02"
)
const (
RequestTimeout = 20 * time.Second
)
Variables ¶
This section is empty.
Functions ¶
func AesCbcDecrypt ¶
AesCbcDecrypt is the counterpart of AesCbcEncrypt; it decrypts the cipher text and strips the PKCS #7 padding bytes off the end of the plain text.
func AesCbcEncrypt ¶
AesCbcEncrypt encrypts the plain text with PKCS #7 padding, block chaining mode of operation, and a predefined initial vector.
func AesEcbDecrypt ¶
AesEcbDecrypt is the counterpart of AesEcbEncrypt; it decrypts the cipher text and strips the PKCS #7 padding bytes off the end of the plain text.
func AesEcbEncrypt ¶
AesEcbEncrypt encrypts the plain text with PKCS #7 padding and electronic codebook mode of operation.
func AppPath ¶
func AppPath() string
AppPath returns the relative path for the directory in which the binary executable of this application resides.
func ApproxEqualUnitNo ¶
ApproxEqualUnitNo compares whether the proposed unit number is approximately the same as the original one.
func DesEcbDecrypt ¶
DesEcbDecrypt is the counterpart of DesEcbEncrypt; it decrypts the cipher text and strips the PKCS #7 padding bytes off the end of the plain text.
func DesEcbEncrypt ¶
DesEcbEncrypt encrypts the plain text with PKCS #7 padding and electronic codebook mode of operation.
func DisableMockHTTPClient ¶
func DisableMockHTTPClient()
func GetField ¶
func GetField(object interface{}, fieldName string) interface{}
GetField takes an arbitary structure, and uses reflection to retrieve the field with specified name from it. Panics if the field does not exist.
func MockHTTPClientError ¶
func MockHTTPClientError(err error)
func MockHTTPClientRespBody ¶
func MockHTTPClientRespBody(body string)
func MockHTTPClientRespBodyFromFile ¶
func MockHTTPClientRespBodyFromFile(mockFile string)
Example ¶
Output: same resp: false no errors: true resp body: package common_test err mock: <nil>, my sample error
func Must ¶
func Must(err error)
Must prints the error message and exit immediately if error is not nil.
func NormalizeTrainNo ¶
NormalizeTrainNo converts possibly abbreviated train number pairs to an array of full qualified train number strings.
func NormalizeUnitNo ¶
Example ¶
Output: CRH6002A CRH5A5028 CR200J4001 CRH380B3770 CRH380D1503 CRH380D1504 CR400BFB5097 CR400AFBZ2249
func PKCS7Padding ¶
PKCS7Padding pads the input octet vector to a multiple of blockSize octets with the scheme defined in RFC 2315.
Example ¶
Output: [97 98 99 100 101 102 103 104 8 8 8 8 8 8 8 8] [97 98 99 100 101 102 103 9 9 9 9 9 9 9 9 9] []
func PKCS7Unpadding ¶
PKCS7Unpadding removes the padded bytes from the decrypted text according to the last decrypted byte to recover the original payload.
func PrettyPrint ¶
func PrettyPrint(obj interface{})
PrettyPrint displays a nested structure in human readable JSON format.
Example ¶
Output: { "CIT380A": "CRH2C-2150", "CR200J": null, "CR400AF": [ "0207", "0208" ], "CR400BF": [ "0503", "0507", "0305" ], "CRH6A": 4002 }
func ReadMockFile ¶
func StructDecode ¶
func StructDecode(src interface{}, dest interface{}) error
StructDecode takes a source structure, and uses reflection to translate it to the destination structure. Typically used to convert native Go structures to map[string]interface{}, and vice versa.
Types ¶
type AdapterConf ¶
type AdapterConf struct { Request *RequestConf `toml:"request,omitempty"` SearchSpace []GenerationRule `toml:"search,omitempty"` }
func (AdapterConf) EmitSerials ¶
func (a AdapterConf) EmitSerials(serials chan<- string)
type Duration ¶
Duration is a TOML wrapper type for time.Duration. https://github.com/golang/go/issues/16039
func (Duration) MarshalText ¶
MarshalText formats a Duration value into a TOML string.
func (*Duration) UnmarshalText ¶
UnmarshalText parses a TOML string into a Duration value.
type GenerationRule ¶
type GenerationRule struct { Format string `toml:"format,omitempty"` Min *int `toml:"min,omitempty"` Max *int `toml:"max,omitempty"` Step *int `toml:"step,omitempty"` }
func (*GenerationRule) EmitSerials ¶
func (rule *GenerationRule) EmitSerials(serials chan<- string)
type GlobalConf ¶
type GlobalConf struct { Request *RequestConf `toml:"request,omitempty"` Schedule ScheduleConf `toml:"schedule,omitempty"` Adapters map[string]AdapterConf `toml:"adapters,omitempty"` }
func Conf ¶
func Conf() *GlobalConf
Conf loads configuration from a TOML file on the filesystem when the function is being called for the first time.
Example ¶
Output: 2460 "2.46µs" CRH5-001A CRH3-002C CRH3-004C CRH3-009C CRH2-001A CRH2-002A CRH2-003A
type HTTPRequester ¶
type HTTPRequester interface { Do(*http.Request) (*http.Response, error) Get(url string) (*http.Response, error) Post(url, contentType string, body io.Reader) (*http.Response, error) PostForm(url string, data url.Values) (*http.Response, error) }
func HTTPClient ¶
func HTTPClient(roundTripper ...http.RoundTripper) HTTPRequester
Example ¶
Output: x == y: false cookies: model=CRH6A; serial=4002 get err: <nil> read err: <nil> load err: <nil> ua equal: true cookies: true