Giter Club home page Giter Club logo

Comments (5)

alexellis avatar alexellis commented on June 8, 2024 1

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.

DanielLee343 avatar DanielLee343 commented on June 8, 2024

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.

alexellis avatar alexellis commented on June 8, 2024

Hi, this example is not part of Serverless For Everyone Else, this is a Go example.

Where did you get it from?

from faasd.

DanielLee343 avatar DanielLee343 commented on June 8, 2024

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.

alexellis avatar alexellis commented on June 8, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.