feedback

package
v0.1.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package feedback stores user votes on answers so confirmed answers rise and corrected ones sink in future rankings. Votes live in their own file, apart from the index, so they survive re-indexing.

Index

Constants

View Source
const (
	// Helpful marks a result the user confirmed.
	Helpful = 1
	// NotHelpful marks a result the user corrected.
	NotHelpful = -1
)

Votes a user can cast on one result.

Variables

View Source
var ErrBadEntry = errors.New("entry needs a query, one target, and a helpful or not-helpful vote")

ErrBadEntry reports a vote missing its query, target, or a known vote value.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	// Query is the question as asked.
	Query string `json:"query"`
	// Person is the voted person's identifier, when the vote is on a person.
	Person string `json:"person,omitempty"`
	// Channel is the voted channel's identifier, when the vote is on a channel.
	Channel string `json:"channel,omitempty"`
	// Vote is Helpful or NotHelpful.
	Vote int `json:"vote"`
	// Comment is an optional note explaining the vote.
	Comment string `json:"comment,omitempty"`
	// Time is when the vote was cast.
	Time time.Time `json:"time"`
}

Entry is one vote on one result for one question.

func (Entry) Valid

func (e Entry) Valid() bool

Valid reports whether the entry names a query, exactly one target, and a known vote.

type Filter added in v0.1.18

type Filter struct {
	// Query matches entries for this exact question, case-insensitively.
	Query string
	// Person matches votes on this person identifier.
	Person string
	// Channel matches votes on this channel name.
	Channel string
}

Filter selects the votes to list or clear. Zero fields match everything; set fields must all match.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store holds votes and persists them as JSON. It is safe for concurrent use.

func Load

func Load(path string) (*Store, error)

Load reads a store from path. A missing file yields an empty store.

func (*Store) Add

func (s *Store) Add(e Entry) error

Add records a vote and persists the store.

func (*Store) All

func (s *Store) All() []Entry

All returns a copy of the recorded votes.

func (*Store) Clear added in v0.1.18

func (s *Store) Clear(f Filter) (int, error)

Clear removes the votes matching f, persists the store, and returns how many were removed.

func (*Store) List added in v0.1.18

func (s *Store) List(f Filter) []Entry

List returns the votes matching f, oldest first.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL