mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Per language HOWTO's on writing functions (#208)
* fnctl: improve UX for howto's * doc: go function howto * fnctl: show the progress of build calls * doc: php function howto * doc: fix Go HOWTO * doc: Node Functions HOWTO * doc: Python Functions HOWTO * doc: improve README files * doc: ccirello -> USERNAME * docs: fix Python example Used an idiomatic method (isatty) to decide whether stdin must be read or not. * doc: fix go example * fnctl: fix docker push output
This commit is contained in:
committed by
Seif Lotfy سيف لطفي
parent
c8e4a9b82b
commit
5b3971060b
5
docs/howto/go/.gitignore
vendored
Normal file
5
docs/howto/go/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
vendor/
|
||||
/hello
|
||||
/go
|
||||
/app
|
||||
/__uberscript__
|
||||
6
docs/howto/go/Dockerfile
Normal file
6
docs/howto/go/Dockerfile
Normal file
@@ -0,0 +1,6 @@
|
||||
FROM iron/go
|
||||
|
||||
WORKDIR /app
|
||||
ADD . /app
|
||||
|
||||
ENTRYPOINT ["./hello"]
|
||||
40
docs/howto/go/README.md
Normal file
40
docs/howto/go/README.md
Normal file
@@ -0,0 +1,40 @@
|
||||
## Quick Example for a Go Function (3 minutes)
|
||||
|
||||
This example will show you how to test and deploy Go (Golang) code to IronFunctions.
|
||||
|
||||
### 1. Prepare the `functions.yaml` file:
|
||||
|
||||
At functions.yaml you will find:
|
||||
```yml
|
||||
app: goapp
|
||||
route: /hello
|
||||
image: USERNAME/hello:0.0.1
|
||||
build:
|
||||
- docker run --rm -v "$PWD":/go/src/ -w /go/src/ -e "GOPATH=/go/src/vendor:/go" iron/go:dev go build -o hello
|
||||
```
|
||||
|
||||
The important step here is to ensure you replace `USERNAME` with your Docker Hub account name. Some points of note:
|
||||
the application name is `goapp` and the route for incoming requests is `/hello`. These informations are relevant for
|
||||
the moment you try to test this function.
|
||||
|
||||
### 2. Build:
|
||||
|
||||
```sh
|
||||
fnctl publish
|
||||
```
|
||||
|
||||
`-v` is optional, but it allows you to see how this function is being built.
|
||||
|
||||
### 3. Queue jobs for your function
|
||||
|
||||
Now you can start jobs on your function. Let's quickly queue up a job to try it out.
|
||||
|
||||
```sh
|
||||
cat hello.payload.json | fnctl run goapp /hello
|
||||
```
|
||||
|
||||
Here's a curl example to show how easy it is to do in any language:
|
||||
|
||||
```sh
|
||||
curl -H "Content-Type: application/json" -X POST -d @hello.payload.json http://localhost:8080/r/goapp/hello
|
||||
```
|
||||
5
docs/howto/go/functions.yaml
Normal file
5
docs/howto/go/functions.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
app: goapp
|
||||
route: /hello
|
||||
image: USERNAME/hello:0.0.1
|
||||
build:
|
||||
- docker run --rm -v "$PWD":/go/src/ -w /go/src/ -e "GOPATH=/go/src/vendor:/go" iron/go:dev go build -o hello
|
||||
17
docs/howto/go/hello.go
Normal file
17
docs/howto/go/hello.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Person struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func main() {
|
||||
p := &Person{Name: "World"}
|
||||
json.NewDecoder(os.Stdin).Decode(p)
|
||||
fmt.Println("Hello", p.Name, "!!!")
|
||||
}
|
||||
3
docs/howto/go/hello.payload.json
Normal file
3
docs/howto/go/hello.payload.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "Johnny"
|
||||
}
|
||||
Reference in New Issue
Block a user