> For the complete documentation index, see [llms.txt](https://backbench.gitbook.io/backbench-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://backbench.gitbook.io/backbench-docs/getting-started/go.md).

# Go

Supports `Go1.x`, that means it updates to latest version of Go.

## Function declaration

In Go you can declare your function in small or big case. The usual big case are accessible throughout modules. A Public function needs to satify following conditions:-

1. Should use `package main` at the top.
2. Function name in Capital Case.
3. Return type must be `string, error`.
4. `string` return must be encapsulated inside `Response` struct; and called with method `send()`.
5. The above function needs be declared in `router.go` as final step.

{% code title="hello.go" %}

```go
package main//step-1

func FunctionName(req Request)(string, error){ //step-2,3
	r := &Response{"some string", nil} //step-4
	return r.send()
}
```

{% endcode %}

and `router.go` as;

{% code title="router.go" %}

```go
package main

var Router = map[string]func(Request) (string, error){
    "FunctionName": FunctionName,
}
```

{% endcode %}

**NOTE**: `,` needs to be present after declaring function. (**Important step**)

Request is a type that is shown as;

```go
type Request struct {
	Path string                 `json:"path"`
	Args map[string]interface{} `json:"args"`
}
```

`Args` is a string to interface map and has following **keys**.

```
method, path, body, headers, query
```

can retrieve information about request from here.

## Restrictions

* Module name cannot be `func.go`.
* Returns `json` with keys `data, error`.

## Example

Hello World in Go.

{% code title="main.go" %}

```go
package main

func Hello(req Request)(string, error){ 
	r := &Response{"Hello from GO!", nil}
	return r.send()
}
```

{% endcode %}

{% code title="router.go" %}

```go
package main

var Router = map[string]func(Request) (string, error){
    "Hello": Hello,
}
```

{% endcode %}

This returns response as `json`;

```javascript
{"data":"Hello from GO","error":null}
```
