Comments (7)
All good.
from golang-http-template.
Hi Billy,
The version of the template you have has other changes, which means the import should be updated for your function to point at github.com/openfaas/templates-sdk/go-http
Here is an example of what it should look like now:
package function
import (
"fmt"
"net/http"
handler "github.com/openfaas/templates-sdk/go-http"
)
// Handle a function invocation
func Handle(req handler.Request) (handler.Response, error) {
var err error
message := fmt.Sprintf("Body: %s", string(req.Body))
return handler.Response{
Body: []byte(message),
StatusCode: http.StatusOK,
}, err
}
This then gives:
$ go mod tidy
go: finding module for package github.com/openfaas/templates-sdk/go-http
go: downloading github.com/openfaas/templates-sdk/go-http v0.0.0-20220408082716-5981c545cb03
go: downloading github.com/openfaas/templates-sdk v0.0.0-20220408082716-5981c545cb03
go: found github.com/openfaas/templates-sdk/go-http in github.com/openfaas/templates-sdk/go-http v0.0.0-20220408082716-5981c545cb03
This is my go.mod file for a test function:
module handler/function
go 1.18
require github.com/openfaas/templates-sdk/go-http v0.0.0-20220408082716-5981c545cb03
Let me know if this resolves the problem you're facing.
Alternatively, you can always pin an older version of a template if that suits your needs (#branch
#tag
#release
):
faas-cli template pull https://github.com/openfaas/golang-http-template#0.4.0
Fetch templates from repository: https://github.com/openfaas/golang-http-template at 0.4.0
2022/05/02 15:40:15 Attempting to expand templates from https://github.com/openfaas/golang-http-template
2022/05/02 15:40:16 Fetched 2 template(s) : [golang-http golang-middleware] from https://github.com/openfaas/golang-http-template
Alex
from golang-http-template.
I made the suggested changes after go mod tidy I have the following in go.mod
module myfunc
go 1.18
require (
github.com/google/uuid v1.3.0
github.com/honeybadger-io/honeybadger-go v0.5.0
github.com/openfaas/templates-sdk/go-http v0.0.0-20220408082716-5981c545cb03
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4
)
require (
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/pborman/uuid v1.2.0 // indirect
github.com/shirou/gopsutil v2.18.12+incompatible // indirect
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
)
When publishing now I run into
#26 [build 13/13] RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build --ldflags "-s -w" -a -installsuffix cgo -o handler . #26 0.136 main.go:16:2: package handler/function is not in GOROOT (/usr/local/go/src/handler/function) #26 ERROR: process "/bin/sh -c CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build --ldflags \"-s -w\" -a -installsuffix cgo -o handler ." did not complete successfully: exit code: 1
I have GO111MODULE
set to on
from golang-http-template.
changing module name from myfunc
to handler/function
fixed the issue.
from golang-http-template.
OK to close the issue?
from golang-http-template.
/lock: resolved
from golang-http-template.
If anyone else has similar issues, feel free to open your own issue on GitHub.
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
- 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.