Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/elliotforbes/go-webassembly-framework
A Go Based WebAssembly framework for building frontend applications in Go!
https://github.com/elliotforbes/go-webassembly-framework
frontend-framework go golang webassembly
Last synced: 5 days ago
JSON representation
A Go Based WebAssembly framework for building frontend applications in Go!
- Host: GitHub
- URL: https://github.com/elliotforbes/go-webassembly-framework
- Owner: elliotforbes
- Created: 2018-10-27T15:13:16.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-02-25T02:02:08.000Z (over 1 year ago)
- Last Synced: 2024-08-02T18:40:19.954Z (3 months ago)
- Topics: frontend-framework, go, golang, webassembly
- Language: Go
- Homepage:
- Size: 4.83 MB
- Stars: 397
- Watchers: 24
- Forks: 34
- Open Issues: 4
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
Oak - The Go WebAssembly Framework
===================================[![Godoc Reference](https://camo.githubusercontent.com/6321d9723db4c8f80466aaa83c19d4afb9fdd208/68747470733a2f2f676f646f632e6f72672f6769746875622e636f6d2f6f616b6d6f756e642f6f616b3f7374617475732e737667)](https://godoc.org/github.com/elliotforbes/go-webassembly-framework) [![Travis Build Status](https://api.travis-ci.org/elliotforbes/oak.svg?branch=master)](https://travis-ci.org/elliotforbes/go-webassembly-framework) [![Go Report Card](https://goreportcard.com/badge/github.com/elliotforbes/oak)](https://goreportcard.com/report/github.com/elliotforbes/go-webassembly-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.
```s
$ 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.
```go
package mainimport (
"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:
```html
Go wasm
Super Simple Example
My Cool Func```
## Components
```go
package componentsimport (
"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 ``
About Component Actually Works
Cool Func
}
```## Routing
```go
package mainimport (
"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
}
``````html
Blog
A Simple Blog
Home
About
```