• Stars
    star
    397
  • Rank 108,561 (Top 3 %)
  • Language
    Go
  • Created about 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Go Based WebAssembly framework for building frontend applications in Go!

Oak - The Go WebAssembly Framework

Godoc Reference Travis Build Status Go Report Card

Oak Framework

With the advent of Go supporting WebAssembly, I thought I'd take a crack at building a really simple Go based WebAssembly framework that allows you to build simple frontend applications in Go, without having to dive too deep into the bushes.


Goals

  • Easier frontend application development using Go

Tutorial

A tutorial describing Oak is avaiable here: https://tutorialedge.net/golang/writing-frontend-web-framework-webassembly-go/

CLI

If you want to easily run the example in this project, I suggest you try out the new Oak CLI which attempts to simplify the task of writing WebAssembly applications in Go.

$ make build-cli
$ cd examples/blog
$ ./oak start
Starting Server
2019/01/06 12:00:37 listening on ":8080"...

Simple Example

Let's take a look at how this framework could be used in a very simple example. We'll be create a really simple app that features on function, mycoolfunc(). We'll kick off our Oak framework within our main() function and then we'll register our coolfunc() function.

package main

import (
	"syscall/js"

	"github.com/elliotforbes/oak"
)

func mycoolfunc(i []js.Value) {
	println("My Awesome Function")
}

func main() {
	oak.Start()
	oak.RegisterFunction("coolfunc", mycoolfunc)
	// keeps our app running
	done := make(chan struct{}, 0)
	<-done
}

We can then call our coolfunc() function from our index.html like so:

<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<title>Go wasm</title>
	<script src="./static/wasm_exec.js"></script>
	<script src="./static/entrypoint.js"></script>
</head>
<body>	
    <h2>Super Simple Example</h2>
    <button class="btn btn-primary btn-block" onClick="coolfunc();" id="subtractButton">My Cool Func</button>
</body>

</html>

Components

package components

import (
	"syscall/js"

	"github.com/elliotforbes/oak"
)

type AboutComponent struct{}

var About AboutComponent

func init() {
	oak.RegisterFunction("coolFunc", CoolFunc)
}

func CoolFunc(i []js.Value) {
	println("does stuff")
}

func (a AboutComponent) Render() string {
	return `<div>
						<h2>About Component Actually Works</h2>
						<button onClick="coolFunc();">Cool Func</button>
					</div>`
}

Routing

package main

import (
	"github.com/elliotforbes/oak"
	"github.com/elliotforbes/oak/router"

	"github.com/elliotforbes/oak/examples/blog/components"
)

func main() {
	// Starts the Oak framework
	oak.Start()

	// Starts our Router
	router.NewRouter()
	router.RegisterRoute("about", aboutComponent)

	// keeps our app running
	done := make(chan struct{}, 0)
	<-done
}
<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<title>Blog</title>
	<link rel="stylesheet" href="./static/bootstrap.css">
	<link rel="stylesheet" href="./static/style.css">
	<script src="./static/wasm_exec.js"></script>
	<script src="./static/entrypoint.js"></script>
</head>
<body>	

  <div class="container">
    <h1>A Simple Blog</h1>

    <div id="view"></div>

    <button onClick="Link('home')">Home</button>
    <button onClick="Link('about')">About</button>

  </div>
</body>

</html>

More Repositories

1

angular-2-admin

An Angular 2 Admin Dashboard built using the Angular-CLI.
TypeScript
64
star
2

tutorialedge-rest-api

Go
50
star
3

ng-diff-match-patch

TypeScript
39
star
4

imgur-clone

An AWS Lambda + S3 + Serverless based Imgur Clone
JavaScript
39
star
5

Concurrency-With-Python

Python
36
star
6

ng-chat

TypeScript
36
star
7

angular-websockets

TypeScript
35
star
8

hackernews-vuejs

Vue
21
star
9

uptimegirl

Python
18
star
10

Angular-Component-Admin-Panel

HTML
12
star
11

realtime-chat-python

Python
11
star
12

go-graphql-tutorial

A reference implementation of a Go GraphQL server
Go
8
star
13

vue-diff-match-patch

JavaScript
8
star
14

broken-link-checker

A quick and simple GitHub Action that takes in the root URL for a website and crawls all of the pages on the sitemap.xml for broken links.
Makefile
6
star
15

angular-socket-io-example

JavaScript
6
star
16

angular-server-dashboard

JavaScript
5
star
17

athena

Go
4
star
18

imgur-clone-vuejs-nodejs

Vue
3
star
19

go-ci-pipeline-example

A simple Go project which features a full CI pipeline example
Go
3
star
20

website-analyzer

HTML
3
star
21

gowatch

A handy tool that watches for .go file changes within your directory and automatically re-runs the tests.
Go
3
star
22

network-monitor

Go
2
star
23

go-challenges

Go
2
star
24

go-immudb-tamperproof-payroll

Go
2
star
25

tuts-edge-rest-api

Python
1
star
26

tutorialedge-new

JavaScript
1
star
27

Tutorial-Edge

Java
1
star
28

AngularFuzzySearch

HTML
1
star
29

graphql-vuejs-blog

JavaScript
1
star
30

go-challenge.dev

The official repository for https://go-challenge.dev
Vue
1
star
31

skeleton-angular-2-project

HTML
1
star
32

go-face-recognition

Go
1
star
33

rs232-controller

Go
1
star
34

PyShell

Simple Python Shell
Python
1
star
35

EndlessRunner

Java
1
star
36

tuts-edge-api

Go
1
star
37

tutsedge-v5.3

PHP
1
star