blob: 7a377ef7229471ba17caf26bb0258addedbb7d57 (
plain) (
tree)
|
|
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"`
}
|