Skip to content

golang openfaas method example instead of function

Notifications You must be signed in to change notification settings

fakturk/openfaas_method

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

openfaas_method

golang openfaas method example instead of function

Golang method is nothing but a function with a special receiver argument.

If you want to use use Golang methods in OpenFaaS you can find a template in the template/go-method folder that use method of Parent type struct isntead of a function.

We can create a new function by the following code

faas-cli new --lang go-method <function-name>

Now we have a handler.go file in the 'function-name' folder


import (
	"fmt"
)

//Parent struct
type Parent struct {
	Name string
}

// Handle a serverless request
func (p *Parent) Handle(req []byte) string {
	return fmt.Sprintf("Hello, Go. You said: %s and name of the parent is :%s", string(req), p.Name)
}

Now we can build, push and deploy our code

faas-cli build -f <function-name>.yml

faas-cli push -f <function-name>.yml

faas-cli deploy -f <function-name>.yml

Or we can replace build/push/deploy with faas-cli up

About

golang openfaas method example instead of function

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published