Skip to content

Commit

Permalink
Restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
verzth committed Mar 14, 2022
1 parent fd84357 commit 26677ce
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 88 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#### Installation
```shell script
go get git.teknoku.digital/teknoku/go-utils
go get git.verzth.work/go/utils
```

#### Available Utils
Expand All @@ -13,7 +13,7 @@ package mypackage

import (
"fmt"
"git.teknoku.digital/teknoku/go-utils/utils"
"git.verzth.work/go/utils"
)

func main() {
Expand Down
42 changes: 21 additions & 21 deletions demo/Demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@ package main

import (
"fmt"
"git.teknoku.digital/teknoku/go-utils/utils"
"git.verzth.work/go/utils"
"os"
)

func main() {
fmt.Printf("RandString: %v\n", utils.RandString(20))
fmt.Printf("RandStringWithCharset: %v\n", utils.RandStringWithCharset(20,"abc123efg456"))
fmt.Printf("RandStringWithCharset: %v\n", utils.RandStringWithCharset(20, "abc123efg456"))
fmt.Printf("RandStringLower: %v\n", utils.RandStringLower(20))
fmt.Printf("RandomHex: %v\n",utils.RandomHex(16))
fmt.Printf("RandomHexUpper: %v\n",utils.RandomHexUpper(16))
fmt.Printf("RandomHex: %v\n", utils.RandomHex(16))
fmt.Printf("RandomHexUpper: %v\n", utils.RandomHexUpper(16))
ranString := utils.RandStringUpper(10)
fmt.Printf("RandStringUpper: %v\n",ranString) // 'ea10a9c919'
fmt.Printf("RandStringUpper: %v\n", ranString) // 'ea10a9c919'

fmt.Printf("Substring: %v\n", utils.Substring(ranString,2)) // '10a9c919'
fmt.Printf("Substring: %v\n", utils.Substring(ranString,1,8)) // 'a10a9c9'
fmt.Printf("Substring: %v\n", utils.Substring(ranString,6,2)) // ''
fmt.Printf("Substring: %v\n", utils.Substring(ranString,10,15)) // ''
fmt.Printf("Substring: %v\n", utils.Substring(ranString,-1,5)) // ''
fmt.Printf("Substring: %v\n", utils.Substring(ranString,5,10)) // '9c919'
fmt.Printf("Substring: %v\n", utils.Substring(ranString, 2)) // '10a9c919'
fmt.Printf("Substring: %v\n", utils.Substring(ranString, 1, 8)) // 'a10a9c9'
fmt.Printf("Substring: %v\n", utils.Substring(ranString, 6, 2)) // ''
fmt.Printf("Substring: %v\n", utils.Substring(ranString, 10, 15)) // ''
fmt.Printf("Substring: %v\n", utils.Substring(ranString, -1, 5)) // ''
fmt.Printf("Substring: %v\n", utils.Substring(ranString, 5, 10)) // '9c919'

arr := []int{ 1,2,3,4,5 }
arr := []int{1, 2, 3, 4, 5}
fmt.Printf("Array Before: %v\n", arr)
utils.Slice.RemoveAt(&arr, 3) // Remove slice at index
fmt.Printf("Array After 1: %v\n", arr)
utils.Slice.AddTo(&arr, 4, 3) // Add data to index 3
utils.Slice.AddTo(&arr, 4, 3) // Add data to index 3
fmt.Printf("Array After 2: %v\n", arr)
utils.Slice.AddTo(&arr, 25, 1) // Add data to index 1
fmt.Printf("Array After 3: %v\n", arr)
Expand All @@ -35,15 +35,15 @@ func main() {
utils.Slice.AddTo(&arr, -5) // Add data with minus index, will be added to first index which is treated as 0
fmt.Printf("Array After 5: %v\n", arr)
i := utils.Slice.Exist(&arr, 9)
fmt.Println("Exist",i)
fmt.Println("Exist", i)
j := utils.Slice.Exist(&arr, 100)
fmt.Println("Exist",j)
fmt.Println("Exist", j)

utils.FileMove("/root/project/filename","/root/project/newname", os.ModePerm) // Move file from path to path
utils.FileMove("/root/project/oldfolder/","/root/project/newfolder/", os.ModePerm, "filename") // Move file from to new location with same name
utils.FileMove("/root/project/oldfolder/","/root/project/newfolder/", os.ModePerm, "filename", "newname") // Move file from to new location with new name
utils.FileMove("/root/project/filename", "/root/project/newname", os.ModePerm) // Move file from path to path
utils.FileMove("/root/project/oldfolder/", "/root/project/newfolder/", os.ModePerm, "filename") // Move file from to new location with same name
utils.FileMove("/root/project/oldfolder/", "/root/project/newfolder/", os.ModePerm, "filename", "newname") // Move file from to new location with new name

arrDuplicate := []int{1,0,0,2,3,2,4,5,6,7,4,4,7,4,7,7,7,15}
arrDuplicate := []int{1, 0, 0, 2, 3, 2, 4, 5, 6, 7, 4, 4, 7, 4, 7, 7, 7, 15}
fmt.Println(arrDuplicate)
utils.Slice.Uniquify(&arrDuplicate)
fmt.Println(arrDuplicate)
Expand All @@ -55,7 +55,7 @@ func main() {
return objArr[i]["num"] == 2
})) // Get all value in slice with condition

fmt.Printf("First: %v\n", utils.Slice.First(objArr)) // Get first value in slice
fmt.Printf("First: %v\n", utils.Slice.First(objArr)) // Get first value in slice
fmt.Printf("IndexOf: %v\n", utils.Slice.IndexOf(arrDuplicate, 15)) // Find first index of value in slice
fmt.Printf("FirstWhere: %v\n", utils.Slice.FirstWhere(objArr, func(i int) bool {
return objArr[i]["num"] == 9
Expand All @@ -64,7 +64,7 @@ func main() {
return objArr[i]["id"] == 0
})) // Get first index in slice with given condition

fmt.Printf("Last: %v\n", utils.Slice.Last(objArr)) // Get first value in slice
fmt.Printf("Last: %v\n", utils.Slice.Last(objArr)) // Get first value in slice
fmt.Printf("LastIndexOf: %v\n", utils.Slice.LastIndexOf(arrDuplicate, 0)) // Find last index of value in slice
fmt.Printf("LastWhere: %v\n", utils.Slice.LastWhere(objArr, func(i int) bool {
return objArr[i]["id"] == 4
Expand Down
10 changes: 5 additions & 5 deletions utils/file.go → file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
)

func movePath(src string, dst string, perm os.FileMode) {
func movePath(src string, dst string, perm os.FileMode) {
oFile, err := ioutil.ReadFile(src)
if err == nil {
os.MkdirAll(dst, perm)
Expand All @@ -17,10 +17,10 @@ func movePath(src string, dst string, perm os.FileMode) {
}
}

func moveFile(src string, dst string, filename string, perm os.FileMode) {
moveFileRename(src,dst,filename,filename, perm)
func moveFile(src string, dst string, filename string, perm os.FileMode) {
moveFileRename(src, dst, filename, filename, perm)
}

func moveFileRename(src string, dst string, filename string, newname string, perm os.FileMode) {
func moveFileRename(src string, dst string, filename string, newname string, perm os.FileMode) {
movePath(src+filename, dst+newname, perm)
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module git.teknoku.digital/teknoku/go-utils
module git.verzth.work/go/utils

go 1.13
2 changes: 1 addition & 1 deletion utils/ranstring.go → ranstring.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ func RandomHex(n int) string {

func RandomHexUpper(n int) string {
return RandStringWithCharset(n, charsetHexUpper)
}
}
Loading

0 comments on commit 26677ce

Please sign in to comment.