diff options
author | NeonXP <i@neonxp.dev> | 2023-01-04 18:52:25 +0300 |
---|---|---|
committer | NeonXP <i@neonxp.dev> | 2023-01-04 18:52:25 +0300 |
commit | 5947c1d643dfc077c19d3b4c01e599578e1dfe62 (patch) | |
tree | 6723c5982626403a507ed25c74711ae74eccbe23 /pkg/bash |
Diffstat (limited to 'pkg/bash')
-rw-r--r-- | pkg/bash/bash.go | 27 |
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, "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"` +} |