-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.go
More file actions
260 lines (222 loc) · 7.22 KB
/
version.go
File metadata and controls
260 lines (222 loc) · 7.22 KB
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/* -----------------------------------------------------------------
* L o r d O f S c r i p t s (tm)
* Copyright (C)2026 Dídimo Grimaldo T.
* APP_NAME
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Package/Module/Application version information
*-----------------------------------------------------------------*/
package gofynex
import (
"fmt"
"runtime"
"strings"
)
/* ----------------------------------------------------------------
* G L O B A L S
*-----------------------------------------------------------------*/
// These must be adapted for the current module
const (
// in case vcsVersion not injected during link phase
MANUAL_VERSION string = "1.2.0"
// Change these values accordingly
NAME string = "Go-Fynex"
DESC string = "An custom widget and helper library for Fyne"
STATUS devStatus = statusReleased
REVISION = 1
)
// These are for all modules where this template is used
const (
// Useful Unicode Characters
CHR_COPYRIGHT = '\u00a9' // ©
CHR_REGISTERED = '\u00ae' // ®
CHR_GUILLEMET_L = '\u00ab' // «
CHR_GUILLEMET_R = '\u00bb' // »
CHR_TRADEMARK = '\u2122' // ™
CHR_SAMARITAN = '\u214f' // ⅏
CHR_PLACEOFINTEREST = '\u2318' // ⌘
CHR_HIGHVOLTAGE = '\u26a1' // ⚡
CHR_TRIDENT = rune(0x1f531) // 🔱
CHR_SPLATTER = rune(0x1fadf)
CHR_WARNING = '\u26a0' // ⚠
CHR_EXCLAMATION = '\u2757'
CHR_SKULL = '\u2620' // ☠
CO1 = "odlamirG omidiD 5202)C("
CO2 = "stpircS fO droL 5202)C("
CO3 = "gnitirwnitsol"
)
var Version PackageVersion
/* ----------------------------------------------------------------
* L O C A L S
*-----------------------------------------------------------------*/
const (
// don't change
statusAlpha devStatus = "Alpha"
statusBeta devStatus = "Beta"
statusRC devStatus = "RC" // Release Candidate
statusReleased devStatus = ""
)
var (
vcsVersion string // automatically injected with linker
vcsCommit string
vcsDate string
vcsBuildNum string
//NOT USEDgo:embed version.txt
)
/* ----------------------------------------------------------------
* I N T E R F A C E S
*-----------------------------------------------------------------*/
/* ----------------------------------------------------------------
* T Y P E S
*-----------------------------------------------------------------*/
type devStatus = string
/* ----------------------------------------------------------------
* P U B L I C T Y P E S
*-----------------------------------------------------------------*/
// Package/Module/Application version descriptor
type PackageVersion struct {
n string // name
v string // version tag
s devStatus // status
sv int // Alpha/Beta/RC-### sequence
}
/* ----------------------------------------------------------------
* P R I V A T E T Y P E S
*-----------------------------------------------------------------*/
/* ----------------------------------------------------------------
* I N I T I A L I Z E R
*-----------------------------------------------------------------*/
func init() {
Version = PackageVersion{
n: NAME,
v: MANUAL_VERSION,
s: STATUS,
sv: REVISION,
}
}
/* ----------------------------------------------------------------
* C O N S T R U C T O R S
*-----------------------------------------------------------------*/
func NewPackageVersion(name, description string, verStr string, status devStatus) PackageVersion {
return PackageVersion{
n: name,
v: verStr,
s: status,
sv: 1,
}
}
/* ----------------------------------------------------------------
* M E T H O D S
*-----------------------------------------------------------------*/
/* ----------------------------------------------------------------
* P U B L I C M E T H O D S
*-----------------------------------------------------------------*/
func (pv PackageVersion) BuildMeta() string {
ver := vcsVersion
if len(vcsVersion) == 0 {
ver = "v" + MANUAL_VERSION
}
return fmt.Sprintf("\t\t%s-%s %s", ver, vcsBuildNum, vcsDate)
}
func (pv PackageVersion) CommitInfo() string {
return fmt.Sprintf("Build #%s (%s)", vcsBuildNum, vcsCommit)
}
func (pv PackageVersion) Short() string {
var ver string
if len(vcsVersion) != 0 {
pv.v = vcsVersion
}
var buildInfo string = ""
if vcsBuildNum != "" {
buildInfo = fmt.Sprintf(" build #%s", vcsBuildNum)
}
switch pv.s {
case statusAlpha:
fallthrough
case statusBeta:
fallthrough
case statusRC:
ver = fmt.Sprintf("v%s-%s-%d%s", pv.v, pv.s, pv.sv, buildInfo)
default:
ver = fmt.Sprintf("v%s %s", pv.v, buildInfo)
}
return ver
}
func (pv PackageVersion) String() string {
var ver string
if len(vcsVersion) != 0 {
pv.v = vcsVersion
}
var buildInfo string = ""
if vcsBuildNum != "" {
buildInfo = fmt.Sprintf(" build #%s", vcsBuildNum)
}
switch pv.s {
case statusAlpha:
fallthrough
case statusBeta:
fallthrough
case statusRC:
ver = fmt.Sprintf("%s v%s-%s-%d%s", pv.n, pv.v, pv.s, pv.sv, buildInfo)
default:
ver = fmt.Sprintf("%s v%s %s", pv.n, pv.v, buildInfo)
}
return ver
}
/* ----------------------------------------------------------------
* P R I V A T E M E T H O D S
*-----------------------------------------------------------------*/
/* ----------------------------------------------------------------
* F U N C T I O N S
*-----------------------------------------------------------------*/
// Funny LordOfScripts logo
func Logo() string {
const (
whiteStar rune = '\u269d' // ⚝
unisex rune = '\u26a5' // ⚥
hotSpring rune = '\u2668' // ♨
leftConv rune = '\u269e' // ⚞
rightConv rune = '\u269f' // ⚟
eye rune = '\u25d5' // ◕
mouth rune = '\u035c' // ͜ ‿ \u203f
skull rune = '\u2620' // ☠
)
return fmt.Sprintf("%c%c%c %c%c", leftConv, eye, mouth, eye, rightConv)
//fmt.Sprintf("(%c%c %c)", eye, mouth, eye)
}
// Hey! My time costs money too!
func BuyMeCoffee(coffee4 ...string) {
const (
coffee rune = '\u2615' // ☕
)
var recipient string
if len(coffee4) == 0 {
recipient = Reverse(CO3)
} else {
recipient = coffee4[0]
}
fmt.Printf("\t%c Buy me a Coffee? https://www.buymeacoffee/%s\n", coffee, recipient)
}
func Copyright(owner string, withLogo bool) {
fmt.Printf("\t%c %s %s %c\n", CHR_TRIDENT, Version, Reverse(owner), CHR_TRIDENT)
fmt.Println("\t\t\t\t", Logo())
}
func Reverse(s string) string {
runes := []rune(s)
for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
runes[i], runes[j] = runes[j], runes[i]
}
return string(runes)
}
// get the current GO language version
func GoVersion() string {
ver := strings.Replace(runtime.Version(), "go", "", -1)
return ver
}
// retrieve the current GO language version and compare it
// to the minimum required. It returns the current version
// and whether the condition current >= min is fulfilled or not.
func GoVersionMin(min string) (string, bool) {
current := GoVersion()
ok := current >= min
return current, ok
}