initial commits

master
Charles Iliya Krempeaux 2024-02-15 09:43:14 -08:00
parent 6cbe8f2b35
commit fa4898e9e6
22 changed files with 225 additions and 38 deletions

9
errors.go 100644
View File

@ -0,0 +1,9 @@
package frameproto
import (
"sourcecode.social/reiver/go-erorr"
)
const (
errNilWriter = erorr.Error("frameproto: nil writer")
)

69
framewriter.go 100644
View File

@ -0,0 +1,69 @@
package frameproto
//
type FrameWriter interface {
// <meta property="fc:frame" content="{{version}}" />
WriteFrame(version string) error
// <meta property="fc:frame:button:1" content="{{label}}" />
WriteFrameButton1(label string) error
// <meta property="fc:frame:button:1:action" content="{{action}}" />
WriteFrameButton1Action(action string) error
// <meta property="fc:frame:button:1:target" content="{{target}}" />
WriteFrameButton1Target(buttonTarget string) error
// <meta property="fc:frame:button:2" content="{{label}}" />
WriteFrameButton2(label string) error
// <meta property="fc:frame:button:2:action" content="{{action}}" />
WriteFrameButton2Action(action string) error
// <meta property="fc:frame:button:2:target" content="{{target}}" />
WriteFrameButton2Target(target string) error
// <meta property="fc:frame:button:3" content="{{label}}" />
WriteFrameButton3(label string) error
// <meta property="fc:frame:button:3:action" content="{{action}}" />
WriteFrameButton3Action(buttonAction string) error
// <meta property="fc:frame:button:3:target" content="{{target}}" />
WriteFrameButton3Target(buttonTarget string) error
// <meta property="fc:frame:button:4" content="{{label}}" />
WriteFrameButton4(label string) error
// <meta property="fc:frame:button:4:action" content="{{action}}" />
WriteFrameButton4Action(action string) error
// <meta property="fc:frame:button:4:target" content="{{target}}" />
WriteFrameButton4Target(target string) error
// <meta property="fc:frame:image" content="{{url}}" />
WriteFrameImage(url string) error
// <meta property="fc:frame:image:aspect_ratio" content="{{aspectRatio}}" />
WriteFrameImageAspectRatio(aspectRatio string) error
// <meta property="fc:frame:input:text" content="{{label}}" />
WriteFrameInputText(label string) error
// <meta property="fc:frame:post_url" content="{{url}}" />
WriteFramePostURL(url string) error
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -15,7 +15,7 @@ import (
// Would write this HTML <meta/> element:
//
// <meta property="fc:frame:button:1" content="go forward" />
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)
}

View File

@ -38,7 +38,7 @@ import (
//
// // <meta property="fc:frame:button:1:action" content="post_redirect" />
// 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)
}

View File

@ -15,7 +15,7 @@ import (
// Would write this HTML <meta/> element:
//
// <meta property="fc:frame:button:1:target" content="https://example.com/thing/do-it" />
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)
}

View File

@ -15,7 +15,7 @@ import (
// Would write this HTML <meta/> element:
//
// <meta property="fc:frame:button:2" content="go forward" />
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)
}

View File

@ -38,7 +38,7 @@ import (
//
// // <meta property="fc:frame:button:2:action" content="post_redirect" />
// 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)
}

View File

@ -15,7 +15,7 @@ import (
// Would write this HTML <meta/> element:
//
// <meta property="fc:frame:button:2:target" content="https://example.com/thing/do-it" />
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)
}

View File

@ -15,7 +15,7 @@ import (
// Would write this HTML <meta/> element:
//
// <meta property="fc:frame:button:3" content="go forward" />
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)
}

View File

@ -38,7 +38,7 @@ import (
//
// // <meta property="fc:frame:button:3:action" content="post_redirect" />
// 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)
}

View File

@ -15,7 +15,7 @@ import (
// Would write this HTML <meta/> element:
//
// <meta property="fc:frame:button:3:target" content="https://example.com/thing/do-it" />
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)
}

View File

@ -15,7 +15,7 @@ import (
// Would write this HTML <meta/> element:
//
// <meta property="fc:frame:button:4" content="go forward" />
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)
}

View File

@ -38,7 +38,7 @@ import (
//
// // <meta property="fc:frame:button:4:action" content="post_redirect" />
// 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)
}

View File

@ -15,7 +15,7 @@ import (
// Would write this HTML <meta/> element:
//
// <meta property="fc:frame:button:4:target" content="https://example.com/thing/do-it" />
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)
}

View File

@ -15,8 +15,8 @@ import (
// Would write this HTML <meta/> element:
//
// <meta property="fc:frame:image" content="https://example.com/images/screen.png" />
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)
}

View File

@ -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)
}

View File

@ -15,7 +15,7 @@ import (
// Would write this HTML <meta/> element:
//
// <meta property="fc:frame:input:text" content="enter your username" />
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)
}

View File

@ -15,7 +15,7 @@ import (
// Would write this HTML <meta/> element:
//
// <meta property="fc:frame:post_url" content="https://example.com/my/post/path.php" />
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)
}

View File

@ -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
}

View File

@ -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()