Giter VIP home page Giter VIP logo

Comments (7)

willfore avatar willfore commented on June 1, 2024 1

All good.

from golang-http-template.

alexellis avatar alexellis commented on June 1, 2024

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.

willfore avatar willfore commented on June 1, 2024

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.

willfore avatar willfore commented on June 1, 2024

changing module name from myfunc to handler/function fixed the issue.

from golang-http-template.

alexellis avatar alexellis commented on June 1, 2024

OK to close the issue?

from golang-http-template.

alexellis avatar alexellis commented on June 1, 2024

/lock: resolved

from golang-http-template.

alexellis avatar alexellis commented on June 1, 2024

If anyone else has similar issues, feel free to open your own issue on GitHub.

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.