candystore

package
v0.0.0-...-63cbb16 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ReportUsersFile is the name of the JSON file to be created
	ReportUsersFile = "report.json"

	// FileMode is the file mode to be used when creating the JSON file
	FileMode = 0644
)

Variables

This section is empty.

Functions

func ReportUsers

func ReportUsers(users []*Users) ([]byte, error)

ReportUsers creates a JSON file with the users and snacks Returns file content is bytes an error if the file cannot be created

Types

type Users

type Users struct {
	NameUser   string           `json:"name"`
	FavSnack   string           `json:"favouriteSnack"`
	EatenSnack int64            `json:"totalSnacks"`
	HeapSnack  map[string]int64 `json:"-"` // Emulate a Max Heap, to get the most frequent snack
}

Users represents a user, his favourite snack and the number of snacks eaten

func ReadUsersFile

func ReadUsersFile(file string) ([]*Users, error)

ReadUsersFile reads a CSV file and returns a slice of users, snacks and eaten snacks The CSV file must have the following columns: name, favourite snack, total snacks Returns an error if the file cannot be read

Jump to

Keyboard shortcuts

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