All Projects → iwittkau → Auto Frontend

iwittkau / Auto Frontend

Licence: mit
Automatically generate frontends for go programs

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Auto Frontend

Composer Assets Plugin
Composer plugin for copying of frontend assets into public directory.
Stars: ✭ 20 (-45.95%)
Mutual labels:  frontend
Mber
Fast and minimal Ember.js CLI alternative, without broccoli.
Stars: ✭ 30 (-18.92%)
Mutual labels:  frontend
Restful.js
A pure JS client for interacting with server-side RESTful resources. Think Restangular without Angular.
Stars: ✭ 977 (+2540.54%)
Mutual labels:  frontend
Frontend Dev Bookmarks
Manually curated collection of resources for frontend web developers.
Stars: ✭ 32,924 (+88883.78%)
Mutual labels:  frontend
App Tutorial
Tutorial app which is built in the tutorial
Stars: ✭ 29 (-21.62%)
Mutual labels:  frontend
Itri Speech Recognition Dataset Generation
Automatic Speech Recognition Dataset Generation
Stars: ✭ 32 (-13.51%)
Mutual labels:  automatic
Astral
⊙ CSS franken-work ⊙
Stars: ✭ 14 (-62.16%)
Mutual labels:  frontend
Js Boilerplate
Boilerplate for any javascript frontend project
Stars: ✭ 36 (-2.7%)
Mutual labels:  frontend
Vanilla Todo
A case study on viable techniques for vanilla web development.
Stars: ✭ 951 (+2470.27%)
Mutual labels:  frontend
Ng Zorro Antd
Angular UI Component Library based on Ant Design
Stars: ✭ 7,841 (+21091.89%)
Mutual labels:  frontend
Mock Server
Easy to use, no frills http mock server
Stars: ✭ 27 (-27.03%)
Mutual labels:  frontend
Crossui
CrossUI is a free Cross-Browser Javascript framework with cutting-edge functionality for rich web application
Stars: ✭ 945 (+2454.05%)
Mutual labels:  frontend
Resourcerer
Declarative data-fetching and caching framework for REST APIs with React
Stars: ✭ 33 (-10.81%)
Mutual labels:  frontend
Gold Miner
🥇掘金翻译计划,可能是世界最大最好的英译中技术社区,最懂读者和译者的翻译平台:
Stars: ✭ 29,872 (+80635.14%)
Mutual labels:  frontend
Unicode Bidirectional
A Javascript implementation of the Unicode 9.0.0 Bidirectional Algorithm
Stars: ✭ 35 (-5.41%)
Mutual labels:  frontend
Organize
The file management automation tool.
Stars: ✭ 883 (+2286.49%)
Mutual labels:  automatic
Translations
Переводы от devSchacht
Stars: ✭ 959 (+2491.89%)
Mutual labels:  frontend
Codegen
A model-view based code generator written in Java
Stars: ✭ 36 (-2.7%)
Mutual labels:  automatic
Vue Beautiful Chat
A simple and beautiful Vue chat component backend agnostic, fully customisable and extendable.
Stars: ✭ 979 (+2545.95%)
Mutual labels:  frontend
Tarant
Reactive, actor based framework that can be used in client and server side.
Stars: ✭ 33 (-10.81%)
Mutual labels:  frontend

go-auto-frontend

Automatically generate frontends for go programs

Auto Frontend screenshot

Why?

Sometimes you want to write go programs without an exhaustive REST API. Auto Frontend lets you dynamically generate a simple, web-based frontend for your application.

How?

There are currently three basic types of interactions available:

  1. get values from your program
  2. set values in your program
  3. execute a function without getting or setting a specific value

Process

  1. Set up your buttons and callback functions
  2. Crete a new auto frontend instance
  3. Register your buttons
  4. Start the auto frontend instance

Features

  • Runs a temporary frontend for a go program
  • Use your own HTML template
  • Basic template provided, includes Bootstrap CSS
  • Connectivity status detection via WebSockets

Getting started

go get github.com/iwittkau/auto-frontend

Basic Example

package main

import (
	"fmt"

	"github.com/iwittkau/auto-frontend/button"
	"github.com/iwittkau/auto-frontend/frontend"
)

var (
	number  = 0
	getFunc = func() map[string]interface{} {
		return map[string]interface{}{
			"Number": number,
		}
	}

	setFunc = func(data map[string]interface{}) {
		fmt.Sscanf(data["Number"].(string), "%d", &number)
	}
)

func main() {

	// a button for getting the 'number' var
	// params: name, button styling class, button keys and a callback function
	// The button styling classes are aligned with Bootstrap: https://getbootstrap.com/docs/4.0/components/buttons/#examples
	btnGet1 := button.NewGet("Get Number", button.DefaultClassGet, button.Keys{"Number"}, getFunc)

	// a button to set the var
	btnSet1 := button.NewSet("Set Number", button.DefaultClassSet, button.Keys{"Number"}, setFunc)

	// Set a name, address with port, and a HTML template path (leave empty to use the default template)
	f := frontend.New("Auto Frontend", "localhost:8080", "")

	// register get button
	f.RegisterGetButtons(btnGet1)

	// register set button
	f.RegisterSetButtons(btnSet1)

	// start the frontend
	if err := f.Start(); err != nil {
		panic(err)
	}

	// frontend.Start() blocks, because it uses http.ListenAndServe()

}

Also check the example in example/multiple-components/.

Button Callback Functions

There are three types of callback functions, one for each component type:

type GetCallback func() map[string]interface{}
type SetCallback func(map[string]interface{})
type DoCallback func()

You have to implement these functions yourself. Panics inside these functions are recovered by the http package.

Button Keys

The keys of Get and Set buttons are required to generate the input fields in the frontend.

Please do not use keys with spaces!

This may work on the go side, but in the frontend they are used as IDs for HTML elements. Spaces in keys will break HTML frontend functions.

How to use keys

Consider this button:

btnGet1 := button.NewGet("Get Number", button.DefaultClassGet, button.Keys{"Number"}, getFunc)

In the button callback you have to use the same key:

getFunc = func() map[string]interface{} {
	return map[string]interface{}{
		"Number": number,
	}
}

Notice: there is a button.Keys{} struct available to declare keys.

Common mistakes with wrong keys

You might encounter a panic like this:

2018/04/03 14:58:21 http: panic serving 127.0.0.1:56107: interface conversion: interface {} is nil, not string

This is most certanly caused by a callback like this:

func(data map[string]interface{}) {
	fmt.Sscanf(data["Number3"].(string), "%d", &number2)
})

There might be no data available for the Key Number3, because this callback was set up for Number2.

Contributing

As I use this for my own projects, I know this might not be the perfect approach for all the projects out there. If you have any ideas, just open an issue and tell me what you think.

Related projects

I don't know of any other projects like this, that's why I created Auto Frontend in the first place. If you know of any other projects like this, please let me know.

Licensing

This project is licensed under MIT License.

Shoutouts

This project uses xid, a Globally Unique ID Generator made by rs. Thanks to jehna for the README template.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].