diary

package module
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2021 License: MIT Imports: 16 Imported by: 0

README

Go-diary

CircleCI

Go-diary is a tool for managing diaries.

Contents

Usage

Install

Install with go tool
go get github.com/komem3/go-diary/cmd/diary

Target File

Target diary file is YYYYMMDD*.*.

  • good example: 20200102.md, 19990912_test.md, 19990912.txt
  • bad example: diary_20111102.md, 202011.md

Sample Case

$ pwd
${GOPATH}/src/github.com/komem3/diary/sample

$ tree
.
├── 20021201.md
├── 20200101.md
└── 20200102.txt

$ diary init
$ ls
20021201.md  20200101.md  20200102.txt template

$ diary format
$ tree
.
├── 2002
│   └── 12
│       └── 20021201.md
├── 2020
│   ├── 01
│   │   ├── 20200101.md
│   │   └── 20200102.txt
│   └── 02
│       └── 20200202.org
├── README.md
└── template
    ├── diary.template.md
    └── top.template.md

$ diary new
$ ls
2002  2020  20200531.md  README.md  template
$ cat 20200531.md
2020/05/31 (Sunday)

Template Variables

top.template.md
  • Base: Base path.
  • Years: Slice of year element.
    • Year
    • Months: Slice of month element.
      • Month
      • Days: Slice of day element.
        • Day
        • Path: Path from base.
diary.template.md
  • Year
  • Month
  • Day
  • Weekday

Licence

MIT

Author

komem3

Documentation

Index

Constants

View Source
const ErrLogOut = "log output: %v\n"

Variables

View Source
var ErrNotParamater = errors.New("insufficient parameters")

Functions

func CloseWithErrLog

func CloseWithErrLog(l Logger, c Closer)

func Initialize

func Initialize(l Logger, dir string, tmplDir string, files []string) error

Initialize create template files.

Types

type Closer

type Closer interface {
	Close() error
}

type Creator

type Creator struct {
	Err error
	// contains filtered or unexported fields
}

Creator generate file.

func NewCreator

func NewCreator(l Logger) *Creator

NewCreator generate Creator.

func (*Creator) NewDiary

func (c *Creator) NewDiary(tmplFile, dir, nameFormat string) (filePath string)

NewDiary generate today diary.

func (*Creator) SetNowFunc

func (c *Creator) SetNowFunc(now func() time.Time)

SetNowFunc sets the function that returns the current time.

type Day

type Day string

type DayElem

type DayElem struct {
	Day
	Path string
}

type FileMap

type FileMap map[Year]map[Month]map[Day]string

type Formatter

type Formatter struct {
	Err error
	// contains filtered or unexported fields
}

Formatter is generator diary.

func NewFormatter

func NewFormatter(logger Logger) *Formatter

NewFormatter generate Formatter.

func (*Formatter) FormatDir

func (f *Formatter) FormatDir(fMap FileMap, to string, move bool) *Formatter

FormatDir format directory.

func (Formatter) Map2Elem

func (f Formatter) Map2Elem(fMap FileMap, optionFuncs ...Map2ElemOptionFunc) (elem TopElem)

Map2Elem convert FileMap to TopElem.

func (Formatter) ParseFileMap

func (f Formatter) ParseFileMap(root string) FileMap

ParseFileMap analys dir and parse FileMap.

Hidden files and directories are ignored.

func (*Formatter) WriteDirTree

func (f *Formatter) WriteDirTree(elem TopElem, filePath, templatePath, to string) *Formatter

WriteDirTree write directory tree.

type Logger

type Logger interface {
	Debug(args ...interface{})
	Warn(args ...interface{})
	Error(args ...interface{})
}

func NewLogger

func NewLogger(verbose bool) Logger

type Map2ElemOptionFunc added in v1.1.0

type Map2ElemOptionFunc func(*map2ElemOption)

func DaySort added in v1.1.0

func DaySort(s SortType) Map2ElemOptionFunc

DaySort specify day sort.

func MonthSort added in v1.1.0

func MonthSort(s SortType) Map2ElemOptionFunc

MonthSort specify month sort.

func YearSort added in v1.1.0

func YearSort(s SortType) Map2ElemOptionFunc

YearSort specify year sort.

type Month

type Month string

type MonthElem

type MonthElem struct {
	Month
	Days []DayElem
}

type SortType added in v1.1.0

type SortType int
const (
	InValid SortType = iota
	ASCSort
	DESCSort
)

type TopElem

type TopElem struct {
	Base  string
	Years []YearElem
}

type Year

type Year string

type YearElem

type YearElem struct {
	Year
	Months []MonthElem
}

Directories

Path Synopsis
cmd
doc

Jump to

Keyboard shortcuts

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