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
76f36d59
Commit
76f36d59
authored
2 years ago
by
Johan de Klerk
Browse files
Options
Downloads
Plain Diff
Merge branch 'main' of gitlab.bob.co.za:bob-public-utils/bobgroup-go-utils
parents
244d12d3
58ea1d59
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
address_utils/address_utils.go
+21
-0
21 additions, 0 deletions
address_utils/address_utils.go
string_utils/string_utils.go
+14
-0
14 additions, 0 deletions
string_utils/string_utils.go
with
35 additions
and
0 deletions
address_utils/address_utils.go
+
21
−
0
View file @
76f36d59
...
...
@@ -3,6 +3,7 @@ package address_utils
import
(
"crypto/md5"
"fmt"
"math"
"regexp"
"strings"
...
...
@@ -275,3 +276,23 @@ func GetZoneDisplayName(zone string) string {
return
zone
}
func
GetDistanceInKmBetweenCoordinates
(
lat1
float64
,
lng1
float64
,
lat2
float64
,
lng2
float64
)
float64
{
radlat1
:=
float64
(
math
.
Pi
*
lat1
/
180
)
radlat2
:=
float64
(
math
.
Pi
*
lat2
/
180
)
theta
:=
float64
(
lng1
-
lng2
)
radtheta
:=
float64
(
math
.
Pi
*
theta
/
180
)
dist
:=
math
.
Sin
(
radlat1
)
*
math
.
Sin
(
radlat2
)
+
math
.
Cos
(
radlat1
)
*
math
.
Cos
(
radlat2
)
*
math
.
Cos
(
radtheta
)
if
dist
>
1
{
dist
=
1
}
dist
=
math
.
Acos
(
dist
)
dist
=
dist
*
180
/
math
.
Pi
dist
=
dist
*
60
*
1.1515
// Return in kilometers
return
dist
*
1.609344
}
This diff is collapsed.
Click to expand it.
string_utils/string_utils.go
+
14
−
0
View file @
76f36d59
...
...
@@ -151,6 +151,20 @@ func ConcatP(args ...*string) string {
return
s
}
// Concat concatenates all specified non-empty strings with ", " separators
func
Concat
(
args
[]
string
,
separator
string
)
string
{
s
:=
""
for
_
,
arg
:=
range
args
{
if
arg
!=
""
{
if
s
!=
""
{
s
+=
separator
}
s
+=
arg
}
}
return
s
}
func
ToJSONString
(
object
interface
{})
(
string
,
error
)
{
jsonBytes
,
err
:=
json
.
Marshal
(
&
object
)
if
err
!=
nil
{
...
...
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