Giter VIP home page Giter VIP logo

Comments (17)

alexellis avatar alexellis commented on June 1, 2024

Good find Michael.

This seems valid, although I didn't run into it in my usage of the template with @ewilde where we also vendored dependencies for the Monzo demos. I wonder what was different?

My suggestion as a workaround would be to try to add a constraint whereby you skip / omit the sdk dependency in the Gopkg.toml or delete it manually as you are doing now.

We need to figure out whether it's possible to have a package with its own vendor folder and then another sub-folder with more vendored folders under that. We get away with this in the "normal" Go template by not having an SDK at all.

from golang-http-template.

alexellis avatar alexellis commented on June 1, 2024

Derek add label: help wanted

from golang-http-template.

alexellis avatar alexellis commented on June 1, 2024

I got a similar error with your example:

# handler
./main.go:37:39: cannot use req 
(type "handler/vendor/github.com/openfaas-incubator/go-function-sdk".Request) 
as type 
"handler/function/vendor/github.com/openfaas-incubator/go-function-sdk".Request
 in argument to function.Handle

from golang-http-template.

alexellis avatar alexellis commented on June 1, 2024

I wonder if we can edit the Dockerfile so that the vendor folder gets moved one level up ready for the build?

from golang-http-template.

embano1 avatar embano1 commented on June 1, 2024

Couple of thoughts on this:

  • dep does not support nested vendor folders (golang/dep#985)
  • moving all dependencies (incl. openfaas-sdk) into the function subfolder won't compile (main.go can't resolve openfaas-sdk dependencies)
  • moving all dependencies (incl. those from the function handler.go) into a vendor folder in the main.go build context folder (i.e. where Dockerfile resides) works

User story: As a template user I want to specify packages and versions in Gopkg.toml. faas-cli build should be able to merge this with template specific dependencies (e.g. openfaas-sdk).

faas-cli build only seems to copy function folder into the build folder (merged with the template logic). So the questions are:

  • Where should user-specific dependency lock information be stored?
  • How can we merge the individual Gopkg.toml files in the best way?

A workaround could be:

  1. Run dep init in the root folder of the function (where the stack file, etc are located as well)
  2. dep will create a vendor folder there (incl. openfaas-sdk deps)
  3. Document the supported SDK pkg version to be used for the template (currently it's master anyways)
  4. User is free to modify Gopkg.toml as per his/her needs (besides SDK version of course)
  5. faas-cli would copy Gopkg.* to the function build context and run dep ensure -vendor-only
  6. This will create a vendor folder in the root build (context) folder of the function

Not sure how much work that is for the faas-cli tool or whether there's a better/cleaner approach.

from golang-http-template.

SidGrundfos avatar SidGrundfos commented on June 1, 2024

Hello.
I have an import as below -
import (
"log"

"github.com/nats-io/nats.go"
"github.com/nats-io/stan.go"

)
when I run go install publish-msg-go/handler.go it compiles ok
but when faas-cli build it gives me error

function/handler.go:6:2: cannot find package "github.com/nats-io/nats.go" in any of:
/usr/local/go/src/github.com/nats-io/nats.go (from $GOROOT)
/go/src/github.com/nats-io/nats.go (from $GOPATH)
function/handler.go:7:2: cannot find package "github.com/nats-io/stan.go" in any of:
/usr/local/go/src/github.com/nats-io/stan.go (from $GOROOT)
/go/src/github.com/nats-io/stan.go (from $GOPATH)
FAASError

from golang-http-template.

alexellis avatar alexellis commented on June 1, 2024

I've been able to use nested folders with dep, Incan share an example if you want?

Ideally you should be looking at Go modules now. Try the example that I added to the readme last week.

from golang-http-template.

SidGrundfos avatar SidGrundfos commented on June 1, 2024

Actually I am trying to test with NATS streaming and want to execute a small piece of code to send/publish messages. I have installed these modules in $GOPATH. when I build locally it builds OK but via faas-cli it fails. Any suggestion how I can make it work?

from golang-http-template.

LucasRoesler avatar LucasRoesler commented on June 1, 2024

@SidGrundfos can you push your test function to a new git repo and share that? It will be easier to debug.

Also, for your specific case, have you seen the test functions in the nats-connector repo? https://github.com/openfaas-incubator/nats-connector/tree/master/contrib/test-functions
And the "try it out" instructions https://github.com/openfaas-incubator/nats-connector#try-it-out

Even if you aren't using the nats connector, perhaps you can checkout those test functions as a reference for your situation. It includes a publish function

from golang-http-template.

SidGrundfos avatar SidGrundfos commented on June 1, 2024

Hello its is just a very small piece of code.

package function

import (
"log"
"fmt"
"net/http"

"github.com/nats-io/nats.go"
"github.com/nats-io/stan.go"

)

// Handle a function invocation
func Handle() {
nc, err := nats.Connect("nats://example-nats:4222")
if err != nil {
log.Fatal(err)
}
sc, err := stan.Connect("example-stan", "client-123", stan.NatsConn(nc))
if err != nil {
log.Fatal(err)
}
sc.Publish("hello", []byte("one"))
sc.Publish("hello", []byte("two"))
sc.Publish("hello", []byte("three"))

sc.Subscribe("hello", func(m *stan.Msg) {
	log.Printf("[Received] %+v", m)
}, stan.DeliverAllAvailable())

select {}

}

I have made 2 functions using c# to send and receive functions in openfaas which works fine.

from golang-http-template.

alexellis avatar alexellis commented on June 1, 2024

cc @LucasRoesler

from golang-http-template.

alexellis avatar alexellis commented on June 1, 2024

@SidGrundfos it looks like Lucas asked for a complete GitHub repo so that we can reproduce the issue. Could you provide that?

from golang-http-template.

SidGrundfos avatar SidGrundfos commented on June 1, 2024

Hi Alex & Lucas, can you please close this issue. I am working with C# now and its working fine. Don't need it anymore. Thanks for all the help.
If only if you could give me any docs or samples regarding Async / NATS Streaming (C#)
Thanks again!

from golang-http-template.

alexellis avatar alexellis commented on June 1, 2024

Feel free to ask on Slack.

from golang-http-template.

alexellis avatar alexellis commented on June 1, 2024

/msg: slack

from golang-http-template.

derek avatar derek commented on June 1, 2024

--
Join Slack to connect with the community
https://docs.openfaas.com/community

from golang-http-template.

alexellis avatar alexellis commented on June 1, 2024

I'll lock the thread now since it's old, if anyone lands here with an issue, please open your own one.

from golang-http-template.

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.