From 970e8578c5326ad236304ecbaba05920c80448bd Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 23 Oct 2018 12:34:16 -0400 Subject: License under the AGPL --- frontend.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'frontend.go') diff --git a/frontend.go b/frontend.go index 285bbd9..108a1b1 100644 --- a/frontend.go +++ b/frontend.go @@ -1,3 +1,18 @@ +// Copyright (C) 2017 Luke Shumaker +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + package libfastimport import ( -- cgit v1.2.3 From 392cc1262df7203a6c8b4f6b692cd69950ccc598 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 23 Oct 2018 13:31:53 -0400 Subject: Add godoc comments --- frontend.go | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'frontend.go') diff --git a/frontend.go b/frontend.go index 108a1b1..dc8e771 100644 --- a/frontend.go +++ b/frontend.go @@ -1,4 +1,4 @@ -// Copyright (C) 2017 Luke Shumaker +// Copyright (C) 2017-2018 Luke Shumaker // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by @@ -30,7 +30,13 @@ func (e UnsupportedCommand) Error() string { } // A Frontend is something that produces a fast-import stream; the -// Frontend object provides methods for reading from it. +// Frontend object provides methods for reading from it. A program +// that writes to a Frontend would itself be a backend. +// +// You may think of a "Frontend" object as a "Reader" object, though +// it was not given that name because the RespondGetMark, +// RespondCatBlob, and RespondLs methods actually write information; +// it isn't a read-only object. type Frontend struct { fastImport *parser catBlobWrite *textproto.CatBlobWriter @@ -39,6 +45,14 @@ type Frontend struct { onErr func(error) error } +// NewFrontend creates a new Frontend object that reads from the given +// io.Reader. +// +// Optionally, you may also provide an io.Writer that responses to +// "cat-blob", "get-mark", and "ls" commands can be written to. +// +// Optionally, you may also provide an onErr function that can bue +// used to handle or transform errors when they are encountered. func NewFrontend(fastImport io.Reader, catBlob io.Writer, onErr func(error) error) *Frontend { ret := &Frontend{} @@ -58,6 +72,7 @@ func NewFrontend(fastImport io.Reader, catBlob io.Writer, onErr func(error) erro return ret } +// ReadCmd reads a command from the Frontend. func (f *Frontend) ReadCmd() (Cmd, error) { cmd, err := f.fastImport.ReadCmd() if err != nil { @@ -66,6 +81,11 @@ func (f *Frontend) ReadCmd() (Cmd, error) { return cmd, err } +// RespondGetMark sends to the Frontend a response to a "get-mark" +// command. +// +// It is an error (panic) to call RespondGetMark if NewFrontend did +// not have a cat-blob writer passed to it. func (f *Frontend) RespondGetMark(sha1 string) error { err := f.catBlobWrite.WriteLine(sha1) if err != nil { @@ -74,6 +94,11 @@ func (f *Frontend) RespondGetMark(sha1 string) error { return f.catBlobFlush.Flush() } +// RespondCatBlob sends to the Frontend a response to a "cat-blob" +// command. +// +// It is an error (panic) to call RespondCatBlob if NewFrontend did +// not have a cat-blob writer passed to it. func (f *Frontend) RespondCatBlob(sha1 string, data string) error { err := f.catBlobWrite.WriteBlob(sha1, data) if err != nil { @@ -82,6 +107,10 @@ func (f *Frontend) RespondCatBlob(sha1 string, data string) error { return f.catBlobFlush.Flush() } +// RespondLs sends to the Frontend a response to a "ls" command. +// +// It is an error (panic) to call RespondLs if NewFrontend did not +// have a cat-blob writer passed to it. func (f *Frontend) RespondLs(mode textproto.Mode, dataref string, path textproto.Path) error { var err error if mode == 0 { -- cgit v1.2.3