Mould

22 commits, 8 files, 244.00 KiBgit clone http://git.cblgh.org/mould.git

Mould is an all-inclusive form builder and server that uses a custom syntax for succinctly declaring a form.

Mould parses the incoming syntax and generates a form and a server that will serve the form and receive its responses. Responses are saved in a json file and persisted between restarts of the form server.

Usage

go run main.go --input example-form-format.txt
go build server.go
./server
# Listening on port:  :7272
# Visit localhost:7272 in your browser to see the form in action! :)

Flags

Generating the form page has a few options you can provide, other than the form input, such as providing custom html and styles:

go run main.go --help

  -html-footer string
        a single html file containing all of the html that will be presented immediately below the form contents
  -html-header string
        a single html file containing all of the html that will be presented immediately above the form contents
  -input string
        a file containing the form format to generate a form server using
  -stylesheet string
        a single css file containing styles that will be applied to the form (fully replaces mould's default styling)

Change the port the server will run on by passing the --port flag:

go run server.go --help

  -port int
        the port to serve the form server on (default 7272)

Example

form-title          = Nonsensical Form
form-desc           = Hey! Hello! This is a nonsensical form served by <untitled form>
form-bg             = wheat
form-titlecolor     = purple
form-fg             = black
input[Name]         = Preferred moniker
textarea[Address]   = Your fediverse residence, else null
number[Money]#amount = min=1, max=100, value=1
radio[Sky type]     = Sunny, Rainy, Moony

Or generically:

<element>[<title>]#<key> = <content>

Currently supported html form elements:

Basic auth: Password protection

Mould has support for http basic authentication with the form-password and form-user form options. To enable basic auth set at least form-password in the form syntax input (default user: mouldy).

Basic auth should be used in combination with https / TLS secured connections to prevent snooping the set password (http specifies that basic credentials are passed in plaintext with the request).

How does it work?

Messily!

From the input syntax I generate the html page that will be served for the form as well as go code, representing the response model. The generated go code is used to parse responses that the form server receives.

All responses are saved in a local json file every time they come through. Respondents, on submitting, are redirected to a static url containing their responses, should they forget what they responded and want to refresh their memory.

The local json file is used to repopulate the form database between server restarts.

Why did you do this?

Yes, why indeed

Well it’s done now!!!