-
Notifications
You must be signed in to change notification settings - Fork 10
/
helpers.go
122 lines (115 loc) · 5.55 KB
/
helpers.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright 2015 Constantin Karataev. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// This file contains some helper function to form data for requests
package webmoney
import (
"fmt"
"golang.org/x/text/encoding/charmap"
"os"
"strings"
"time"
)
// function return reqn params for webmoney request
// each subsequent more as the previews
func Reqn() string {
nanoseconds := fmt.Sprintf("%03.f", float32(time.Now().Nanosecond()/1000000))
loc, err := time.LoadLocation("Europe/Moscow")
if err != nil {
panic(err)
}
if os.Getenv("USE_OLD_REQN") != "" {
loc, _ = time.LoadLocation("UTC")
return time.Now().In(loc).Format("060102150405") + nanoseconds[0:2]
}
return time.Now().In(loc).Format("20060102150405") + nanoseconds
}
// Utf8ToWin encode string from utf8 to cp1251
func Utf8ToWin(s string) (string, error) {
encoder := charmap.Windows1251.NewEncoder()
return encoder.String(s)
}
func DebugLog(v ...interface{}) {
if strings.ToUpper(os.Getenv("LOG_LEVEL")) == "TRACE" {
fmt.Println(v...)
}
}
func DebugLogf(format string, v ...interface{}) {
if strings.ToUpper(os.Getenv("LOG_LEVEL")) == "TRACE" {
fmt.Printf(format, v...)
}
}
// Root ca for webmoney requests
const ROOT_CA = `
-----BEGIN CERTIFICATE-----
MIIFsTCCA5mgAwIBAgIQA7dHzSZ7uJdBxFycIWn+WjANBgkqhkiG9w0BAQUFADBr
MSswKQYDVQQLEyJXTSBUcmFuc2ZlciBDZXJ0aWZpY2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