summaryrefslogtreecommitdiff
path: root/pkg/bash/bash.go
diff options
context:
space:
mode:
authorNeonXP <i@neonxp.dev>2023-01-04 18:52:25 +0300
committerNeonXP <i@neonxp.dev>2023-01-04 18:52:25 +0300
commit5947c1d643dfc077c19d3b4c01e599578e1dfe62 (patch)
tree6723c5982626403a507ed25c74711ae74eccbe23 /pkg/bash/bash.go
Diffstat (limited to 'pkg/bash/bash.go')
-rw-r--r--pkg/bash/bash.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/pkg/bash/bash.go b/pkg/bash/bash.go
new file mode 100644
index 0000000..7a377ef
--- /dev/null
+++ b/pkg/bash/bash.go
@@ -0,0 +1,27 @@
+package bash
+
+import (
+ "encoding/json"
+ "math/rand"
+ "os"
+ "time"
+)
+
+func Get() (*QuoteElem, error) {
+ f, err := os.ReadFile("db/quotes.json")
+ if err != nil {
+ return nil, err
+ }
+ quotes := []QuoteElem{}
+ if err := json.Unmarshal(f, &quotes); err != nil {
+ return nil, err
+ }
+ rand.Seed(time.Now().UnixMicro())
+ return &quotes[rand.Intn(len(quotes))], nil
+}
+
+type QuoteElem struct {
+ Num int `json:"num"`
+ Body string `json:"body"`
+ Date string `json:"date"`
+}