-
Notifications
You must be signed in to change notification settings - Fork 0
Utils Function
samithiwat edited this page Feb 12, 2023
·
3 revisions
Utils function is the function that can be use in a various scenario
the function use for convert bool
to *bool
boolPtr := gosdk.BoolAdr(boolean)
name | description | example |
---|---|---|
boolean | the boolean value | true |
name | description | example |
---|---|---|
boolPtr | the boolean pointer |
the function use for convert string
to *string
stringPtr := gosdk.StringAdr(string)
name | description | example |
---|---|---|
string | the string value | "hello world" |
name | description | example |
---|---|---|
stringPtr | the string pointer |
the function use for convert int
to *int
intPtr := gosdk.IntAdr(int)
name | description | example |
---|---|---|
int | the int value | 999 |
name | description | example |
---|---|---|
intPtr | the int pointer |
the function use for convert uuid.UUID
to *uuid.UUID
uuidPtr := gosdk.UUIDAdr(uuid)
name | description | example |
---|---|---|
uuid | the uuid value |
name | description | example |
---|---|---|
uuidPtr | the uuid pointer |
the function use to get the current time pointer
currentTimePtr := gosdk.GetCurrentTimePtr()
name | description | example |
---|---|---|
currentTimePtr | current time pointer in *time.Time
|
the function use to get the 2 last digit of current year
year2Digit := gosdk.GetCurrentYear2Digit()
name | description | example |
---|---|---|
year2Digit | current year in 2 last digit int
|
66 |
the function use to get the current year of student from the student id
year, err := gosdk.CalYearFromID(studentID)
if err != nil{
// handle error
}
name | description | example |
---|---|---|
studentID | the student id | 633xxxxx21 |
name | description | example |
---|---|---|
year | the year from student id | 3 |
Check is the variable existed in map
if ok := gosdk.IsExisted(map, key); !ok {
// handle error
}
name | description | example |
---|---|---|
map | the map structure | |
key | the key of map that you want to check | "hello" |
name | description | example |
---|---|---|
ok | boolean is existed | true |
merge slices of string into one slice
resultSlice := gosdk.MergeStringSlice(slice1, slice2, ...)
name | description | example |
---|---|---|
slice | the string slice |
name | description | example |
---|---|---|
resultSlice | the slice of string that was merged | true |
Trim the string if existed in list
result := gosdk.TrimInList(word, sep, trimList)
name | description | example |
---|---|---|
word | the input word | /v1/path |
sep | the separate work | / |
trimList | the list of word that want to trim in map[string]struct
|
map[string]struct{}{"v1": {}} |
name | description | example |
---|---|---|
result | result string that was trimmed | /path |