Help us shape the future of Go! Take the 2026 Go Developer Survey

gitdoc

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2019 License: MIT Imports: 11 Imported by: 0

README

gitdoc

Library for managing documents using Git.

Getting Started

go get github.com/hellodhlyn/gitdoc

See godoc for documentation.

Development

Prerequisites
  • go 1.11+
Test
# Install all dependencies.
go mod download

# Run test.
# Gitdoc directly accesses to file system. For running test, it requires permissions to access `$HOME/.gitdoc` directory.
make test

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDocumentExists    = errors.New("document already exists")
	ErrDocumentNotExists = errors.New("document not exists")

	ErrCreateDocument = errors.New("failed to create document")
	ErrGetDocument    = errors.New("failed to open document")

	ErrInvalidOption = errors.New("invalid option")
)
View Source
var (
	ErrInitNotEmpty = errors.New("path to initialized not empty")
	ErrInitFailed   = errors.New("failed to initialize repository")
)

Functions

This section is empty.

Types

type CompareOutputOption

type CompareOutputOption int8

CompareOutputOption is a type for options to select the style of diffs.

const (
	// CompareOutputHTML is a option to present diffs as HTML string.
	CompareOutputHTML CompareOutputOption = iota

	// CompareOutputText is a option to present diffs as a colored string.
	// Recommended for terminal uses.
	CompareOutputText
)

type Document

type Document struct {
	ID       string
	Body     string
	Revision DocumentRevision
}

type DocumentRevision

type DocumentRevision struct {
	Hash      string
	UpdatedAt *time.Time
}

type InitOptions

type InitOptions struct {
	Path string

	// Author** fields used as signature for commit.
	AuthorName  string // deafult value: "gitdoc"
	AuthorEmail string // default value: "-"
}

type Repository

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

func Init

func Init(opt *InitOptions) (*Repository, error)

func (*Repository) CompareDocumentRevisions

func (r *Repository) CompareDocumentRevisions(id, revHashFrom, revHashTo string, typ CompareOutputOption) (string, error)

CompareDocumentRevisions show diffs of two revisions of the document.

func (*Repository) CreateDocument

func (r *Repository) CreateDocument(id string, body string) (*Document, error)

CreateDocument makes new file in the repository. It returns ErrDocumentExists if given ID already exists.

func (*Repository) GetDocument

func (r *Repository) GetDocument(id string) (*Document, error)

GetDocument returns latest revision of the document.

func (*Repository) GetDocumentAtRevision

func (r *Repository) GetDocumentAtRevision(id string, revisionHash string) (*Document, error)

GetDocumentAtRevision returns specific revision of the document.

func (*Repository) GetDocumentIDs

func (r *Repository) GetDocumentIDs() ([]string, error)

GetDocumentIDs returns list of id for all documents. TODO - Implement pagination

func (*Repository) GetDocumentRevisions

func (r *Repository) GetDocumentRevisions(id string) ([]DocumentRevision, error)

GetDocumentRevisions returns all revisions of the document. TODO - Implement pagination

func (*Repository) UpdateDocument

func (r *Repository) UpdateDocument(id string, newBody string) (*Document, error)

UpdateDocument update the body of existing document and create new revision. It returns ErrDocumentNotExists if given ID doesn't exist.

Jump to

Keyboard shortcuts

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