-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.go
102 lines (84 loc) · 1.87 KB
/
app.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
package main
import (
"context"
"dev-tools/utils/base64"
"dev-tools/utils/md5"
"dev-tools/utils/qrcode"
"dev-tools/utils/str_length"
"dev-tools/utils/timex"
"dev-tools/utils/url_code"
"dev-tools/utils/uuid"
)
// App struct
type App struct {
ctx context.Context
}
// NewApp creates a new App application struct
func NewApp() *App {
return &App{}
}
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
}
func (a *App) beforeClose(ctx context.Context) (prevent bool) {
timex.DeleteTmpFile()
return false
}
// GenerateQRCode .
func (a *App) GenerateQRCode(txt string) string {
return qrcode.Generate(txt)
}
// Base64Encode .
func (a *App) Base64Encode(txt string) string {
return base64.Encode(txt)
}
// Base64Decode .
func (a *App) Base64Decode(txt string) string {
return base64.Decode(txt)
}
// UrlEncode .
func (a *App) UrlEncode(txt string) string {
return url_code.Encode(txt)
}
// UrlDecode .
func (a *App) UrlDecode(txt string) string {
return url_code.Decode(txt)
}
// Md5Encode .
func (a *App) Md5Encode(txt string) string {
return md5.Encode(txt)
}
// StrLength .
func (a *App) StrLength(txt string) int {
return str_length.Count(txt)
}
// TimeInit .
func (a *App) TimeInit() timex.TimeOption {
return timex.TimeInit()
}
// GetTimeOption .
func (a *App) GetTimeOption() timex.TimeOption {
return timex.GetTimeOption()
}
// SetUnix .
func (a *App) SetUnix(timestamp int64) {
timex.SetUnix(timestamp)
}
// SetLocation .
func (a *App) SetLocation(timezone string) {
timex.SetLocation(timezone)
}
// SetFormat .
func (a *App) SetFormat(layout string) {
timex.SetFormat(layout)
}
// SetDatetime .
func (a *App) SetDatetime(datetime string) {
timex.SetDatetime(datetime)
}
// GetUUID .
func (a *App) GetUUID(isHyphen bool) string {
return uuid.GenUUID(isHyphen)
}