diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-07-21 11:04:46 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-07-21 11:04:46 +0300 |
| commit | 12558447c73da90f63276143f4d6a8796ec2fe7b (patch) | |
| tree | fad42fa04b56d497d7251bf4270f7c427ba8feea /go-src/utils | |
| parent | 7457f7af8effa21ecf328058475e944e46075670 (diff) | |
| download | ctfc-12558447c73da90f63276143f4d6a8796ec2fe7b.tar ctfc-12558447c73da90f63276143f4d6a8796ec2fe7b.tar.gz ctfc-12558447c73da90f63276143f4d6a8796ec2fe7b.zip | |
Implemented a very hardcoded way for chat message pagination and real time updating
Diffstat (limited to 'go-src/utils')
| -rw-r--r-- | go-src/utils/utils.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/go-src/utils/utils.go b/go-src/utils/utils.go index 754c7ed..c1bd8a4 100644 --- a/go-src/utils/utils.go +++ b/go-src/utils/utils.go @@ -1,6 +1,8 @@ package utils -import "os" +import ( + "os" +) // Repeats a rune given amount of times and returns the result as a string func RepeatRune(r rune, times int) (result string) { @@ -31,3 +33,11 @@ func AppendToFile(path string, value string) { allChatsFile.WriteString(value) allChatsFile.Close() } + +func TotalPages(maxSize int, messageAmount int) int { + return messageAmount / maxSize +} + +func Paginate(page int, maxSize int, messages ...string) []string { + return messages[len(messages)-maxSize*page : len(messages)-maxSize*(page-1)] +} |
