From 5947c1d643dfc077c19d3b4c01e599578e1dfe62 Mon Sep 17 00:00:00 2001 From: NeonXP Date: Wed, 4 Jan 2023 18:52:25 +0300 Subject: init --- pkg/bash/bash.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 pkg/bash/bash.go (limited to 'pkg/bash') 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, "es); err != nil { + return nil, err + } + rand.Seed(time.Now().UnixMicro()) + return "es[rand.Intn(len(quotes))], nil +} + +type QuoteElem struct { + Num int `json:"num"` + Body string `json:"body"` + Date string `json:"date"` +} -- cgit v1.2.3