In this Golang Web Development Series #12, we'll learn the Golang WebAssembly (WASM) web application project structures that are ideal, scalable, and organized with step by step guide here in Golang's Web Development Series.
Example Syntax on How to Build Golang WASM in different OS:
BUILD WASM IN UBUNTU:
GOOS=js GOARCH=wasm go build -o /var/www/html/maharlikanscode.com/public_html/static/assets/js/auth/auth.wasm main.go
BUILD WASM IN WINDOWS:
set GOOS=js
set GOARCH=wasm
go build -o "C:\maharlikans_code\go\Golang Web Development\gowebapp\static\assets\js\auth\auth.wasm" main.go
Get Linode Account:
https://www.linode.com/?r=6aae17162e9...
Maharlikans Code Github:
https://github.com/maharlikanscode/go...
#MaharlikansCode
#GolangWebDevelopment12
#GolangWebAssemblyProjectStructure
#GolangWASM
#GoWASMProjectStructure
#GolangTutorial
#LearnGolangWebDevelopment
#Golang
#LifeAsSoftwareDeveloper
#Maharlikans
#FilipinoSoftwareDeveloper
If you go with extra mile for buying me a cup of coffee, I appreciate it guys: https://ko-fi.com/maharlikanscode
Source Codes:
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strconv"
"strings"
"syscall/js"
"time"
_ "github.com/go-sql-driver/mysql"
)
// login exposed function to JS interface{}
func login(this js.Value, args []js.Value) interface{} {
// Get the JS objects here
jsDoc := js.Global().Get("document")
if !jsDoc.Truthy() {
return js.Global().Call("eval", `Swal.fire("Oops!, Error", "Unable to get document object", "error");`)
}
username := jsDoc.Call("getElementById", "username")
if !username.Truthy() {
return js.Global().Call("eval", `Swal.fire("Oops!, Error", "Unable to get username", "error");`)
}
return nil
}
func exposeGoFunc() {
// Start exposing the following Go functions to JS client side
js.Global().Set("login", js.FuncOf(login))
}
func main() {
fmt.Println("Welcome to Maharlikans WASM tutorials")
c := make(chan bool, 1)
// Initializes all your exposable Go's functions to JS
exposeGoFunc()
lt-c
}