music

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintTracks

func PrintTracks(tracks []*Track)
Example
length := func(s string) time.Duration {
	d, err := time.ParseDuration(s)
	if err != nil {
		panic(s)
	}
	return d
}
var tracks = []*Track{
	{"Go", "Delilah", "From the Roots Up", 2012, length("3m38s")},
	{"Go", "Moby", "Moby", 1992, length("3m37s")},
	{"Go Ahead", "Alicia Keys", "As I Am", 2007, length("4m36s")},
	{"Ready 2 Go", "Martin Solveig", "Smash", 2011, length("4m24s")},
}
fmt.Println("Click Artist once:")
sort.Sort(ByTitle(tracks))
PrintTracks(tracks)
fmt.Println("Click Artist twice:")
sort.Sort(sort.Reverse(ByTitle(tracks)))
PrintTracks(tracks)
fmt.Println("Click Year once:")
sort.Sort(ByYear(tracks))
PrintTracks(tracks)
fmt.Println("Click Year twice:")
sort.Sort(sort.Reverse(ByYear(tracks)))
PrintTracks(tracks)
fmt.Println("Custom sorting: Title, Year, Length:")
sort.Sort(CustomSort{t: tracks, less: func(x, y *Track) bool {
	if x.Title != y.Title {
		return x.Title < y.Title
	}
	if x.Year != y.Year {
		return x.Year < y.Year
	}
	if x.Length != y.Length {
		return x.Length < y.Length
	}
	return false
}})
PrintTracks(tracks)
Output:

func PrintTracksAsHTML

func PrintTracksAsHTML(tracks []*Track) (HTMLString string, err error)

Types

type ByAlbum

type ByAlbum []*Track

func (ByAlbum) At

func (x ByAlbum) At(i int) interface{}

func (ByAlbum) Len

func (x ByAlbum) Len() int

func (ByAlbum) Less

func (x ByAlbum) Less(i, j int) bool

func (ByAlbum) Swap

func (x ByAlbum) Swap(i, j int)

type ByArtist

type ByArtist []*Track

func (ByArtist) At

func (x ByArtist) At(i int) interface{}

func (ByArtist) Len

func (x ByArtist) Len() int

func (ByArtist) Less

func (x ByArtist) Less(i, j int) bool

func (ByArtist) Swap

func (x ByArtist) Swap(i, j int)

type ByLength

type ByLength []*Track

func (ByLength) At

func (x ByLength) At(i int) interface{}

func (ByLength) Len

func (x ByLength) Len() int

func (ByLength) Less

func (x ByLength) Less(i, j int) bool

func (ByLength) Swap

func (x ByLength) Swap(i, j int)

type ByTitle

type ByTitle []*Track

func (ByTitle) At

func (x ByTitle) At(i int) interface{}

func (ByTitle) Len

func (x ByTitle) Len() int

func (ByTitle) Less

func (x ByTitle) Less(i, j int) bool

func (ByTitle) Swap

func (x ByTitle) Swap(i, j int)

type ByYear

type ByYear []*Track

func (ByYear) At

func (x ByYear) At(i int) interface{}

func (ByYear) Len

func (x ByYear) Len() int

func (ByYear) Less

func (x ByYear) Less(i, j int) bool

func (ByYear) Swap

func (x ByYear) Swap(i, j int)

type CustomSort

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

func (CustomSort) Len

func (x CustomSort) Len() int

func (CustomSort) Less

func (x CustomSort) Less(i, j int) bool

func (CustomSort) Swap

func (x CustomSort) Swap(i, j int)

type Track

type Track struct {
	Title  string
	Artist string
	Album  string
	Year   int
	Length time.Duration
}

Jump to

Keyboard shortcuts

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