Comments (5)
Hi @DanielLee343 thanks for your interest.
Unfortunately, you've deleted the issue template which has some important questions.
For sending data between functions, we recommend calling via the gateway and/or using async.
This is covered in detail in the docs and the eBook - https://gumroad.com/l/serverless-for-everyone-else
You don't say whether you have a copy, but you should find everything you need there.
Alex
from faasd.
Hi @alexellis
I read the eBook and tried to setup an async call within a function. There is some "vendor" problem whenever I want to re-build the image.
To reproduce
faas-cli template store pull golang-http
faas-cli new --lang golang-http fn1 --prefix lyuze
mv f1.yml stack.yml
faas-cli new --lang golang-http fn2 --prefix lyuze --append stack.yml
faas-cli up -f stack.yml
Everything is fine here, then I change the function code to
package function
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
handler "github.com/openfaas/templates-sdk/go-http"
)
func Handle(req handler.Request) (handler.Response, error) {
reqBody := url.Values{
"name": {"John Doe"},
"occupation": {"gardener"},
}
resp, err := http.PostForm("http://gateway.openfaas.svc.cluster.local:8080/function/fn2", reqBody)
if err != nil {
log.Fatal(err)
return handler.Response{}, err
}
defer resp.Body.Close()
bodyByte, err := ioutil.ReadAll(resp.Body)
fmt.Print("Body: %s", bodyByte)
// message := fmt.Sprintf("Body: %s", string(req.Body))
return handler.Response{
Body: bodyByte,
StatusCode: http.StatusOK,
}, err
}
I tried to re-build the image but it shows (no matter what changes I made to the code):
$ faas-cli up -f fn1.yml
...
Step 18/37 : RUN test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./function/vendor/*"))" || { echo "Run \"gofmt -s -w\" on your Golang code"; exit 1; }
---> Running in e14ea422864c
Run "gofmt -s -w" on your Golang code
The command '/bin/sh -c test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./function/vendor/*"))" || { echo "Run \"gofmt -s -w\" on your Golang code"; exit 1; }' returned a non-zero code: 1
[0] < Building fn1 done in 8.82s.
[0] Worker done.
Total build time: 8.82s
Errors received during build:
- [fn1] received non-zero exit code from build, error: The command '/bin/sh -c test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./function/vendor/*"))" || { echo "Run \"gofmt -s -w\" on your Golang code"; exit 1; }' returned a non-zero code: 1
Attempts I Tried
I tried to build with faas-cli build --build-arg GO111MODULE=on
, or go mod tidy
before build, neither worked.
I also saw this merge but didn't get anything from it.
I also changed to use template golang-middleware
, didn't work either.
from faasd.
Hi, this example is not part of Serverless For Everyone Else, this is a Go example.
Where did you get it from?
from faasd.
This is not from the eBook, but another issue with golang-middleware/golang-http template.
I simply changed the original template code of golang-middleware
to the following, which is from your youtube video (or the go-http-template example):
package function
import (
"net/http"
)
//handles a request
func Handle(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet {
w.WriteHeader(http.StatusOK)
w.Write([]byte("Access granted!"))
return
}
w.WriteHeader(http.StatusMethodNotAllowed)
w.Write([]byte("Access not allowed!"))
}
And faas-cli build -f fn1.yml
throws the above error.
A temp fix is commenting out the following line in the template Dockerfile:
RUN test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./function/vendor/*"))" || { echo "Run \"gofmt -s -w\" on your Golang code"; exit 1; }
from faasd.
The example repo should be working out of the box. If not can you create a separate issue in the template's repo?
We will get this closed since the two are not connected.
Thanks
from faasd.
Related Issues (20)
- Remove basic auth plugin HOT 3
- Support request for faasd and Go HOT 4
- Update to containerd 1.7.0 - last release with 32-bit Arm support
- Support request logging in HOT 2
- Issues with rust HOT 1
- Access host's network from a docker-compose.yaml's service HOT 5
- Support request for Docker installed with faasd (invalid) HOT 5
- Can docker-compose be used with faasd? HOT 8
- Support question on MQTT HOT 4
- Executing install.sh fails because of wrong version HOT 1
- Grafana installation - volume permissions HOT 2
- Multi-node support HOT 3
- Support request for monitoring with cAdvisor HOT 6
- NATS JetStream support HOT 2
- disable printing function invocation duration
- Terrraform install fails on macOS Sonoma HOT 2
- faasd and faasd provider in different ports HOT 1
- faasd namespace support openfaas=true instead of openfaas=1
- Is Scale to Zero included in the Community Edition of OpenFaaS? HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from faasd.