summaryrefslogtreecommitdiff
path: root/pkg/bash/bash.go
blob: 7a377ef7229471ba17caf26bb0258addedbb7d57 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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, &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"`
}