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: "UI events example", 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() }