Skip to content

digitalocean/sample-functions-golang-random

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Deploying the Function

Clone this repo:

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:

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 <funcName> --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.