summaryrefslogblamecommitdiff
path: root/pkg/bash/bash.go
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, &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"`
}