mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2026-05-19 09:15:47 +08:00
Initial commit
This commit is contained in:
9
util/hash.go
Normal file
9
util/hash.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package util
|
||||
|
||||
import "hash/fnv"
|
||||
|
||||
func Hash64(s string) uint64 {
|
||||
h := fnv.New64()
|
||||
h.Write([]byte(s))
|
||||
return h.Sum64()
|
||||
}
|
||||
7
util/image.go
Normal file
7
util/image.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package util
|
||||
|
||||
import "image"
|
||||
|
||||
func ReadImage(path string) image.Image {
|
||||
return nil
|
||||
}
|
||||
40
util/string.go
Normal file
40
util/string.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func SliceString(str string, from int, to int) (string, bool) {
|
||||
sList := []rune(str)
|
||||
if to <= 0 {
|
||||
to = len(sList) + to
|
||||
}
|
||||
if from >= len(sList) || to > len(sList) {
|
||||
return "", false
|
||||
}
|
||||
return string(sList[from:to]), true
|
||||
}
|
||||
|
||||
func LenString(str string) int {
|
||||
return len([]rune(str))
|
||||
}
|
||||
|
||||
func StringNormalize(str string, min int, max int) string {
|
||||
fmtStr := fmt.Sprintf("%%-%d.%ds", min, max)
|
||||
return fmt.Sprintf(fmtStr, str)
|
||||
}
|
||||
|
||||
func StringSliceContains(s []string, e string) bool {
|
||||
for _, a := range s {
|
||||
if a == e {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func StringToInt(s string) int {
|
||||
i, _ := strconv.Atoi(s)
|
||||
return i
|
||||
}
|
||||
7
util/time.go
Normal file
7
util/time.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package util
|
||||
|
||||
import "fmt"
|
||||
|
||||
func FormatTime(time int) string {
|
||||
return fmt.Sprintf("%01d:%02d", time/60, time%60)
|
||||
}
|
||||
10
util/time_test.go
Normal file
10
util/time_test.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFormatTime(t *testing.T) {
|
||||
fmt.Println(FormatTime(60 * 60))
|
||||
}
|
||||
Reference in New Issue
Block a user