{"id":19037065,"url":"https://github.com/retgits/of-templates","last_synced_at":"2026-05-06T19:30:20.130Z","repository":{"id":143785047,"uuid":"188899034","full_name":"retgits/of-templates","owner":"retgits","description":"Custom templates for OpenFaaS","archived":false,"fork":false,"pushed_at":"2019-06-13T18:28:34.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-02T06:14:09.925Z","etag":null,"topics":["openfaas","openfaas-template"],"latest_commit_sha":null,"homepage":"https://www.openfaas.com/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/retgits.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-27T19:32:12.000Z","updated_at":"2019-06-13T18:28:36.000Z","dependencies_parsed_at":"2023-06-08T18:45:08.914Z","dependency_job_id":null,"html_url":"https://github.com/retgits/of-templates","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/retgits%2Fof-templates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/retgits%2Fof-templates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/retgits%2Fof-templates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/retgits%2Fof-templates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/retgits","download_url":"https://codeload.github.com/retgits/of-templates/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240093186,"owners_count":19746786,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["openfaas","openfaas-template"],"created_at":"2024-11-08T21:58:36.473Z","updated_at":"2026-05-06T19:30:20.085Z","avatar_url":"https://github.com/retgits.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Custom OpenFaaS Templates\n\nThis repository contains templates for [OpenFaaS](https://openfaas.com) which I use for my OpenFaaS functions.\n\n```\n$ faas-cli template pull https://github.com/retgits/of-templates\n$ faas-cli new --list\n\nLanguages available as templates:\n- gomods-http\n- go-arti-http\n```\n\n## gomods-http\n\nThe template _gomods-http_ is equivalent to [`golang-http`](https://github.com/openfaas-incubator/golang-http-template/tree/master/template/golang-http) with the exception being this template uses [Go modules](https://github.com/golang/go/wiki/Modules) and the Go [1.12.5](https://golang.org/doc/go1.12)\n\n## go-arti-http\n\nThe template _go-arti-http_ is equivalent to `gomods-http` with the exception being this template uses [JFrog Artifactory](https://jfrog.com/artifactory) to resolve Go modules. If you need an Artifactory instance yo try it out, you can use [JFrog's testdrive](https://try.jfrog.com) and get a four-day triel of both Artifactory and Xray.\n\n## Status of the templates\n\nThe template is customized to suit my needs, though if you have any thoughts or suggestions, I'd love to hear them.\n\nJust like the `golang-http` template, this template makes use of the OpenFaaS incubator project [of-watchdog](https://github.com/openfaas-incubator/of-watchdog).\n\n### Trying the templates\n\n```\n$ faas-cli template pull https://github.com/retgits/of-templates\n$ faas-cli new --lang \u003ctemplate\u003e \u003cfn-name\u003e\n```\n\nThe above commands will create a folder with the name of your function and a set of files:\n\n```text\n.\n├── go.mod\n├── go.sum\n└── handler.go\n```\n\nYou can change the name of your package by updating the name in the `go.mod` file. The build template will automatically pick up the correct name when building an OpenFaaS function. It is important that you keep the `package function` declaration at the top of `handler.go`.\n\nWhen using the `go-arti-http` template, you'll need to set a few `build-args` for it to work. \n\n```\n# The command\nfaas-cli build -f stacks.yml -b APP_VERSION=\u003cversion of your app\u003e -b APP_NAME=\u003cname of your app\u003e -b ARTIFACTORY_URL=\u003cartifactory host\u003e -b ARTIFACTORY_USER=\u003cartifactory user\u003e -b ARTIFACTORY_PASSWD=\u003cartifactory password\u003e\n```\n\nThe build automatically creates a `buildInfo` in Artifactory and publishes the dependencies in case they do not yet exist.\n\n### Example usage\n\nThe below samples are from the [OpenFaaS](https://github.com/openfaas-incubator/golang-http-template) repository.\n\nExample writing a successful message:\n\n```go\npackage function\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\n\t\"github.com/openfaas-incubator/go-function-sdk\"\n)\n\n// Handle a function invocation\nfunc Handle(req handler.Request) (handler.Response, error) {\n\tvar err error\n\n\tmessage := fmt.Sprintf(\"Hello world, input was: %s\", string(req.Body))\n\n\treturn handler.Response{\n\t\tBody:       []byte(message),\n    }, err\n}\n```\n\nExample writing a custom status code\n\n```go\npackage function\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\n\t\"github.com/openfaas-incubator/go-function-sdk\"\n)\n\n// Handle a function invocation\nfunc Handle(req handler.Request) (handler.Response, error) {\n\tvar err error\n\n\treturn handler.Response{\n\t\tBody:       []byte(\"Your workload was accepted\"),\n\t\tStatusCode: http.StatusAccepted,\n\t}, err\n}\n```\n\nExample writing an error / failure.\n\n```go\npackage function\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\n\t\"github.com/openfaas-incubator/go-function-sdk\"\n)\n\n// Handle a function invocation\nfunc Handle(req handler.Request) (handler.Response, error) {\n\tvar err error\n\n\treturn handler.Response{\n        Body: []byte(\"the input was invalid\")\n\t}, fmt.Errorf(\"invalid input\")\n}\n```\n\nThe error will be logged to `stderr` and the `body` will be written to the client along with a HTTP 500 status code.\n\nExample reading a header.\n\n```go\npackage function\n\nimport (\n\t\"log\"\n\n\t\"github.com/openfaas-incubator/go-function-sdk\"\n)\n\n// Handle a function invocation\nfunc Handle(req handler.Request) (handler.Response, error) {\n\tvar err error\n\n\tlog.Println(req.Header) // Check function logs for the request headers\n\n\treturn handler.Response{\n\t\tBody: []byte(\"This is the response\"),\n\t\tHeader: map[string][]string{\n\t\t\t\"X-Served-By\": []string{\"My Awesome Function\"},\n\t\t},\n\t}, err\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fretgits%2Fof-templates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fretgits%2Fof-templates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fretgits%2Fof-templates/lists"}