Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bobgroup-go-utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Commits
58ab9602
Commit
58ab9602
authored
3 years ago
by
Francé Wilke
Browse files
Options
Downloads
Patches
Plain Diff
Add some util functions
parent
27cc74b1
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
date_utils/date_utils.go
+25
-1
25 additions, 1 deletion
date_utils/date_utils.go
encryption/encryption.go
+8
-0
8 additions, 0 deletions
encryption/encryption.go
string_utils/string_utils.go
+19
-0
19 additions, 0 deletions
string_utils/string_utils.go
with
52 additions
and
1 deletion
date_utils/date_utils.go
+
25
−
1
View file @
58ab9602
...
@@ -8,7 +8,7 @@ import (
...
@@ -8,7 +8,7 @@ import (
const
TimeZoneString
=
"Africa/Johannesburg"
const
TimeZoneString
=
"Africa/Johannesburg"
func
DateLayoutYearMonthDayTimeT
()
string
{
func
DateLayoutYearMonthDayTimeT
()
string
{
layout
:=
"2006-01-02T15:04"
layout
:=
"2006-01-02T15:04
:05
"
return
layout
return
layout
}
}
...
@@ -47,6 +47,20 @@ func DateLayoutHumanReadable() string {
...
@@ -47,6 +47,20 @@ func DateLayoutHumanReadable() string {
return
layout
return
layout
}
}
func
DateLayoutTrimmed
()
string
{
layout
:=
"20060102150405"
return
layout
}
func
DateDBFormattedString
(
date
time
.
Time
)
string
{
return
date
.
Format
(
"2006-01-02 15:04:05.000000-07"
)
}
func
DateDBFormattedStringDateOnly
(
date
time
.
Time
)
string
{
return
date
.
Format
(
"2006-01-02"
)
}
func
CurrentLocation
()
*
time
.
Location
{
func
CurrentLocation
()
*
time
.
Location
{
loc
,
_
:=
time
.
LoadLocation
(
TimeZoneString
)
loc
,
_
:=
time
.
LoadLocation
(
TimeZoneString
)
return
loc
return
loc
...
@@ -88,3 +102,13 @@ func TimeBefore(a string, b string) bool {
...
@@ -88,3 +102,13 @@ func TimeBefore(a string, b string) bool {
return
hoursA
<
hoursB
return
hoursA
<
hoursB
}
}
// ConvertToNoDateTimeString - Converts a PSQL Time type to Go Time type
func
ConvertToNoDateTimeString
(
timeString
*
string
)
(
*
string
,
error
)
{
parsedTime
,
err
:=
time
.
Parse
(
"15:04:05"
,
*
timeString
)
if
err
!=
nil
{
return
nil
,
err
}
formattedTime
:=
parsedTime
.
Format
(
"15:04"
)
return
&
formattedTime
,
nil
}
This diff is collapsed.
Click to expand it.
encryption/encryption.go
+
8
−
0
View file @
58ab9602
...
@@ -2,8 +2,10 @@ package encryption
...
@@ -2,8 +2,10 @@ package encryption
import
(
import
(
"crypto/hmac"
"crypto/hmac"
"crypto/md5"
"crypto/sha256"
"crypto/sha256"
"encoding/base64"
"encoding/base64"
"fmt"
)
)
func
Hash
(
input
string
,
key
string
)
string
{
func
Hash
(
input
string
,
key
string
)
string
{
...
@@ -12,3 +14,9 @@ func Hash(input string, key string) string {
...
@@ -12,3 +14,9 @@ func Hash(input string, key string) string {
h
.
Write
([]
byte
(
input
))
h
.
Write
([]
byte
(
input
))
return
base64
.
StdEncoding
.
EncodeToString
(
h
.
Sum
(
nil
))
return
base64
.
StdEncoding
.
EncodeToString
(
h
.
Sum
(
nil
))
}
}
func
Md5HashString
(
bytesToHash
[]
byte
)
string
{
hash
:=
md5
.
Sum
(
bytesToHash
)
hashString
:=
fmt
.
Sprintf
(
"%X"
,
hash
)
return
hashString
}
This diff is collapsed.
Click to expand it.
string_utils/string_utils.go
+
19
−
0
View file @
58ab9602
package
string_utils
package
string_utils
import
(
import
(
"crypto/md5"
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"regexp"
"regexp"
...
@@ -192,3 +193,21 @@ func StringTrimQuotes(stringToTrim string) string {
...
@@ -192,3 +193,21 @@ func StringTrimQuotes(stringToTrim string) string {
return
stringToTrim
return
stringToTrim
}
}
func
KeyToHumanReadable
(
s
string
)
string
{
s
=
strings
.
TrimSpace
(
s
)
re
:=
regexp
.
MustCompile
(
"(_|-)"
)
s
=
re
.
ReplaceAllString
(
s
,
" "
)
return
sentenceCase
(
string
(
s
))
}
func
sentenceCase
(
str
string
)
string
{
for
i
,
v
:=
range
str
{
return
string
(
unicode
.
ToUpper
(
v
))
+
str
[
i
+
1
:
]
}
return
""
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment