diff options
Diffstat (limited to 'pkg/bash/bash.go')
-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"` +} |