Skip to content

Commit fc38e14

Browse files
committed
golang changes
1 parent 209a9f5 commit fc38e14

File tree

6 files changed

+277
-49
lines changed

6 files changed

+277
-49
lines changed

samples/golang-http-form/README.md

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,51 @@
44

55
This Go application demonstrates a simple form submission using the standard net/http library. Users can input their first name into a form, and upon submission, they will be greeted personally by the application.
66

7-
## Features
7+
## Prerequisites
88

9-
1. Simple form to submit a user's first name.
10-
2. Personalized greeting displayed in response to the form submission
9+
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
10+
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
11+
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
1112

12-
## Essential Setup Files
13+
## Development
1314

14-
1. A [Dockerfile](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/).
15-
2. A [compose file](https://docs.defang.io/docs/concepts/compose) to define and run multi-container Docker applications (this is how Defang identifies services to be deployed). (compose.yaml file)
15+
To run the application locally, you can use the following command:
1616

17-
## Prerequisite
17+
```bash
18+
docker compose up --build
19+
```
1820

19-
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
20-
2. If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc), make sure you have properly [authenticated your AWS account (optional)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)
21+
## Configuration
22+
23+
For this sample, you will not need to provide [configuration](https://docs.defang.io/docs/concepts/configuration).
24+
25+
If you wish to provide configuration, see below for an example of setting a configuration for a value named `API_KEY`.
26+
27+
```bash
28+
defang config set API_KEY
29+
```
30+
31+
## Deployment
32+
33+
> [!NOTE]
34+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
35+
36+
### Defang Playground
37+
38+
Deploy your application to the Defang Playground by opening up your terminal and typing:
39+
```bash
40+
defang compose up
41+
```
42+
43+
### BYOC (AWS)
2144

22-
## A Step-by-Step Guide
45+
If you want to deploy to your own cloud account, you can use Defang BYOC:
2346

24-
1. Open the terminal and type `defang login`
25-
2. Type `defang compose up` in the CLI
26-
3. Your app should be up and running with Defang in minutes!
47+
1. [Authenticate your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html), and check that you have properly set your environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`.
48+
2. Run in a terminal that has access to your AWS environment variables:
49+
```bash
50+
defang --provider=aws compose up
51+
```
2752

2853
---
2954

samples/golang-http/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,52 @@
44

55
A very simple example of a Go service that listens on a port and returns information about the request.
66

7+
## Prerequisites
8+
9+
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
10+
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
11+
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
12+
13+
## Development
14+
15+
To run the application locally, you can use the following command:
16+
17+
```bash
18+
docker compose up --build
19+
```
20+
21+
## Configuration
22+
23+
For this sample, you will not need to provide [configuration](https://docs.defang.io/docs/concepts/configuration).
24+
25+
If you wish to provide configuration, see below for an example of setting a configuration for a value named `API_KEY`.
26+
27+
```bash
28+
defang config set API_KEY
29+
```
30+
31+
## Deployment
32+
33+
> [!NOTE]
34+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
35+
36+
### Defang Playground
37+
38+
Deploy your application to the Defang Playground by opening up your terminal and typing:
39+
```bash
40+
defang compose up
41+
```
42+
43+
### BYOC (AWS)
44+
45+
If you want to deploy to your own cloud account, you can use Defang BYOC:
46+
47+
1. [Authenticate your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html), and check that you have properly set your environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`.
48+
2. Run in a terminal that has access to your AWS environment variables:
49+
```bash
50+
defang --provider=aws compose up
51+
```
52+
753
---
854

955
Title: Go HTTP Server

samples/golang-mongodb-atlas/README.md

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,59 @@
22

33
[![1-click-deploy](https://defang.io/deploy-with-defang.png)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-golang-mongodb-atlas-template%26template_owner%3DDefangSamples)
44

5-
## Overview
5+
This sample is a task manager application that uses Go and MongoDB Atlas, deployed with Defang.
66

7-
This sample is is a web-based task manager designed to help users manage their tasks efficiently. It allows users to add, delete, and view tasks in a simple and intuitive interface. This application is ideal for anyone looking to enhance their productivity by keeping track of their daily activities. There is a go.mod file that includes dependencies for the Dockerfile to install
7+
HTML and JavaScript are used for the frontend to interact with the backend via API calls. There is a `go.mod` file that includes dependencies for the Dockerfile to install.
88

9-
## Features
9+
There is a environment variable named `MONGO_URI` for the `MONGODB` connection string. In the `compose.yaml` file, be sure to put your MongoDB URI, i.e.
10+
`mongodb+srv://<username>:<pwd>@host`.
1011

11-
Create Tasks: Users can add new tasks with descriptions.
12-
Delete Tasks: Users can remove tasks when they are completed or no longer needed.
13-
View Tasks: Users can view a list of their current tasks.
12+
## Prerequisites
1413

15-
## Technology
14+
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
15+
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
16+
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
1617

17-
Backend: The application is built with Go (Golang), utilizing the powerful net/http standard library for handling HTTP requests and responses.
18-
Database: MongoDB is used for storing tasks. It is a NoSQL database that offers high performance, high availability, and easy scalability.
19-
Frontend: Basic HTML and JavaScript are used for the frontend to interact with the backend via API calls.
20-
Environment: Designed to run in containerized environments using Docker, which ensures consistency across different development and production environments.
18+
## Development
2119

22-
## Prerequisite
20+
To run the application locally, you can use the following command:
2321

24-
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
25-
2. If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc), make sure you have properly [authenticated your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)
26-
Plus, make sure that you have properly set all environment variables up
27-
3. There is a environment variable named MONGO_URI for the MONGODB connection string, in the compose file, be sure to put your mongodb URI, i.e.
28-
mongodb+srv://<username>:<pwd>@host
22+
```bash
23+
docker compose up --build
24+
```
25+
26+
## Configuration
27+
For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration):
28+
29+
> Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
30+
31+
### `MONGODB_URI`
32+
A URI for MongoDB that should have a format of `mongodb+srv://<username>:<pwd>@host`.
33+
```bash
34+
defang config set MONGODB_URI
35+
```
36+
37+
## Deployment
38+
39+
> [!NOTE]
40+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
41+
42+
### Defang Playground
43+
44+
Deploy your application to the Defang Playground by opening up your terminal and typing:
45+
```bash
46+
defang compose up
47+
```
48+
49+
### BYOC (AWS)
2950

30-
## A Step-by-Step Guide
51+
If you want to deploy to your own cloud account, you can use Defang BYOC:
3152

32-
1. Open the terminal and type `defang login`
33-
2. Type `defang compose up` in the CLI
34-
3. Your app should be up and running with Defang in minutes!
53+
1. [Authenticate your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html), and check that you have properly set your environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`.
54+
2. Run in a terminal that has access to your AWS environment variables:
55+
```bash
56+
defang --provider=aws compose up
57+
```
3558

3659
---
3760

samples/golang-openai/README.md

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,70 @@
11
# Golang & OpenAI
22

3-
[![1-click-deploy](https://defang.io/deploy-with-defang.png)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-golang-mongodb-atlas-template%26template_owner%3DDefangSamples)
3+
[![1-click-deploy](https://defang.io/deploy-with-defang.png)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-golang-openai-template%26template_owner%3DDefangSamples)
44

5-
## Setup
5+
This sample demonstrates how to deploy a Go project with OpenAI using Defang.
66

7-
This sample requires an API key to access the OpenAI API. The name of the config value is referenced in the compose.yaml file.
8-
To provide a value for it, you can use the Defang CLI like this:
7+
## Prerequisites
98

9+
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
10+
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
11+
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
12+
13+
## Development
14+
15+
To run the application locally, you can use the following command:
16+
17+
```bash
18+
docker compose up --build
1019
```
20+
21+
## Configuration
22+
For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration):
23+
24+
> Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
25+
26+
### `OPENAI_KEY`
27+
An API key to access the OpenAI API.
28+
29+
```bash
1130
defang config set --name OPENAI_KEY
1231
```
1332

14-
and then enter the value when prompted.
15-
1633
## Testing
34+
Below are some useful commands for testing.
1735

18-
```
36+
```bash
1937
echo "Hello" | curl -H "Content-Type: application/text" -d @- https://xxxxxxxx/prompt
2038
```
2139

22-
or
40+
or alternatively,
2341

24-
```
42+
```bash
2543
cat prompt.txt | curl -H "Content-Type: application/text" -d @- https://xxxxxxxx/prompt
2644
```
2745

46+
## Deployment
47+
48+
> [!NOTE]
49+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
50+
51+
### Defang Playground
52+
53+
Deploy your application to the Defang Playground by opening up your terminal and typing:
54+
```bash
55+
defang compose up
56+
```
57+
58+
### BYOC (AWS)
59+
60+
If you want to deploy to your own cloud account, you can use Defang BYOC:
61+
62+
1. [Authenticate your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html), and check that you have properly set your environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`.
63+
2. Run in a terminal that has access to your AWS environment variables:
64+
```bash
65+
defang --provider=aws compose up
66+
```
67+
2868
---
2969

3070
Title: Go & OpenAI

samples/golang-rest-api/README.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,55 @@
22

33
[![1-click-deploy](https://defang.io/deploy-with-defang.png)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-golang-rest-api-template%26template_owner%3DDefangSamples)
44

5-
This is a simple HTTP server written in Go that serves two endpoints: / and /rates. The / endpoint responds with a JSON object containing the status, while the /rates endpoint fetches data from the Fiscal Data Treasury API and returns the response to the client.
5+
This sample shows a Go HTTP server that uses a REST API to fetch data, deployed using Defang.
6+
7+
It serves two endpoints: `/` and `/rates`. The `/` endpoint responds with a JSON object containing the status, while the `/rates` endpoint fetches data from the [Fiscal Data Treasury API](https://fiscaldata.treasury.gov/api-documentation/) and returns the response to the client.
8+
9+
## Prerequisites
10+
11+
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
12+
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
13+
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
14+
15+
## Development
16+
17+
To run the application locally, you can use the following command:
18+
19+
```bash
20+
docker compose up --build
21+
```
22+
23+
## Configuration
24+
25+
For this sample, you will not need to provide [configuration](https://docs.defang.io/docs/concepts/configuration).
26+
27+
If you wish to provide configuration, see below for an example of setting a configuration for a value named `API_KEY`.
28+
29+
```bash
30+
defang config set API_KEY
31+
```
32+
33+
## Deployment
34+
35+
> [!NOTE]
36+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
37+
38+
### Defang Playground
39+
40+
Deploy your application to the Defang Playground by opening up your terminal and typing:
41+
```bash
42+
defang compose up
43+
```
44+
45+
### BYOC (AWS)
46+
47+
If you want to deploy to your own cloud account, you can use Defang BYOC:
48+
49+
1. [Authenticate your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html), and check that you have properly set your environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`.
50+
2. Run in a terminal that has access to your AWS environment variables:
51+
```bash
52+
defang --provider=aws compose up
53+
```
654

755
---
856

0 commit comments

Comments
 (0)