Skip to content

Commit bfd6e76

Browse files
Added Go Server (#17)
* Added go server * Added readme for go server * Fixed documentation and read me of go files * Updated readme for go server * Updated documentation of json.go * Updated formatting of license in go files * Added cors middleware handler to go server * Fixed readme for go server * Update README.md Added manual go installation instructions * Update README.md Added link for manual Go installation * Update README.md to skip to manual install for Go * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Updated documentation of main.go
1 parent 9e81005 commit bfd6e76

File tree

6 files changed

+546
-4
lines changed

6 files changed

+546
-4
lines changed

README.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99
- [Intro](#intro)
1010
- [API documentation](#api-documentation)
1111
- [Installation](#installation)
12-
- [Using bash script(Linux/macOS)](#using-bash-scriptlinuxmacos)
12+
- [Using bash script for Node.js/Flask on Linux/macOS](#using-bash-script-for-nodejsflask-on-linuxmacos)
1313
- [Install manually(Linux/macOS/Windows)](#install-manuallylinuxmacoswindows)
1414
- [nvm(Node Version Manager) installation](#nvmnode-version-manager-installation)
1515
- [Node.js installation](#nodejs-installation)
1616
- [Flask installation](#flask-installation)
17+
- [Go installation](#go-installation)
1718
- [Run the app](#run-the-app)
1819
- [Run React client](#run-react-client)
1920
- [Run backend server](#run-backend-server)
2021
- [Configure and run Node.js backend](#configure-and-run-nodejs-backend)
2122
- [Configure and run Python/Flask backend](#configure-and-run-pythonflask-backend)
23+
- [Configure and run Go backend](#configure-and-run-go-backend)
2224
- [Usage](#usage)
2325

2426
## Intro
@@ -33,7 +35,7 @@ Streaming mode uses Gemini's streaming capability to achieve faster interactions
3335
The client for this app is written using [React](https://react.dev/) and served using [Vite](https://github.com/vitejs/vite).
3436

3537
### Backend
36-
The app currently has 2 different backend servers that the user can choose from, [Flask](https://flask.palletsprojects.com/en/3.0.x/quickstart/) and [Node.js](https://Node.js.org/en).
38+
The app currently has 3 different backend servers that the user can choose from, [Flask](https://flask.palletsprojects.com/en/3.0.x/quickstart/), [Node.js](https://Node.js.org/en) or [Go](https://go.dev)
3739

3840
## API documentation
3941
### Endpoints available
@@ -90,8 +92,8 @@ This is the <b>streaming</b> POST method route. Use this to send the chat messag
9092
## Installation
9193
Click [here](#windows) to skip to installation on Windows.
9294

93-
For Linux/macOS a setup bash script is available for easy installation. If you prefer installing manually you can skip to [next section](#install-manuallylinuxmacoswindows).
94-
### Using bash script(Linux/macOS)
95+
If your choice of backend is Node.js or Flask, for Linux/macOS a setup bash script is available for easy installation. The bash script does not support installation of Go. If you wish to use Go as your backend or prefer installing manually, you can skip to the [next section](#install-manuallylinuxmacoswindows).
96+
### Using bash script for Node.js/Flask on Linux/macOS
9597
#### Make the script executable
9698
```
9799
chmod +x setup.sh
@@ -167,6 +169,14 @@ You can quickly install the required packages using the `package.json` file.
167169
pip install -r requirements.txt
168170
```
169171

172+
#### Go installation
173+
174+
Check if Go is already installed on your system.
175+
```
176+
go version
177+
```
178+
If Go is not installed, follow the instructions for your operating system from the [official Go installation guide](https://go.dev/doc/install).
179+
170180
## Run the app
171181
To launch the app you have to perform the following steps:
172182
1. Run React client
@@ -238,6 +248,22 @@ python app.py
238248
```
239249
The server will start on `localhost:9000`.
240250

251+
##### Configure and run Go backend
252+
###### Configuration
253+
You need a Gemini API key to run the server,
254+
255+
If you don't have a Gemini API key ready, you can create a key with one click in [Google AI Studio](https://aistudio.google.com/app/apikey).
256+
You must set the API key as an environment variable while running the application.
257+
258+
###### Running the Application
259+
1. Navigate to the app directory, `server-go` (i.e. where main.go is located).
260+
2. Run the application with the following command.
261+
```
262+
GOOGLE_API_KEY=<your_api_key> go run .
263+
```
264+
The server will start on `localhost:9000`.
265+
By default, the server starts on port 9000. You can override the default port the server listens on by setting the environment variable `PORT` in the command above.
266+
241267
## Usage
242268
To start using the app, visit [http://localhost:3000](http://localhost:3000/)
243269

server-go/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Gemini chat app with Go
2+
3+
## Install Go
4+
To run this server, Go must be installed on your system.
5+
Check if Go is already installed.
6+
```
7+
go version
8+
```
9+
If Go is not installed, follow the instructions for your operating system from the [official Go installation guide](https://go.dev/doc/install).
10+
11+
## Run the application
12+
You need a Gemini API key to run the server,
13+
14+
If you don't have a Gemini API key ready, you can create a key with one click in [Google AI Studio](https://aistudio.google.com/app/apikey).
15+
16+
1. Navigate to the app directory, `server-go` (i.e. where main.go is located).
17+
2. Run the application with the following command.
18+
```
19+
GOOGLE_API_KEY=<your_api_key> PORT=<your_port> go run .
20+
```
21+
22+
## Environment Variables
23+
* GOOGLE_API_KEY: API key for Gemini service.
24+
* PORT: The port this server is listening on (default 9000).

server-go/go.mod

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module chat
2+
3+
go 1.23.0
4+
5+
require (
6+
github.com/google/generative-ai-go v0.18.0
7+
github.com/rs/cors v1.11.1
8+
google.golang.org/api v0.199.0
9+
)
10+
11+
require (
12+
cloud.google.com/go v0.115.1 // indirect
13+
cloud.google.com/go/ai v0.8.2 // indirect
14+
cloud.google.com/go/auth v0.9.7 // indirect
15+
cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect
16+
cloud.google.com/go/compute/metadata v0.5.2 // indirect
17+
cloud.google.com/go/longrunning v0.6.1 // indirect
18+
github.com/felixge/httpsnoop v1.0.4 // indirect
19+
github.com/go-logr/logr v1.4.2 // indirect
20+
github.com/go-logr/stdr v1.2.2 // indirect
21+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
22+
github.com/google/s2a-go v0.1.8 // indirect
23+
github.com/google/uuid v1.6.0 // indirect
24+
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
25+
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
26+
go.opencensus.io v0.24.0 // indirect
27+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.55.0 // indirect
28+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0 // indirect
29+
go.opentelemetry.io/otel v1.30.0 // indirect
30+
go.opentelemetry.io/otel/metric v1.30.0 // indirect
31+
go.opentelemetry.io/otel/trace v1.30.0 // indirect
32+
golang.org/x/crypto v0.27.0 // indirect
33+
golang.org/x/net v0.29.0 // indirect
34+
golang.org/x/oauth2 v0.23.0 // indirect
35+
golang.org/x/sync v0.8.0 // indirect
36+
golang.org/x/sys v0.26.0 // indirect
37+
golang.org/x/text v0.19.0 // indirect
38+
golang.org/x/time v0.7.0 // indirect
39+
google.golang.org/genproto/googleapis/api v0.0.0-20240930140551-af27646dc61f // indirect
40+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240930140551-af27646dc61f // indirect
41+
google.golang.org/grpc v1.67.1 // indirect
42+
google.golang.org/protobuf v1.34.2 // indirect
43+
)

0 commit comments

Comments
 (0)