cats

package module
v0.0.0-...-3b88529 Latest Latest
Warning

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

Go to latest
Published: May 29, 2019 License: MIT Imports: 4 Imported by: 0

README

GoDoc Build Status Coverage Status Go Report Card

cats

Go category library for creating and outputting a tree in various formats.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category struct {
	ID       int
	Name     string
	Icon     string
	Parent   int
	Path     string
	Children []*Category
}

Category model.

type CategoryMap

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

CategoryMap a map of Category pointers and associates an index with it, for ordered output. The order of the index is based on the order items where added.

func NewCm

func NewCm() *CategoryMap

NewCm initializes and returs a pointer to a new CategoryMap.

func (*CategoryMap) GeneratePaths

func (cm *CategoryMap) GeneratePaths()

GeneratePaths generate paths for each category

func (*CategoryMap) Get

func (cm *CategoryMap) Get(id int) (c *Category)

Get a Category pointer by its id.

func (*CategoryMap) Index

func (cm *CategoryMap) Index() []int

Index returns a struct of category id. It allows for a sorted range loop.

func (*CategoryMap) JSONTree

func (cm *CategoryMap) JSONTree(offset int) ([]byte, error)

JSONTree returns a JSON document, representing the parent / child relationship of the categories in a tree. It returns an error if json.Marshall does.

func (*CategoryMap) Set

func (cm *CategoryMap) Set(c *Category)

Set a Category point to the map. It will also be appended to the index, keeping the order of calling this function.

func (*CategoryMap) Sort

func (cm *CategoryMap) Sort()

Sort re-indexes the CategoryMap, increasing order on category id. It is advised to add the categories in a sorted way instead of using this method.

func (*CategoryMap) Tree

func (cm *CategoryMap) Tree(offset int) (root []*Category)

Tree creates decendant tree by population the Category's children. It returns a slice of Category pointers, representing the root of the tree.

func (*CategoryMap) XMLTree

func (cm *CategoryMap) XMLTree(offset int) ([]byte, error)

XMLTree returns a XML document, representing the parent / child relationship of the categories in a tree. It returns an error if XML.Marshall does.

Jump to

Keyboard shortcuts

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