From fa4898e9e6d59d370908cba709acb308594e3e9a Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Thu, 15 Feb 2024 09:43:14 -0800 Subject: [PATCH] initial commits --- errors.go | 9 +++ framewriter.go | 69 +++++++++++++++++++++ framewriter_internal.go | 101 +++++++++++++++++++++++++++++++ writeframe.go | 4 +- writeframebutton1.go | 4 +- writeframebutton1action.go | 4 +- writeframebutton1target.go | 4 +- writeframebutton2.go | 4 +- writeframebutton2action.go | 4 +- writeframebutton2target.go | 4 +- writeframebutton3.go | 4 +- writeframebutton3action.go | 4 +- writeframebutton3target.go | 4 +- writeframebutton4.go | 4 +- writeframebutton4action.go | 4 +- writeframebutton4target.go | 4 +- writeframeimage.go | 4 +- writeframeimageaspectratio.go | 4 +- writeframeinputtext.go | 4 +- writeframeposturl.go | 4 +- writemetapropertycontent.go | 7 ++- writemetapropertycontent_test.go | 9 ++- 22 files changed, 225 insertions(+), 38 deletions(-) create mode 100644 errors.go create mode 100644 framewriter.go create mode 100644 framewriter_internal.go diff --git a/errors.go b/errors.go new file mode 100644 index 0000000..ee992a2 --- /dev/null +++ b/errors.go @@ -0,0 +1,9 @@ +package frameproto + +import ( + "sourcecode.social/reiver/go-erorr" +) + +const ( + errNilWriter = erorr.Error("frameproto: nil writer") +) diff --git a/framewriter.go b/framewriter.go new file mode 100644 index 0000000..dbc256e --- /dev/null +++ b/framewriter.go @@ -0,0 +1,69 @@ +package frameproto + +// +type FrameWriter interface { + // + WriteFrame(version string) error + + + + // + WriteFrameButton1(label string) error + + // + WriteFrameButton1Action(action string) error + + // + WriteFrameButton1Target(buttonTarget string) error + + + + // + WriteFrameButton2(label string) error + + // + WriteFrameButton2Action(action string) error + + // + WriteFrameButton2Target(target string) error + + + + // + WriteFrameButton3(label string) error + + // + WriteFrameButton3Action(buttonAction string) error + + // + WriteFrameButton3Target(buttonTarget string) error + + + + // + WriteFrameButton4(label string) error + + // + WriteFrameButton4Action(action string) error + + // + WriteFrameButton4Target(target string) error + + + + // + WriteFrameImage(url string) error + + // + WriteFrameImageAspectRatio(aspectRatio string) error + + + + // + WriteFrameInputText(label string) error + + + + // + WriteFramePostURL(url string) error +} diff --git a/framewriter_internal.go b/framewriter_internal.go new file mode 100644 index 0000000..a95732a --- /dev/null +++ b/framewriter_internal.go @@ -0,0 +1,101 @@ +package frameproto + +import ( + "io" +) + +type internalFrameWriter struct { + writer io.Writer +} + +var _ FrameWriter = internalFrameWriter{} + +func CreateFrameWriter(writer io.Writer) FrameWriter { + return internalFrameWriter{ + writer:writer, + } +} + + + +func (receiver internalFrameWriter) WriteFrame(version string) error { + return WriteFrame(receiver.writer, version) +} + + + +func (receiver internalFrameWriter) WriteFrameButton1(label string) error { + return WriteFrameButton1(receiver.writer, label) +} + +func (receiver internalFrameWriter) WriteFrameButton1Action(label string) error { + return WriteFrameButton1Action(receiver.writer, label) +} + +func (receiver internalFrameWriter) WriteFrameButton1Target(target string) error { + return WriteFrameButton1Target(receiver.writer, target) +} + + + +func (receiver internalFrameWriter) WriteFrameButton2(label string) error { + return WriteFrameButton2(receiver.writer, label) +} + +func (receiver internalFrameWriter) WriteFrameButton2Action(label string) error { + return WriteFrameButton2Action(receiver.writer, label) +} + +func (receiver internalFrameWriter) WriteFrameButton2Target(target string) error { + return WriteFrameButton2Target(receiver.writer, target) +} + + + +func (receiver internalFrameWriter) WriteFrameButton3(label string) error { + return WriteFrameButton3(receiver.writer, label) +} + +func (receiver internalFrameWriter) WriteFrameButton3Action(label string) error { + return WriteFrameButton3Action(receiver.writer, label) +} + +func (receiver internalFrameWriter) WriteFrameButton3Target(target string) error { + return WriteFrameButton3Target(receiver.writer, target) +} + + + +func (receiver internalFrameWriter) WriteFrameButton4(label string) error { + return WriteFrameButton4(receiver.writer, label) +} + +func (receiver internalFrameWriter) WriteFrameButton4Action(label string) error { + return WriteFrameButton4Action(receiver.writer, label) +} + +func (receiver internalFrameWriter) WriteFrameButton4Target(target string) error { + return WriteFrameButton4Target(receiver.writer, target) +} + + + +func (receiver internalFrameWriter) WriteFrameImage(url string) error { + return WriteFrameImage(receiver.writer, url) +} + +func (receiver internalFrameWriter) WriteFrameImageAspectRatio(aspectRatio string) error { + return WriteFrameImageAspectRatio(receiver.writer, aspectRatio) +} + + + +func (receiver internalFrameWriter) WriteFrameInputText(label string) error { + return WriteFrameInputText(receiver.writer, label) +} + + + +func (receiver internalFrameWriter) WriteFramePostURL(url string) error { + return WriteFramePostURL(receiver.writer, url) +} diff --git a/writeframe.go b/writeframe.go index eccb57b..62bc71f 100644 --- a/writeframe.go +++ b/writeframe.go @@ -22,7 +22,7 @@ import ( // Which in code would be used as: // // str := frameproto.WriteFrame(writer, frameproto.VersionVNext) -func WriteFrame(writer io.Writer, version string) { +func WriteFrame(writer io.Writer, version string) error { const property string = MetaPropertyFrame - writeMetaPropertyContent(writer, property, version) + return writeMetaPropertyContent(writer, property, version) } diff --git a/writeframebutton1.go b/writeframebutton1.go index d68973d..04f25ec 100644 --- a/writeframebutton1.go +++ b/writeframebutton1.go @@ -15,7 +15,7 @@ import ( // Would write this HTML element: // // -func WriteFrameButton1(writer io.Writer, label string) { +func WriteFrameButton1(writer io.Writer, label string) error { const property string = MetaPropertyFrameButton1 - writeMetaPropertyContent(writer, property, label) + return writeMetaPropertyContent(writer, property, label) } diff --git a/writeframebutton1action.go b/writeframebutton1action.go index be83868..be86e01 100644 --- a/writeframebutton1action.go +++ b/writeframebutton1action.go @@ -38,7 +38,7 @@ import ( // // // // frameproto.WriteFrameButton1Action(writer, frameproto.ButtonActionPostRedirect) -func WriteFrameButton1Action(writer io.Writer, action string) { +func WriteFrameButton1Action(writer io.Writer, action string) error { const property string = MetaPropertyFrameButton1Action - writeMetaPropertyContent(writer, property, action) + return writeMetaPropertyContent(writer, property, action) } diff --git a/writeframebutton1target.go b/writeframebutton1target.go index 12456d0..261feef 100644 --- a/writeframebutton1target.go +++ b/writeframebutton1target.go @@ -15,7 +15,7 @@ import ( // Would write this HTML element: // // -func WriteFrameButton1Target(writer io.Writer, target string) { +func WriteFrameButton1Target(writer io.Writer, target string) error { const property string = MetaPropertyFrameButton1Target - writeMetaPropertyContent(writer, property, target) + return writeMetaPropertyContent(writer, property, target) } diff --git a/writeframebutton2.go b/writeframebutton2.go index a912bab..14a7139 100644 --- a/writeframebutton2.go +++ b/writeframebutton2.go @@ -15,7 +15,7 @@ import ( // Would write this HTML element: // // -func WriteFrameButton2(writer io.Writer, label string) { +func WriteFrameButton2(writer io.Writer, label string) error { const property string = MetaPropertyFrameButton2 - writeMetaPropertyContent(writer, property, label) + return writeMetaPropertyContent(writer, property, label) } diff --git a/writeframebutton2action.go b/writeframebutton2action.go index 91ca267..57aa5b4 100644 --- a/writeframebutton2action.go +++ b/writeframebutton2action.go @@ -38,7 +38,7 @@ import ( // // // // frameproto.WriteFrameButton2Action(writer, frameproto.ButtonActionPostRedirect) -func WriteFrameButton2Action(writer io.Writer, action string) { +func WriteFrameButton2Action(writer io.Writer, action string) error { const property string = MetaPropertyFrameButton2Action - writeMetaPropertyContent(writer, property, action) + return writeMetaPropertyContent(writer, property, action) } diff --git a/writeframebutton2target.go b/writeframebutton2target.go index 57b1e1a..21b9e5b 100644 --- a/writeframebutton2target.go +++ b/writeframebutton2target.go @@ -15,7 +15,7 @@ import ( // Would write this HTML element: // // -func WriteFrameButton2Target(writer io.Writer, target string) { +func WriteFrameButton2Target(writer io.Writer, target string) error { const property string = MetaPropertyFrameButton2Target - writeMetaPropertyContent(writer, property, target) + return writeMetaPropertyContent(writer, property, target) } diff --git a/writeframebutton3.go b/writeframebutton3.go index 793bd41..1a397a2 100644 --- a/writeframebutton3.go +++ b/writeframebutton3.go @@ -15,7 +15,7 @@ import ( // Would write this HTML element: // // -func WriteFrameButton3(writer io.Writer, label string) { +func WriteFrameButton3(writer io.Writer, label string) error { const property string = MetaPropertyFrameButton3 - writeMetaPropertyContent(writer, property, label) + return writeMetaPropertyContent(writer, property, label) } diff --git a/writeframebutton3action.go b/writeframebutton3action.go index eb3b389..70c2933 100644 --- a/writeframebutton3action.go +++ b/writeframebutton3action.go @@ -38,7 +38,7 @@ import ( // // // // frameproto.WriteFrameButton3Action(writer, frameproto.ButtonActionPostRedirect) -func WriteFrameButton3Action(writer io.Writer, action string) { +func WriteFrameButton3Action(writer io.Writer, action string) error { const property string = MetaPropertyFrameButton3Action - writeMetaPropertyContent(writer, property, action) + return writeMetaPropertyContent(writer, property, action) } diff --git a/writeframebutton3target.go b/writeframebutton3target.go index f4f2e70..f3e3740 100644 --- a/writeframebutton3target.go +++ b/writeframebutton3target.go @@ -15,7 +15,7 @@ import ( // Would write this HTML element: // // -func WriteFrameButton3Target(writer io.Writer, target string) { +func WriteFrameButton3Target(writer io.Writer, target string) error { const property string = MetaPropertyFrameButton3Target - writeMetaPropertyContent(writer, property, target) + return writeMetaPropertyContent(writer, property, target) } diff --git a/writeframebutton4.go b/writeframebutton4.go index 46bd2ec..1cb3094 100644 --- a/writeframebutton4.go +++ b/writeframebutton4.go @@ -15,7 +15,7 @@ import ( // Would write this HTML element: // // -func WriteFrameButton4(writer io.Writer, label string) { +func WriteFrameButton4(writer io.Writer, label string) error { const property string = MetaPropertyFrameButton4 - writeMetaPropertyContent(writer, property, label) + return writeMetaPropertyContent(writer, property, label) } diff --git a/writeframebutton4action.go b/writeframebutton4action.go index 8e9c085..5da997f 100644 --- a/writeframebutton4action.go +++ b/writeframebutton4action.go @@ -38,7 +38,7 @@ import ( // // // // frameproto.WriteFrameButton4Action(writer, frameproto.ButtonActionPostRedirect) -func WriteFrameButton4Action(writer io.Writer, action string) { +func WriteFrameButton4Action(writer io.Writer, action string) error { const property string = MetaPropertyFrameButton4Action - writeMetaPropertyContent(writer, property, action) + return writeMetaPropertyContent(writer, property, action) } diff --git a/writeframebutton4target.go b/writeframebutton4target.go index bd4a57c..b85a6a0 100644 --- a/writeframebutton4target.go +++ b/writeframebutton4target.go @@ -15,7 +15,7 @@ import ( // Would write this HTML element: // // -func WriteFrameButton4Target(writer io.Writer, target string) { +func WriteFrameButton4Target(writer io.Writer, target string) error { const property string = MetaPropertyFrameButton4Target - writeMetaPropertyContent(writer, property, target) + return writeMetaPropertyContent(writer, property, target) } diff --git a/writeframeimage.go b/writeframeimage.go index b345ce3..f8241b2 100644 --- a/writeframeimage.go +++ b/writeframeimage.go @@ -15,8 +15,8 @@ import ( // Would write this HTML element: // // -func WriteFrameImage(writer io.Writer, url string) { +func WriteFrameImage(writer io.Writer, url string) error { const property string = MetaPropertyFrameImage - writeMetaPropertyContent(writer, property, url) + return writeMetaPropertyContent(writer, property, url) } diff --git a/writeframeimageaspectratio.go b/writeframeimageaspectratio.go index 6f8a4c5..46a75a0 100644 --- a/writeframeimageaspectratio.go +++ b/writeframeimageaspectratio.go @@ -26,7 +26,7 @@ import ( // And: // // frameproto.WriteFrameImageAspectRatio(writer, frameproto.AspectRatioOneToOne) -func WriteFrameImageAspectRatio(writer io.Writer, label string) { +func WriteFrameImageAspectRatio(writer io.Writer, label string) error { const property string = MetaPropertyFrameImageAspectRatio - writeMetaPropertyContent(writer, property, label) + return writeMetaPropertyContent(writer, property, label) } diff --git a/writeframeinputtext.go b/writeframeinputtext.go index 20c9e5e..048e436 100644 --- a/writeframeinputtext.go +++ b/writeframeinputtext.go @@ -15,7 +15,7 @@ import ( // Would write this HTML element: // // -func WriteFrameInputText(writer io.Writer, label string) { +func WriteFrameInputText(writer io.Writer, label string) error { const property string = MetaPropertyFrameInputText - writeMetaPropertyContent(writer, property, label) + return writeMetaPropertyContent(writer, property, label) } diff --git a/writeframeposturl.go b/writeframeposturl.go index befc674..55a26fe 100644 --- a/writeframeposturl.go +++ b/writeframeposturl.go @@ -15,7 +15,7 @@ import ( // Would write this HTML element: // // -func WriteFramePostURL(writer io.Writer, url string) { +func WriteFramePostURL(writer io.Writer, url string) error { const property string = MetaPropertyFramePostURL - writeMetaPropertyContent(writer, property, url) + return writeMetaPropertyContent(writer, property, url) } diff --git a/writemetapropertycontent.go b/writemetapropertycontent.go index 00f450f..67d93aa 100644 --- a/writemetapropertycontent.go +++ b/writemetapropertycontent.go @@ -4,10 +4,10 @@ import ( "io" ) -func writeMetaPropertyContent(writer io.Writer, property string, content string) { +func writeMetaPropertyContent(writer io.Writer, property string, content string) error { if nil == writer { - return + return errNilWriter } var buffer [bufferSize]byte @@ -15,5 +15,6 @@ func writeMetaPropertyContent(writer io.Writer, property string, content string) p = appendMetaPropertyContent(p, property, content) - writer.Write(p) + _, err := writer.Write(p) + return err } diff --git a/writemetapropertycontent_test.go b/writemetapropertycontent_test.go index 60c2091..37a73b0 100644 --- a/writemetapropertycontent_test.go +++ b/writemetapropertycontent_test.go @@ -61,7 +61,14 @@ func TestWriteMetaPropertyContent(t *testing.T) { var buffer strings.Builder - writeMetaPropertyContent(&buffer, test.Property, test.Content) + err := writeMetaPropertyContent(&buffer, test.Property, test.Content) + if nil != err { + t.Errorf("For test #%d, did not expect an error but actually got one." , testNumber) + t.Logf("ERROR: (%T) %s", err, err) + t.Logf("PROPERTY: %s", test.Property) + t.Logf("CONTENT: %s", test.Content) + continue + } expected := test.Expected actual := buffer.String()