# Naffg Native-like Application Framework For Golang This is a simple module that provide a desktop application windows for your application using the Windows' WebView2 API. This module also includes a basic http server based on net/http and provide a embedded client & server bundle in single binary using go:embed. ### Usage This module wraps an internal web resources folder and a WebView2 instance in one module, so you can easily get started building a simple local application using WebApp technology. The main components of this module consists of the following - WebView2 Instance - A HTTP Web Server (default to `:36850`, can be changed by `EventExchangePort` variable in `naffg.Options`) - Support embedded file system for Web UI files ### Example The following example assume you have the following folder structure with `res` storing all the UI resources (html, css and javascript files) ``` MyProject/ ├─ res/ │ ├─ index.html ├─ main.go ``` Content of `main.go` ```go package main import ( "embed" "encoding/json" "net/http" "github.com/tobychui/naffg" ) //go:embed res/* var uiFiles embed.FS func main() { app := naffg.NewApplication(&naffg.Options{ Title: "Hello World", Width: 400, Height: 300, Resizable: false, UiRes: &uiFiles, //Embed the UI resources UiResPreix: "res", //The folder where the resources is embeded from }) //Print the embedded files app.Debug_PrintEmbeddedFiles() //Handle the API, for example /api/hello?name=John app.Mux().HandleFunc("/api/hello", func(w http.ResponseWriter, r *http.Request) { //Get the name from the query name := r.URL.Query().Get("name") if name == "" { name = "Who are you?" } else { name = "Hello, " + name } //Write the response js, _ := json.Marshal(name) w.Header().Set("Content-Type", "application/json") w.Write([]byte(js)) }) // Run the application app.Run() } ``` Content of the `./res/index.html` ```html
Enter a name in the input box and click send