# Create your first project

{% hint style="info" %}
**Good to know:** I recommand to install wasmbrowsertest for live testings
{% endhint %}

## Minimal code for a WebAssembly project

You MUST always include a waiting channel at the end of the main function. If you're not including this channel, the wasm just load, exec and stopped. If you web app export some functions, handle events , all this functional code is unloaded and can't be used.

```
package main


func main() {
    
	ch := make(chan struct{})
	<-ch

}
```

## &#x20;Your first Hello World

Init your project with the namespace of your choice

```
go mod init hogosuruworld
```

Add the hogosuru framework:

```
GOOS=js GOARCH=wasm go get github.com/realPy/hogosuru@latest
```

Create your main.go with content:

```
package main

import (
	"github.com/realPy/hogosuru"
	"github.com/realPy/hogosuru/document"
	"github.com/realPy/hogosuru/htmlheadingelement"
)

func main() {
    hogosuru.Init()    
	//we get the current document if an error occur the err is draw to the console thank to AssertErr
	if doc, err := document.New(); hogosuru.AssertErr(err) {
		//we get the body of the document if an error occur the err is draw to the console thank to AssertErr
		if body, err := doc.Body(); hogosuru.AssertErr(err) {
			//now we create dynamiclly the h1 element
			if h1, err := htmlheadingelement.NewH1(doc); hogosuru.AssertErr(err) {
				//We set the text content with Hello World
				h1.SetTextContent("Hello world")
				// and append to the body
				body.AppendChild(h1.Node)
			}
		}
	}
	ch := make(chan struct{})
	<-ch

}
```

Launch main.go

```
WASM_HEADLESS=off GOOS=js GOARCH=wasm go run main.go
```

It open a chrome instance with content

![](/files/JtEIe6Gk5CUjCsOU7MEI)

## Let's take a closer look at the code

Your main must always call first the initialisation frameworks

```
  hogosuru.Init() 
```

Get the current document. If an error occurs AssertErr can handle this error and log in console. It's recommend to use AssertErr to handle error, AssertErr can be hook in a future version to a bug tracker like Sentry.

```
if doc, err := document.New(); hogosuru.AssertErr(err) {
```

Get the current body in the document

```
if body, err := doc.Body(); hogosuru.AssertErr(err) {
```

Create dynamically the htmlelement h1

```
if h1, err := htmlheadingelement.NewH1(doc); hogosuru.AssertErr(err) {
```

Set the text between the \<h1>\</h1>

```
	h1.SetTextContent("Hello world")
```

Append the h1 to the end of the node contains in body

```
body.AppendChild(h1.Node)
```

Infinite waiting with a channel

```
ch := make(chan struct{})
<-ch
```

{% hint style="info" %}
If a struct{} is sent to the channel, the wasm is unloaded and all current work and function are unloaded. This function can be used to reloaded a new wasm (for example) and you must ensure there is no work in progress.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hogosuru.v-ip.fr/guides/create-your-first-project.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
