Let's make a basic working Vugu application that runs in your browser. It only takes three small files to start. Make sure you have at least Go 1.12 installed.

    • Create a new empty folder anywhere you like. We'll use the name testapp as an example. Each file you create will be directly in this folder, no subfolders are needed.

    • Create go.mod which specifies a Go module name. To get started, you can pick any name you like as a placeholder following the pattern shown. For example:

    1. module example.org/someone/testapp
    • Create a Vugu component file. We'll put a click handler and an element that toggles to demonstrate some basic functionality. This first component should be called root.vugu:

    1. <div class="my-first-vugu-comp">
    2. <button @click="data.Toggle()">Test</button>
    3. <div vg-if="data.Show">I am here!</div>
    4. </div>
    5.  
    6. <style>
    7. .my-first-vugu-comp { background: #eee; }
    8. </style>
    9.  
    10. <script type="application/x-go">
    11. type RootData struct { Show bool }
    12. func (data *RootData) Toggle() { data.Show = !data.Show }
    13. </script>
    • Create a development server file. Note that this does not get compiled to WebAssembly. This is a server which serves your program up to the browser. devserver.go:

    1. // +build ignore
    2.  
    3. package main
    4.  
    5. import (
    6. "log"
    7. "net/http"
    8. "os"
    9.  
    10. "github.com/vugu/vugu/simplehttp"
    11. )
    12.  
    13. func main() {
    14. wd, _ := os.Getwd()
    15. l := "127.0.0.1:8844"
    16. log.Printf("Starting HTTP Server at %q", l)
    17. h := simplehttp.New(wd, true)
    18. // include a CSS file
    19. // simplehttp.DefaultStaticData["CSSFiles"] = []string{ "/my/file.css" }
    20. log.Fatal(http.ListenAndServe(l, h))
    21. }
    • Run the server. While in the same directory, run the command go run devserver.go

    After a few brief moments, the server should start. It works the same on Windows, Linux or Mac.

    • Marvel at the wonder you have created.