frameproto

package module
v0.0.0-...-a4951bf Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: MIT Imports: 4 Imported by: 0

README

go-frameproto

Package frameproto provides tools for the Frame Protocol — which is also known as Farcaster Frames, for the Go programming language.

The specification for the Frame Protocol is at: https://docs.farcaster.xyz/reference/frames/spec

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/sourcecode.social/reiver/go-frameproto

GoDoc

Explanation

The Frames Protocol, also known Farcaster Frames, is a simple web-based technology used for making applications.

It uses HTML without really using HTML, so that Frames Protocol applications work with clients that don't support the Frames Protocol. The fall-back being OpenGraph.

Really, a Frames Protocol application is mostly made up of images and buttons on the client-side (that are specified using HTML <meta> element) with a back-end that gets HTTP POSTed to, which can return a new "page" with an image and buttons, and so on and so on.

This choice of just being mostly images and buttons actually makes the Frames Protocol simpler to create a viewer from scatch. No need to implement all Web technologies. No need to worry about security and privacy holes that Web technologies introduce.

Although the Frames Protocol could be used outside of Farcaster, at the time of writing, Farcaster clients (such as Warpcast) are the only major (client-side) platform to support it.

(The server-side of the Frames Protocol, which is called a Frame Server, is an just HTTP resource — which some might loosely call an HTTP (or HTTPS) URL.)

Enough talking — let's look at some code. Here is the client-side of a Frames Protocol application:

<meta property="fc:frame" content="vNext" />
<meta property="fc:frame:image" content="https://example.com/path/to/image.png" />
<meta property="og:image" content="https://example.com/path/to/image.png" />

It is just HTML.

Although this would need to be embedded into an HTML document, so really it would be something more like this:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="utf-8" />

<meta property="fc:frame" content="vNext" />
<meta property="fc:frame:image" content="https://example.com/path/to/image.png" />
<meta property="og:image" content="https://example.com/path/to/image.png" />

</head>
<body>
</body>
</html>

This package provides you tools for creating this.

For example:

func ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) {

	// ...

	frameproto.WriteFrame(responseWriter, frameproto.VersionVNext)
	frameproto.WriteFrameImage(responseWriter, frameImageURL)

	// ...
}


Import

To import package frameproto use import code like the follownig:

import "sourcecode.social/reiver/go-frameproto"

Installation

To install package frameproto do the following:

GOPROXY=direct go get https://sourcecode.social/reiver/go-frameproto

Author

Package frameproto was written by Charles Iliya Krempeaux

Documentation

Index

Constants

View Source
const (
	ButtonActionLink         = "link"
	ButtonActionMint         = "mint"
	ButtonActionPost         = "post"
	ButtonActionPostRedirect = "post_redirect"
)

These constants are 'values' in name-value pairs used with HTML <meta /> elements by the frame-protocol, when the name is of the form "fc:frame:button:*:action". I.e., when the name is: "fc:frame:button:1:action", "fc:frame:button:2:action", "fc:frame:button:3:action", or "fc:frame:button:4:action".

For example:

<meta property="fc:frame:button:1:action" content="post" />
<meta property="fc:frame:button:2:action" content="post_redirect" />
<meta property="fc:frame:button:3:action" content="mint" />
<meta property="fc:frame:button:4:action" content="link" />

The way these would be used are:

frameproto.WriteFrameButton1Action(writer, frameproto.ButtonActionLink)

And:

p = frameproto.AppendFrameButton2Action(p, frameproto.ButtonActionMint)

And:

s = frameproto.FrameButton3Action(p, frameproto.ButtonActionPost)

Etc.

View Source
const (
	MetaPropertyFrame                 = "fc:frame"
	MetaPropertyFrameButton1          = "fc:frame:button:1"
	MetaPropertyFrameButton1Action    = "fc:frame:button:1:action"
	MetaPropertyFrameButton1Target    = "fc:frame:button:1:target"
	MetaPropertyFrameButton2          = "fc:frame:button:2"
	MetaPropertyFrameButton2Action    = "fc:frame:button:2:action"
	MetaPropertyFrameButton2Target    = "fc:frame:button:2:target"
	MetaPropertyFrameButton3          = "fc:frame:button:3"
	MetaPropertyFrameButton3Action    = "fc:frame:button:3:action"
	MetaPropertyFrameButton3Target    = "fc:frame:button:3:target"
	MetaPropertyFrameButton4          = "fc:frame:button:4"
	MetaPropertyFrameButton4Action    = "fc:frame:button:4:action"
	MetaPropertyFrameButton4Target    = "fc:frame:button:4:target"
	MetaPropertyFrameImage            = "fc:frame:image"
	MetaPropertyFrameImageAspectRatio = "fc:frame:image:aspect_ratio"
	MetaPropertyFrameInputText        = "fc:frame:input:text"
	MetaPropertyFramePostURL          = "fc:frame:post_url"
)

These constants are 'names' in name-value pairs used with HTML <meta /> elements by the frame-protocol.

For example:

<meta property="fc:frame"       content="vNext" />
<meta property="fc:frame:image" content="https://example.com/path/to/image.png" />
<meta property="og:image"       content="https://example.com/path/to/image.png" />
View Source
const AspectRatioOnePointNineOneToOne = "1.91:1"
View Source
const AspectRatioOneToOne = "1:1"
View Source
const (
	VersionVNext = "vNext"
)

Variables

This section is empty.

Functions

func AppendFrame

func AppendFrame(p []byte, version string) []byte

AppendFrame will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame" name-value pair.

For example, this call:

var p []byte

// ...

var version string = "vNext"

p = frameproto.AppendFrame(p, version)

Would append this HTML <meta/> element:

<meta property="fc:frame" content="vNext" />

Note that this package provides some constants to use with AppendFrame. Namely: VersionVNext (for "vNext").

Which in code would be used as:

p = frameproto.AppendFrame(p, frameproto.VersionVNext)

func AppendFrameButton1

func AppendFrameButton1(p []byte, label string) []byte

AppendFrameButton1 will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:1" name-value pair.

For example, this call:

var p []byte

// ...

var label string = "go forward"

p = frameproto.AppendFrameButton1(p, label)

Would append this HTML <meta/> element:

<meta property="fc:frame:button:1" content="go forward" />

func AppendFrameButton1Action

func AppendFrameButton1Action(p []byte, action string) []byte

AppendFrameButton1Action will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:1:action" name-value pair.

For example, this call:

var p []byte

// ..

var buttonAction string = "post"

p = frameproto.AppendFrameButton1Action(p, buttonAction)

Would append this HTML <meta/> element:

<meta property="fc:frame:button:1:action" content="post" />

Note that this package provides some constants to use with AppendFrameButton1Action. Namely: ButtonActionLink (for "link"), ButtonActionMint (for "mint"), ButtonActionPost (for "post"), and ButtonActionPostRedirect (for "post_redirect").

Which in code would be used as:

// <meta property="fc:frame:button:1:action" content="link" />
p = frameproto.AppendFrameButton1Action(p, frameproto.ButtonActionLink)

And:

// <meta property="fc:frame:button:1:action" content="mint" />
p = frameproto.AppendFrameButton1Action(p, frameproto.ButtonActionMint)

And:

// <meta property="fc:frame:button:1:action" content="post" />
str :+ frameproto.AppendFrameButton1Action(p, frameproto.ButtonActionPost)

And:

// <meta property="fc:frame:button:1:action" content="post_redirect" />
p = frameproto.AppendFrameButton1Action(p, frameproto.ButtonActionPostRedirect)

func AppendFrameButton1Target

func AppendFrameButton1Target(p []byte, target string) []byte

AppendFrameButton1Target will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:1:target" name-value pair.

For example, this call:

var p []byte

// ...

var target string = "https://example.com/thing/do-it"

p = frameproto.AppendFrameButton1Target(p, target)

Would append this HTML <meta/> element:

<meta property="fc:frame:button:1:target" content="https://example.com/thing/do-it" />

func AppendFrameButton2

func AppendFrameButton2(p []byte, label string) []byte

AppendFrameButton2 will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:2" name-value pair.

For example, this call:

var p []byte

// ...

var label string = "go forward"

p = frameproto.AppendFrameButton2(p, label)

Would append this HTML <meta/> element:

<meta property="fc:frame:button:2" content="go forward" />

func AppendFrameButton2Action

func AppendFrameButton2Action(p []byte, action string) []byte

AppendFrameButton2Action will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:2:action" name-value pair.

For example, this call:

var p []byte

// ..

var buttonAction string = "post"

p = frameproto.AppendFrameButton2Action(p, buttonAction)

Would append this HTML <meta/> element:

<meta property="fc:frame:button:2:action" content="post" />

Note that this package provides some constants to use with AppendFrameButton2Action. Namely: ButtonActionLink (for "link"), ButtonActionMint (for "mint"), ButtonActionPost (for "post"), and ButtonActionPostRedirect (for "post_redirect").

Which in code would be used as:

// <meta property="fc:frame:button:2:action" content="link" />
p = frameproto.AppendFrameButton2Action(p, frameproto.ButtonActionLink)

And:

// <meta property="fc:frame:button:2:action" content="mint" />
p = frameproto.AppendFrameButton2Action(p, frameproto.ButtonActionMint)

And:

// <meta property="fc:frame:button:2:action" content="post" />
str :+ frameproto.AppendFrameButton2Action(p, frameproto.ButtonActionPost)

And:

// <meta property="fc:frame:button:2:action" content="post_redirect" />
p = frameproto.AppendFrameButton2Action(p, frameproto.ButtonActionPostRedirect)

func AppendFrameButton2Target

func AppendFrameButton2Target(p []byte, target string) []byte

AppendFrameButton2Target will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:2:target" name-value pair.

For example, this call:

var p []byte

// ...

var target string = "https://example.com/thing/do-it"

p = frameproto.AppendFrameButton2Target(p, target)

Would append this HTML <meta/> element:

<meta property="fc:frame:button:2:target" content="https://example.com/thing/do-it" />

func AppendFrameButton3

func AppendFrameButton3(p []byte, label string) []byte

AppendFrameButton3 will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:3" name-value pair.

For example, this call:

var p []byte

// ...

var label string = "go forward"

p = frameproto.AppendFrameButton3(p, label)

Would append this HTML <meta/> element:

<meta property="fc:frame:button:3" content="go forward" />

func AppendFrameButton3Action

func AppendFrameButton3Action(p []byte, action string) []byte

AppendFrameButton3Action will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:3:action" name-value pair.

For example, this call:

var p []byte

// ..

var buttonAction string = "post"

p = frameproto.AppendFrameButton3Action(p, buttonAction)

Would append this HTML <meta/> element:

<meta property="fc:frame:button:3:action" content="post" />

Note that this package provides some constants to use with AppendFrameButton3Action. Namely: ButtonActionLink (for "link"), ButtonActionMint (for "mint"), ButtonActionPost (for "post"), and ButtonActionPostRedirect (for "post_redirect").

Which in code would be used as:

// <meta property="fc:frame:button:3:action" content="link" />
p = frameproto.AppendFrameButton3Action(p, frameproto.ButtonActionLink)

And:

// <meta property="fc:frame:button:3:action" content="mint" />
p = frameproto.AppendFrameButton3Action(p, frameproto.ButtonActionMint)

And:

// <meta property="fc:frame:button:3:action" content="post" />
str :+ frameproto.AppendFrameButton3Action(p, frameproto.ButtonActionPost)

And:

// <meta property="fc:frame:button:3:action" content="post_redirect" />
p = frameproto.AppendFrameButton3Action(p, frameproto.ButtonActionPostRedirect)

func AppendFrameButton3Target

func AppendFrameButton3Target(p []byte, target string) []byte

AppendFrameButton3Target will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:3:target" name-value pair.

For example, this call:

var p []byte

// ...

var target string = "https://example.com/thing/do-it"

p = frameproto.AppendFrameButton3Target(p, target)

Would append this HTML <meta/> element:

<meta property="fc:frame:button:3:target" content="https://example.com/thing/do-it" />

func AppendFrameButton4

func AppendFrameButton4(p []byte, label string) []byte

AppendFrameButton4 will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:4" name-value pair.

For example, this call:

var p []byte

// ...

var label string = "go forward"

p = frameproto.AppendFrameButton4(p, label)

Would append this HTML <meta/> element:

<meta property="fc:frame:button:4" content="go forward" />

func AppendFrameButton4Action

func AppendFrameButton4Action(p []byte, action string) []byte

AppendFrameButton4Action will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:4:action" name-value pair.

For example, this call:

var p []byte

// ..

var buttonAction string = "post"

p = frameproto.AppendFrameButton4Action(p, buttonAction)

Would append this HTML <meta/> element:

<meta property="fc:frame:button:4:action" content="post" />

Note that this package provides some constants to use with AppendFrameButton4Action. Namely: ButtonActionLink (for "link"), ButtonActionMint (for "mint"), ButtonActionPost (for "post"), and ButtonActionPostRedirect (for "post_redirect").

Which in code would be used as:

// <meta property="fc:frame:button:4:action" content="link" />
p = frameproto.AppendFrameButton4Action(p, frameproto.ButtonActionLink)

And:

// <meta property="fc:frame:button:4:action" content="mint" />
p = frameproto.AppendFrameButton4Action(p, frameproto.ButtonActionMint)

And:

// <meta property="fc:frame:button:4:action" content="post" />
str :+ frameproto.AppendFrameButton4Action(p, frameproto.ButtonActionPost)

And:

// <meta property="fc:frame:button:4:action" content="post_redirect" />
p = frameproto.AppendFrameButton4Action(p, frameproto.ButtonActionPostRedirect)

func AppendFrameButton4Target

func AppendFrameButton4Target(p []byte, target string) []byte

AppendFrameButton4Target will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:4:target" name-value pair.

For example, this call:

var p []byte

// ...

var target string = "https://example.com/thing/do-it"

p = frameproto.AppendFrameButton4Target(p, target)

Would append this HTML <meta/> element:

<meta property="fc:frame:button:4:target" content="https://example.com/thing/do-it" />

func AppendFrameImage

func AppendFrameImage(p []byte, url string) []byte

AppendFrameImage will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:image" name-value pair.

For example, this call:

var p []byte

// ...

var url string = "https://example.com/images/screen.png"

p = frameproto.AppendFrameImage(p, url)

Would append this HTML <meta/> element:

<meta property="fc:frame:image" content="https://example.com/images/screen.png" />

func AppendFrameImageAspectRatio

func AppendFrameImageAspectRatio(p []byte, label string) []byte

AppendFrameImageAspectRatio will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:image:aspect_ratio" name-value pair.

For example, this call:

var p []byte

// ..

var aspectRatio string = "1.91:1"

p = frameproto.AppendFrameImageAspectRatio(p, aspectRatio)

Would append this HTML <meta/> element:

<meta property="fc:frame:image:aspect_ratio" content="1.91:1" />

Note that this package provides some constants to use with AppendFrameImageAspectRatio. Namely: AspectRatioOnePointNineOneToOne (for "1.91:1") and AspectRatioOneToOne (for "1:1").

Which in code would be used at:

p = frameproto.AppendFrameImageAspectRatio(p, frameproto.AspectRatioOnePointNineOneToOne)

And:

p = frameproto.AppendFrameImageAspectRatio(p, frameproto.AspectRatioOneToOne)

func AppendFrameInputText

func AppendFrameInputText(p []byte, label string) []byte

AppendFrameInputText will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:input:text" name-value pair.

For example, this call:

var p []byte

// ...

var label string = "enter your username

p = frameproto.AppendFrameInputText(p, label)

Would append this HTML <meta/> element:

<meta property="fc:frame:input:text" content="enter your username" />

func AppendFramePostURL

func AppendFramePostURL(p []byte, url string) []byte

AppendFramePostURL will append the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:post_url" name-value pair.

For example, this call:

var p []byte

// ...

var url string = "https://example.com/my/post/path.php"

p = frameproto.AppendFramePostURL(p, url)

Would append this HTML <meta/> element:

<meta property="fc:frame:post_url" content="https://example.com/my/post/path.php" />

func StringFrame

func StringFrame(version string) string

StringFrame will return the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame" name-value pair.

For example, this call:

var version string = "vNext"

s = frameproto.StringFrame(version)

Would return this HTML <meta/> element:

<meta property="fc:frame" content="vNext" />

Note that this package provides some constants to use with StringFrame. Namely: VersionVNext (for "vNext").

Which in code would be used as:

p = frameproto.StringFrame(p, frameproto.VersionVNext)

func StringFrameButton1

func StringFrameButton1(label string) string

StringFrameButton1 will return the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:1" name-value pair.

For example, this call:

var label string = "go forward"

str := frameproto.StringFrameButton1(label)

Would return this HTML <meta/> element:

<meta property="fc:frame:button:1" content="go forward" />

func StringFrameButton1Action

func StringFrameButton1Action(action string) string

StringFrameButton1Action will return the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:1:action" name-value pair.

For example, this call:

var buttonAction string = "post"

str := frameproto.StringFrameButton1Action(buttonAction)

Would return this HTML <meta/> element:

<meta property="fc:frame:button:1:action" content="post" />

Note that this package provides some constants to use with StringFrameButton1Action. Namely: ButtonActionLink (for "link"), ButtonActionMint (for "mint"), ButtonActionPost (for "post"), and ButtonActionPostRedirect (for "post_redirect").

Which in code would be used as:

// <meta property="fc:frame:button:1:action" content="link" />
str := frameproto.StringFrameButton1Action(frameproto.ButtonActionLink)

And:

// <meta property="fc:frame:button:1:action" content="mint" />
str := frameproto.StringFrameButton1Action(frameproto.ButtonActionMint)

And:

// <meta property="fc:frame:button:1:action" content="post" />
str :+ frameproto.StringFrameButton1Action(frameproto.ButtonActionPost)

And:

// <meta property="fc:frame:button:1:action" content="post_redirect" />
str := frameproto.StringFrameButton1Action(frameproto.ButtonActionPostRedirect)

func StringFrameButton1Target

func StringFrameButton1Target(target string) string

StringFrameButton1Target will return the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:1:target" name-value pair.

For example, this call:

var target string = "https://example.com/thing/do-it"

str := frameproto.StringFrameButton1Target(target)

Would return this HTML <meta/> element:

<meta property="fc:frame:button:1:target" content="https://example.com/thing/do-it" />

func StringFrameButton2

func StringFrameButton2(label string) string

StringFrameButton2 will return the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:2" name-value pair.

For example, this call:

var label string = "go forward"

str := frameproto.StringFrameButton2(label)

Would return this HTML <meta/> element:

<meta property="fc:frame:button:2" content="go forward" />

func StringFrameButton2Action

func StringFrameButton2Action(action string) string

StringFrameButton2Action will return the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:2:action" name-value pair.

For example, this call:

var buttonAction string = "post"

str := frameproto.StringFrameButton2Action(buttonAction)

Would return this HTML <meta/> element:

<meta property="fc:frame:button:2:action" content="post" />

Note that this package provides some constants to use with StringFrameButton2Action. Namely: ButtonActionLink (for "link"), ButtonActionMint (for "mint"), ButtonActionPost (for "post"), and ButtonActionPostRedirect (for "post_redirect").

Which in code would be used as:

// <meta property="fc:frame:button:2:action" content="link" />
str := frameproto.StringFrameButton2Action(frameproto.ButtonActionLink)

And:

// <meta property="fc:frame:button:2:action" content="mint" />
str := frameproto.StringFrameButton2Action(frameproto.ButtonActionMint)

And:

// <meta property="fc:frame:button:2:action" content="post" />
str :+ frameproto.StringFrameButton2Action(frameproto.ButtonActionPost)

And:

// <meta property="fc:frame:button:2:action" content="post_redirect" />
str := frameproto.StringFrameButton2Action(frameproto.ButtonActionPostRedirect)

func StringFrameButton2Target

func StringFrameButton2Target(target string) string

StringFrameButton2Target will return the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:2:target" name-value pair.

For example, this call:

var target string = "https://example.com/thing/do-it"

str := frameproto.StringFrameButton2Target(target)

Would return this HTML <meta/> element:

<meta property="fc:frame:button:2:target" content="https://example.com/thing/do-it" />

func StringFrameButton3

func StringFrameButton3(label string) string

StringFrameButton3 will return the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:3" name-value pair.

For example, this call:

var label string = "go forward"

str := frameproto.StringFrameButton3(label)

Would return this HTML <meta/> element:

<meta property="fc:frame:button:3" content="go forward" />

func StringFrameButton3Action

func StringFrameButton3Action(action string) string

StringFrameButton3Action will return the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:3:action" name-value pair.

For example, this call:

var buttonAction string = "post"

str := frameproto.StringFrameButton3Action(buttonAction)

Would return this HTML <meta/> element:

<meta property="fc:frame:button:3:action" content="post" />

Note that this package provides some constants to use with StringFrameButton3Action. Namely: ButtonActionLink (for "link"), ButtonActionMint (for "mint"), ButtonActionPost (for "post"), and ButtonActionPostRedirect (for "post_redirect").

Which in code would be used as:

// <meta property="fc:frame:button:3:action" content="link" />
str := frameproto.StringFrameButton3Action(frameproto.ButtonActionLink)

And:

// <meta property="fc:frame:button:3:action" content="mint" />
str := frameproto.StringFrameButton3Action(frameproto.ButtonActionMint)

And:

// <meta property="fc:frame:button:3:action" content="post" />
str :+ frameproto.StringFrameButton3Action(frameproto.ButtonActionPost)

And:

// <meta property="fc:frame:button:3:action" content="post_redirect" />
str := frameproto.StringFrameButton3Action(frameproto.ButtonActionPostRedirect)

func StringFrameButton3Target

func StringFrameButton3Target(target string) string

StringFrameButton3Target will return the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:3:target" name-value pair.

For example, this call:

var target string = "https://example.com/thing/do-it"

str := frameproto.StringFrameButton3Target(target)

Would return this HTML <meta/> element:

<meta property="fc:frame:button:3:target" content="https://example.com/thing/do-it" />

func StringFrameButton4

func StringFrameButton4(label string) string

StringFrameButton4 will return the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:4" name-value pair.

For example, this call:

var label string = "go forward"

str := frameproto.StringFrameButton4(label)

Would return this HTML <meta/> element:

<meta property="fc:frame:button:4" content="go forward" />

func StringFrameButton4Action

func StringFrameButton4Action(action string) string

StringFrameButton4Action will return the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:4:action" name-value pair.

For example, this call:

var buttonAction string = "post"

str := frameproto.StringFrameButton4Action(buttonAction)

Would return this HTML <meta/> element:

<meta property="fc:frame:button:4:action" content="post" />

Note that this package provides some constants to use with StringFrameButton4Action. Namely: ButtonActionLink (for "link"), ButtonActionMint (for "mint"), ButtonActionPost (for "post"), and ButtonActionPostRedirect (for "post_redirect").

Which in code would be used as:

// <meta property="fc:frame:button:4:action" content="link" />
str := frameproto.StringFrameButton4Action(frameproto.ButtonActionLink)

And:

// <meta property="fc:frame:button:4:action" content="mint" />
str := frameproto.StringFrameButton4Action(frameproto.ButtonActionMint)

And:

// <meta property="fc:frame:button:4:action" content="post" />
str :+ frameproto.StringFrameButton4Action(frameproto.ButtonActionPost)

And:

// <meta property="fc:frame:button:4:action" content="post_redirect" />
str := frameproto.StringFrameButton4Action(frameproto.ButtonActionPostRedirect)

func StringFrameButton4Target

func StringFrameButton4Target(target string) string

StringFrameButton4Target will return the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:4:target" name-value pair.

For example, this call:

var target string = "https://example.com/thing/do-it"

str := frameproto.StringFrameButton4Target(target)

Would return this HTML <meta/> element:

<meta property="fc:frame:button:4:target" content="https://example.com/thing/do-it" />

func StringFrameImage

func StringFrameImage(url string) string

StringFrameImage will return the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:image" name-value pair.

For example, this call:

var url string = "https://example.com/images/screen.png"

str := frameproto.StringFrameImage(url)

Would return this HTML <meta/> element:

<meta property="fc:frame:image" content="https://example.com/images/screen.png" />

func StringFrameImageAspectRatio

func StringFrameImageAspectRatio(label string) string

StringFrameImageAspectRatio will return the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:image:aspect_ratio" name-value pair.

For example, this call:

var aspectRatio string = "1.91:1"

str := frameproto.StringFrameImageAspectRatio(aspectRatio)

Would return this HTML <meta/> element:

<meta property="fc:frame:image:aspect_ratio" content="1.91:1" />

Note that this package provides some constants to use with StringFrameImageAspectRatio. Namely: AspectRatioOnePointNineOneToOne (for "1.91:1") and AspectRatioOneToOne (for "1:1").

Which in code would be used at:

str := frameproto.StringFrameImageAspectRatio(frameproto.AspectRatioOnePointNineOneToOne)

And:

str := frameproto.StringFrameImageAspectRatio(frameproto.AspectRatioOneToOne)

func StringFrameInputText

func StringFrameInputText(label string) string

StringFrameInputText will return the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:input:text" name-value pair.

For example, this call:

var label string = "enter your username"

str := frameproto.StringFrameInputText(label)

Would return this HTML <meta/> element:

<meta property="fc:frame:input:text" content="enter your username" />

func StringFramePostURL

func StringFramePostURL(url string) string

StringFramePostURL will return the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:post_url" name-value pair.

For example, this call:

var url string = "https://example.com/my/post/path.php"

str := frameproto.StringFramePostURL(url)

Would return this HTML <meta/> element:

<meta property="fc:frame:post_url" content="https://example.com/my/post/path.php" />

func WriteFrame

func WriteFrame(writer io.Writer, version string) error

WriteFrame will write the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame" name-value pair.

For example, this call:

var version string = "vNext"

str := frameproto.WriteFrame(writer, version)

Would write this HTML <meta/> element:

<meta property="fc:frame" content="vNext" />

Note that this package provides some constants to use with WriteFrame. Namely: VersionVNext (for "vNext").

Which in code would be used as:

str := frameproto.WriteFrame(writer, frameproto.VersionVNext)

func WriteFrameButton1

func WriteFrameButton1(writer io.Writer, label string) error

WriteFrameButton1 will write the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:1" name-value pair.

For example, this call:

var label string = "go forward"

frameproto.WriteFrameButton1(writer, label)

Would write this HTML <meta/> element:

<meta property="fc:frame:button:1" content="go forward" />

func WriteFrameButton1Action

func WriteFrameButton1Action(writer io.Writer, action string) error

WriteFrameButton1Action will write the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:1:action" name-value pair.

For example, this call:

var buttonAction string = "post"

frameproto.WriteFrameButton1Action(writer, buttonAction)

Would write this HTML <meta/> element:

<meta property="fc:frame:button:1:action" content="post" />

Note that this package provides some constants to use with WriteFrameButton1Action. Namely: ButtonActionLink (for "link"), ButtonActionMint (for "mint"), ButtonActionPost (for "post"), and ButtonActionPostRedirect (for "post_redirect").

Which in code would be used as:

// <meta property="fc:frame:button:1:action" content="link" />
frameproto.WriteFrameButton1Action(writer, frameproto.ButtonActionLink)

And:

// <meta property="fc:frame:button:1:action" content="mint" />
frameproto.WriteFrameButton1Action(writer, frameproto.ButtonActionMint)

And:

// <meta property="fc:frame:button:1:action" content="post" />
frameproto.WriteFrameButton1Action(writer, frameproto.ButtonActionPost)

And:

// <meta property="fc:frame:button:1:action" content="post_redirect" />
frameproto.WriteFrameButton1Action(writer, frameproto.ButtonActionPostRedirect)

func WriteFrameButton1Target

func WriteFrameButton1Target(writer io.Writer, target string) error

WriteFrameButton1Target will write the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:1:target" name-value pair.

For example, this call:

var target string = "https://example.com/thing/do-it"

frameproto.WriteFrameButton1Target(writer, target)

Would write this HTML <meta/> element:

<meta property="fc:frame:button:1:target" content="https://example.com/thing/do-it" />

func WriteFrameButton2

func WriteFrameButton2(writer io.Writer, label string) error

WriteFrameButton2 will write the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:2" name-value pair.

For example, this call:

var label string = "go forward"

frameproto.WriteFrameButton2(writer, label)

Would write this HTML <meta/> element:

<meta property="fc:frame:button:2" content="go forward" />

func WriteFrameButton2Action

func WriteFrameButton2Action(writer io.Writer, action string) error

WriteFrameButton2Action will write the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:2:action" name-value pair.

For example, this call:

var buttonAction string = "post"

frameproto.WriteFrameButton2Action(writer, buttonAction)

Would write this HTML <meta/> element:

<meta property="fc:frame:button:2:action" content="post" />

Note that this package provides some constants to use with WriteFrameButton2Action. Namely: ButtonActionLink (for "link"), ButtonActionMint (for "mint"), ButtonActionPost (for "post"), and ButtonActionPostRedirect (for "post_redirect").

Which in code would be used as:

// <meta property="fc:frame:button:2:action" content="link" />
frameproto.WriteFrameButton2Action(writer, frameproto.ButtonActionLink)

And:

// <meta property="fc:frame:button:2:action" content="mint" />
frameproto.WriteFrameButton2Action(writer, frameproto.ButtonActionMint)

And:

// <meta property="fc:frame:button:2:action" content="post" />
frameproto.WriteFrameButton2Action(writer, frameproto.ButtonActionPost)

And:

// <meta property="fc:frame:button:2:action" content="post_redirect" />
frameproto.WriteFrameButton2Action(writer, frameproto.ButtonActionPostRedirect)

func WriteFrameButton2Target

func WriteFrameButton2Target(writer io.Writer, target string) error

WriteFrameButton2Target will write the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:2:target" name-value pair.

For example, this call:

var target string = "https://example.com/thing/do-it"

frameproto.WriteFrameButton2Target(writer, target)

Would write this HTML <meta/> element:

<meta property="fc:frame:button:2:target" content="https://example.com/thing/do-it" />

func WriteFrameButton3

func WriteFrameButton3(writer io.Writer, label string) error

WriteFrameButton3 will write the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:3" name-value pair.

For example, this call:

var label string = "go forward"

frameproto.WriteFrameButton3(writer, label)

Would write this HTML <meta/> element:

<meta property="fc:frame:button:3" content="go forward" />

func WriteFrameButton3Action

func WriteFrameButton3Action(writer io.Writer, action string) error

WriteFrameButton3Action will write the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:3:action" name-value pair.

For example, this call:

var buttonAction string = "post"

frameproto.WriteFrameButton3Action(writer, buttonAction)

Would write this HTML <meta/> element:

<meta property="fc:frame:button:3:action" content="post" />

Note that this package provides some constants to use with WriteFrameButton3Action. Namely: ButtonActionLink (for "link"), ButtonActionMint (for "mint"), ButtonActionPost (for "post"), and ButtonActionPostRedirect (for "post_redirect").

Which in code would be used as:

// <meta property="fc:frame:button:3:action" content="link" />
frameproto.WriteFrameButton3Action(writer, frameproto.ButtonActionLink)

And:

// <meta property="fc:frame:button:3:action" content="mint" />
frameproto.WriteFrameButton3Action(writer, frameproto.ButtonActionMint)

And:

// <meta property="fc:frame:button:3:action" content="post" />
frameproto.WriteFrameButton3Action(writer, frameproto.ButtonActionPost)

And:

// <meta property="fc:frame:button:3:action" content="post_redirect" />
frameproto.WriteFrameButton3Action(writer, frameproto.ButtonActionPostRedirect)

func WriteFrameButton3Target

func WriteFrameButton3Target(writer io.Writer, target string) error

WriteFrameButton3Target will write the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:3:target" name-value pair.

For example, this call:

var target string = "https://example.com/thing/do-it"

frameproto.WriteFrameButton3Target(writer, target)

Would write this HTML <meta/> element:

<meta property="fc:frame:button:3:target" content="https://example.com/thing/do-it" />

func WriteFrameButton4

func WriteFrameButton4(writer io.Writer, label string) error

WriteFrameButton4 will write the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:4" name-value pair.

For example, this call:

var label string = "go forward"

frameproto.WriteFrameButton4(writer, label)

Would write this HTML <meta/> element:

<meta property="fc:frame:button:4" content="go forward" />

func WriteFrameButton4Action

func WriteFrameButton4Action(writer io.Writer, action string) error

WriteFrameButton4Action will write the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:4:action" name-value pair.

For example, this call:

var buttonAction string = "post"

frameproto.WriteFrameButton4Action(writer, buttonAction)

Would write this HTML <meta/> element:

<meta property="fc:frame:button:4:action" content="post" />

Note that this package provides some constants to use with WriteFrameButton4Action. Namely: ButtonActionLink (for "link"), ButtonActionMint (for "mint"), ButtonActionPost (for "post"), and ButtonActionPostRedirect (for "post_redirect").

Which in code would be used as:

// <meta property="fc:frame:button:4:action" content="link" />
frameproto.WriteFrameButton4Action(writer, frameproto.ButtonActionLink)

And:

// <meta property="fc:frame:button:4:action" content="mint" />
frameproto.WriteFrameButton4Action(writer, frameproto.ButtonActionMint)

And:

// <meta property="fc:frame:button:4:action" content="post" />
frameproto.WriteFrameButton4Action(writer, frameproto.ButtonActionPost)

And:

// <meta property="fc:frame:button:4:action" content="post_redirect" />
frameproto.WriteFrameButton4Action(writer, frameproto.ButtonActionPostRedirect)

func WriteFrameButton4Target

func WriteFrameButton4Target(writer io.Writer, target string) error

WriteFrameButton4Target will write the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:button:4:target" name-value pair.

For example, this call:

var target string = "https://example.com/thing/do-it"

frameproto.WriteFrameButton4Target(writer, target)

Would write this HTML <meta/> element:

<meta property="fc:frame:button:4:target" content="https://example.com/thing/do-it" />

func WriteFrameImage

func WriteFrameImage(writer io.Writer, url string) error

WriteFrameImage will write the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:image" name-value pair.

For example, this call:

var url string = "https://example.com/images/screen.png"

frameproto.WriteFrameImage(writer, url)

Would write this HTML <meta/> element:

<meta property="fc:frame:image" content="https://example.com/images/screen.png" />

func WriteFrameImageAspectRatio

func WriteFrameImageAspectRatio(writer io.Writer, label string) error

WriteFrameImageAspectRatio will write the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:image:aspect_ratio" name-value pair.

For example, this call:

var aspectRatio string = "1.91:1"

frameproto.WriteFrameImageAspectRatio(writer, aspectRatio)

Would write this HTML <meta/> element:

<meta property="fc:frame:image:aspect_ratio" content="1.91:1" />

Note that this package provides some constants to use with WriteFrameImageAspectRatio. Namely: AspectRatioOnePointNineOneToOne (for "1.91:1") and AspectRatioOneToOne (for "1:1").

Which in code would be used at:

frameproto.WriteFrameImageAspectRatio(writer, frameproto.AspectRatioOnePointNineOneToOne)

And:

frameproto.WriteFrameImageAspectRatio(writer, frameproto.AspectRatioOneToOne)

func WriteFrameInputText

func WriteFrameInputText(writer io.Writer, label string) error

WriteFrameInputText will write the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:input:text" name-value pair.

For example, this call:

var label string = "enter your username"

frameproto.WriteFrameInputText(writer, label)

Would write this HTML <meta/> element:

<meta property="fc:frame:input:text" content="enter your username" />

func WriteFramePostURL

func WriteFramePostURL(writer io.Writer, url string) error

WriteFramePostURL will write the HTML <meta/> element for the Frame-Protocol's (i.e., Farcaster Frame's) "fc:frame:post_url" name-value pair.

For example, this call:

var url string = "https://example.com/my/post/path.php"

frameproto.WriteFramePostURL(writer, url)

Would write this HTML <meta/> element:

<meta property="fc:frame:post_url" content="https://example.com/my/post/path.php" />

func WriteSkeleFrame

func WriteSkeleFrame(writer io.Writer, frameWriterFunc func(io.Writer) error) error

WriteSkeleFrame takes care of creating a skeleton-HTML-page that the Frame-Protocol's (i.e., Farcaster Frame's) tags are included in.

For example, this:

frameproto.WriteSkeleFrame(w, func(writer io.Writer){

	// This will write:
	// <meta property="fc:frame" content="vNext" />
	frameproto.WriteFrame(writer, frameproto.VersionVNext)

	// This will write:
	// <meta property="fc:frame:image" content="https://example.com/path/to/img.png" />
	var imgURL string = "https://example.com/path/to/img.png"
	frameproto.WriteFrameImage(writer, imgURL)
})

Would write this:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" /
<meta property="fc:frame" content="vNext" />
<meta property="fc:frame:image" content="https://example.com/path/to/img.png" />
</head>
<body>
</body>
</html>

Note that http.ResponseWriter is an io.Writer. So this function can be used to write to http.ResponseWriter.

Types

type ActionBody

type ActionBody struct {
	UntrustedData ActionBodyUntrustedData `json:"untrustedData"`
	TrustedData   ActionBodyTrustedData   `json:"trustedData"`
}

ActionBody represents the data sent to a Frame-Protocol's (i.e., Farcaster Frame's) application when it is POSTed to.

Example usage:

p, err := io.ReadAll(request.Body)
if nil != err {
	return err
}

var actionBody frameproto.ActionBody

err := json.Unmarshal(p, &actionBody)
if nil != err {
	return err
}

type ActionBodyCastID

type ActionBodyCastID struct {
	FID  opt.Optional[uint64] `json:"fid"`
	Hash opt.Optional[string] `json:"hash"`
}

type ActionBodyTrustedData

type ActionBodyTrustedData struct {
	MessageBytes opt.Optional[string]
}

type ActionBodyUntrustedData

type ActionBodyUntrustedData struct {
	FID         opt.Optional[uint64] `json:"fid"`
	URL         opt.Optional[string] `json:"url"`
	MessageHash opt.Optional[string] `json:"messageHash"`
	Timestamp   opt.Optional[int64]  `json:"timestamp"`
	Network     opt.Optional[uint64] `json:"network"`
	ButtonIndex opt.Optional[uint64] `json:"buttonIndex"`
	InputText   opt.Optional[string] `json:"inputText"`
	CastID      ActionBodyCastID     `json:"castId"`
}

type FrameWriter

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
}

func CreateFrameWriter

func CreateFrameWriter(writer io.Writer) FrameWriter

CreateFrameWriter returns a FrameWriter that writers to an io.Writer.

For example:

func ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) {

	// ...

	var frameWriter frameproto.FrameWriter = frameproto.CreateFrameWriter(responseWriter)

	// ...

	frameWriter.WriteFrame(frameproto.VersionVNext)
	frameWriter.WriteFrameImage(imageURL)

	// ...

}

Source Files

Jump to

Keyboard shortcuts

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