Comments (17)
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.
Derek add label: help wanted
from golang-http-template.
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.
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.
Couple of thoughts on this:
dep
does not support nestedvendor
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 avendor
folder in themain.go
build context folder (i.e. whereDockerfile
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:
- Run
dep init
in the root folder of the function (where the stack file, etc are located as well) dep
will create avendor
folder there (incl. openfaas-sdk deps)- Document the supported SDK pkg version to be used for the template (currently it's
master
anyways) - User is free to modify
Gopkg.toml
as per his/her needs (besides SDK version of course) faas-cli
would copyGopkg.*
to the function build context and rundep ensure -vendor-only
- 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.
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)
from golang-http-template.
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.
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.
@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.
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.
from golang-http-template.
@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.
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.
Feel free to ask on Slack.
from golang-http-template.
/msg: slack
from golang-http-template.
--
Join Slack to connect with the community
https://docs.openfaas.com/community
from golang-http-template.
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)
- Go modules - unable to get a sub-package to work HOT 7
- Graceful shutdown for Kubernetes
- Broken link to golang-middleware section of README.md HOT 1
- golang-http does not allow graceful request cancelling HOT 5
- Improve caching for sub-package cache HOT 1
- not set ADDITIONAL_PACKAGE arg HOT 3
- Feature: replace alpine Docker image with scratch HOT 3
- Add multi-arch support, with fallback to current behaviour HOT 3
- Feature: Add Busybox Binary Version HOT 2
- received non-zero exit code from build, error: invalid platform architecture "amd64}" HOT 1
- Getting `go: inconsistent vendoring` error when a module is located within function HOT 23
- Cannot find package HOT 2
- Enable Go modules as a default HOT 3
- Cannot build with go modules HOT 7
- Use of-watchdog 0.9.3 to suppress custom health check logging messages
- Replace ioutil HOT 3
- Add a GitHub Action to do a test build for both templates HOT 1
- Cannot publish Function after updating template HOT 7
- Unable to use vendoring with golang-http HOT 16
- chore: remove unused atomic int
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 golang-http-template.