https://github.com/digitalocean/sample-functions-golang-random
⛵ App Platform sample for a function that returns a random number.
https://github.com/digitalocean/sample-functions-golang-random
app-sample
Last synced: about 1 year ago
JSON representation
⛵ App Platform sample for a function that returns a random number.
- Host: GitHub
- URL: https://github.com/digitalocean/sample-functions-golang-random
- Owner: digitalocean
- Created: 2022-04-13T17:14:06.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-05-06T16:54:15.000Z (about 1 year ago)
- Last Synced: 2025-05-06T17:49:58.726Z (about 1 year ago)
- Topics: app-sample
- Language: Go
- Homepage:
- Size: 108 KB
- Stars: 3
- Watchers: 74
- Forks: 11
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sample Function: Go "Random"
## Introduction
This repository contains a sample "Random" function written in Go. You can deploy it on DigitalOcean's App Platform as a Serverless Function component or as a standalone Function. Documentation is available at https://docs.digitalocean.com/products/functions.
**Note: Following these steps may result in charges for the use of DigitalOcean services.**
### Requirements
* You need a DigitalOcean account. If you don't already have one, you can sign up at [https://cloud.digitalocean.com/registrations/new](https://cloud.digitalocean.com/registrations/new).
* To deploy from the command line, you will need the [DigitalOcean `doctl` CLI](https://github.com/digitalocean/doctl/releases).
## Deploying the Function
Clone this repo:
```shell
git clone git@github.com:digitalocean/sample-functions-golang-random.git
```
Deploy the project, using a remote build so that compiled executable matches the runtime environment:
```shell
doctl serverless deploy sample-functions-golang-random --remote-build
```
The output from the deploy command will resemble the following:
```
Deploying 'sample-functions-golang-random'
to namespace 'fn-...'
on host '...'
Submitted function 'sample/random' for remote building and deployment in runtime go:default (id: ...)
Deployment status recorded in 'sample-functions-golang-random/.deployed'
Deployed functions ('doctl sls fn get --url' for URL):
- sample/random
```
## Using the Function
Invoking the function will return a random number from 0 to 100.
```
doctl serverless functions invoke sample/random
```
Use this command to retrieve the URL for your function and use it as an API.
```
doctl sls fn get sample/random --url
```
You can use that API directly in your browser, with `curl` or with an API platform such as Postman.
Parameters may be passed as query parameters, or as JSON body. Here is an example using `curl`.
```
curl `doctl sls fn get sample/random --url`
```
### Learn More
You can learn more about Functions by reading the [Functions Documentation](https://docs.digitalocean.com/products/functions).