# 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}
```


---

# 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://backbench.gitbook.io/backbench-docs/getting-started/go.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.
