-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
executable file
·215 lines (181 loc) · 5.24 KB
/
main.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package main
import "github.com/high-performance-payment-gateway/balance-service/balance"
func main() {
balanceModule := balance.NewModule()
balanceModule.Start()
}
/*
func response(c *fiber.Ctx) error {
return c.SendString("Success !!!!!!!!!!!!!!!1111111")
}
func temp() {
log_init.Init(log_init.Log{
TypeFormat: log_init.TYPE_FORMAT_TEXT,
TypeOutput: log_init.TYPE_OUTPUT_FILE,
LinkFile: "balance/infrastructure/log/log_file/log.log",
})
//
//gCf := TestEnvGlobal()
//TestAutoChangeSecret(gCf.AuthInternalServiceConfig())
// Create a new fiber instance with custom config
app := fiber.New(fiber.Config{
// Override default error handler
ErrorHandler: error_handle.CustomMessageError,
})
//config error handle
eH := error_handle.ErrorHandle{
App: app,
}
eH.Init()
// config alert panic notify
alertAc := error_handle.AlertAc{
Dsn: "https://[email protected]/6739879",
Repanic: true,
Debug: true,
AttachStacktrace: true,
}
alertPanic := error_handle.NewPanicHandle(&alertAc, app)
alertPanic.Init()
//app.Use(fibersentry.New(fibersentry.Config{
// Repanic: true,
// WaitForDelivery: true,
//}))
//
//enhanceSentryEvent := func(c *fiber.Ctx) error {
// if hub := fibersentry.GetHubFromContext(c); hub != nil {
// hub.Scope().SetTag("someRandomTag", "maybeYouNeedIt")
// }
// return c.Next()
//}
app.Get("/panic", func(c *fiber.Ctx) error {
panic("panic0999hbhbhb" + "333333333333333333333")
})
//app.All("/", func(c *fiber.Ctx) error {
// if hub := fibersentry.GetHubFromContext(c); hub != nil {
// hub.WithScope(func(scope *sentry.Scope) {
// scope.SetExtra("unwantedQuery", "someQueryDataMaybe")
// hub.CaptureMessage("User provided unwanted query string, but we recovered just fine")
// })
// }
// return c.SendStatus(fiber.StatusOK)
//})
errApp := app.Listen(":3000")
if errApp != nil {
errMApp := fmt.Sprintf("Init app error, message: %s", errApp.Error())
panic(errMApp)
os.Exit(0)
}
}
func TestJsonHamas() {
ListES := validate.ListErrorsDefaultShow{}
oneErr := validate.OneErrorDefaultShow{
Field: "name",
Rule: "require",
Message: "field is require",
ParamRule: "required",
}
ListES["name"] = oneErr
showE := validate.DefaultShowError{
ListError: ListES,
}
rs, errCV := json.Marshal(showE)
if errCV != nil {
fmt.Println("error")
}
fmt.Println(string(rs))
}
func TestValidate() {
// User contains user information
type User struct {
FirstName string `json:"fname" validate:"maxlengError,alpha,required"`
LastName string `json:"lname" validate:"alpha"`
Age uint8 `validate:"gte=20,lte=65"`
Email string `json:"e-mail" validate:"required,email"`
JoiningDate string `validate:"datetime"`
}
// use a single instance of validate, it caches struct info
var validate *validator.Validate
validate = validator.New()
validate.RegisterValidation("maxlengError", func(fl validator.FieldLevel) bool {
fmt.Println("ffffff", fl.Field())
return len(fl.Field().String()) > 6
})
user := &User{
FirstName: "",
LastName: "Test",
Age: 75,
Email: "Badger.Smith@",
JoiningDate: "005-25-10",
}
err := validate.Struct(user)
if err != nil {
if _, ok := err.(*validator.InvalidValidationError); ok {
fmt.Println(err)
return
}
fmt.Println("------ List of tag fields with error ---------")
for _, err := range err.(validator.ValidationErrors) {
fmt.Println(err.StructField())
fmt.Println(err.ActualTag())
fmt.Println(err.Kind())
fmt.Println(err.Value())
fmt.Println(err.Param())
fmt.Println("---------------")
}
return
}
}
func TestEnvGlobal() env.GlobalConfigInterface {
os.Setenv(env.ENV_ENVIRONMENT, env.ENV_DEV)
os.Setenv(env.AWS_SECRET_NAME_GLOBAL_KEY, "payment-balance-service-qwedjfndasndajndn12")
os.Setenv(env.AWS_REGION_GLOBAL_KEY, "ap-southeast-1")
os.Setenv(env.AWS_VERSION_STATE_GLOBAL_KEY, "AWSCURRENT")
gCf := env.NewGlobalConfig()
gCf.Init(env.ConfigEnv{
FilePatchLogInLocal: "balance/infrastructure/config/env/.env",
})
return gCf
}
func TestAutoChangeSecret(ai env.AuthInternalServiceConfigInterface) {
//firstInit
//err := auth_internal_service.FirstTimeContructSecret()
//if err != nil {
// fmt.Println("contrcut secret firsttime erro : %s", err.Error())
//} else {
// fmt.Println("contruct secret in firsttime success")
//}
//auto change secret
//auto := auth_internal_service.NewAutoChangeSecret(ai)
//err := auto.Init()
//if err != nil {
// fmt.Println("init error : %s", err.Error())
//} else {
// fmt.Println("init success")
//}
//test auth
//auth := auth_internal_service.NewAuthInternalService(ai)
//auth.Init()
//fmt.Println(auth.Auth("42zPQ0sIAmjtHSTRANmc00000000000000000004"))
// test integrated
//auto change secret
//go func() {
// auto := auth_internal_service.NewAutoChangeSecret(ai)
// err := auto.Init()
// if err != nil {
// fmt.Println("init error : %s", err.Error())
// } else {
// fmt.Println("init success")
// }
//}()
//
////init auth
//auth := auth_internal_service.NewAuthInternalService(ai)
//auth.Init()
//go func() {
// for {
// fmt.Println(auth.Auth("K38xvC2XthUC6fHSxz6W00000000000000000006"))
// time.Sleep(5 * time.Second)
// }
//}()
}
*/