$ faas-cli new --lang java11 java-fn
package com.openfaas.function;
import com.openfaas.model.IHandler;
import com.openfaas.model.IResponse;
import com.openfaas.model.IRequest;
import com.openfaas.model.Response;
public class Handler implements com.openfaas.model.IHandler {
public IResponse Handle(IRequest req) {
Response res = new Response();
res.setBody("Hello, world!");
return res;
}
}
$ faas-cli template store pull golang-http
$ faas-cli new --lang golang-http golang-http-fn
package function
import (
"fmt"
"net/http"
"github.com/openfaas-incubator/go-function-sdk"
)
// Handle a function invocation
func Handle(req handler.Request) (handler.Response, error) {
var err error
message := fmt.Sprintf("Hello world, input was: %s", string(req.Body))
return handler.Response{
Body: []byte(message),
StatusCode: http.StatusOK,
}, err
}
$ faas-cli new --lang python3 python3-fn
def handle(req):
"""handle a request to the function
Args:
req (str): request body
"""
return req
$ faas-cli new --lang node12 javascript-fn
"use strict"
module.exports = async (event, context) => {
const result = {
status: "Received input: " + JSON.stringify(event.body)
};
return context
.status(200)
.succeed(result);
}
$ faas-cli template store pull bash-streaming
$ faas-cli new --lang bash-streaming bash-fn
#!/bin/sh
for i in $(seq 1 100)
do
sleep 0.001
echo "Hello" $i
done
$ faas-cli new --lang dockerfile ruby
FROM ruby:2.7-alpine3.11
WORKDIR /home/app
COPY . .
RUN bundle install
CMD ["ruby", "main.rb"]