Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.

Commit 2e3605d

Browse files
authored
Update golang docs (#1138)
1 parent 78d3ced commit 2e3605d

File tree

1 file changed

+50
-13
lines changed

1 file changed

+50
-13
lines changed

docs/runtimes.md

+50-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Kubeless Runtime Variants
22

3-
By default Kubeless has support for runtimes in different states: stable and incubator. You can find the different runtimes available in this repository:
3+
By default Kubeless has support for runtimes in different states: stable and incubator. You can find the different runtimes available in this repository:
44

55
[https://github.com/kubeless/runtimes](https://github.com/kubeless/runtimes).
66

@@ -55,7 +55,7 @@ $ kubeless function deploy myFunction --runtime nodejs6 \
5555

5656
**For Webpack Users**
5757

58-
Your webpacked functions will be `require()`-d in so your bundle should work out of the box. However, if your bundle size is approaching 1mb you should take advantage of Kubeless' ability to install dependencies for you instead of bundling them all into your payload.
58+
Your webpacked functions will be `require()`-d in so your bundle should work out of the box. However, if your bundle size is approaching 1mb you should take advantage of Kubeless' ability to install dependencies for you instead of bundling them all into your payload.
5959

6060
You will need to customize your webpack config to suit your own project, but below is an sample config of how to achieve this in Webpack 4.x:
6161

@@ -123,7 +123,7 @@ For the Node.js runtime we start an [Express](http://expressjs.com) server and w
123123

124124
There is the [distroless](https://github.com/GoogleContainerTools/distroless) variant of the Node.js 8 runtime.
125125
The distroless Node.js runtime contains only the kubeless function and its runtime dependencies.
126-
In particular, this variant does not contain package manager, shells or any other programs which are part of a standard Linux distribution.
126+
In particular, this variant does not contain package manager, shells or any other programs which are part of a standard Linux distribution.
127127

128128
The same example Node.js function from above can then be deployed:
129129

@@ -204,7 +204,44 @@ func Handler(event functions.Event, context functions.Context) (string, error) {
204204

205205
#### Description
206206

207-
Go functions require to import the package `github.com/kubeless/kubeless/pkg/functions` that is used to define the input parameters. The desired method should be exported in the package. You can specify dependencies using a `Gopkg.toml` file, dependencies are installed using [`dep`](https://github.com/golang/dep).
207+
Go functions require to import the package `github.com/kubeless/kubeless/pkg/functions` that is used to define the input parameters. The desired method should be exported in the package. You can specify dependencies using [go modules](https://blog.golang.org/using-go-modules).
208+
209+
#### Go with Dependency Example
210+
211+
This is an example of a function using the `github.com/sirupsen/logrus` dependency.
212+
213+
```go
214+
// hellowithdeps.go
215+
216+
package kubeless
217+
218+
import (
219+
"github.com/kubeless/kubeless/pkg/functions"
220+
"github.com/sirupsen/logrus"
221+
)
222+
223+
// Hello sample function with dependencies
224+
func Hello(event functions.Event, context functions.Context) (string, error) {
225+
logrus.Info(event.Data)
226+
return "Hello world!", nil
227+
}
228+
```
229+
230+
```go
231+
//go.mod
232+
233+
module function
234+
235+
go 1.14
236+
237+
require (
238+
github.com/sirupsen/logrus v1.6.0
239+
)
240+
```
241+
242+
```bash
243+
kubeless function deploy get-go-deps --runtime go1.14 --handler hellowithdeps.Hello --from-file hellowithdeps.go --dependencies go.mod
244+
```
208245

209246
#### Server implementation
210247

@@ -261,7 +298,7 @@ func Foo(event functions.Event, context functions.Context) (string, error) {
261298
}
262299
```
263300

264-
If the function above has a timeout smaller than 5 seconds it will exit and the code after the `select{}` won't be executed.
301+
If the function above has a timeout smaller than 5 seconds it will exit and the code after the `select{}` won't be executed.
265302

266303
### Java
267304

@@ -462,13 +499,13 @@ public function foo(kubeless:Event event, kubeless:Context context) returns (str
462499

463500
#### Description
464501

465-
The Ballerina functions should import the package `kubeless/kubeless`. This [package](https://central.ballerina.io/kubeless/kubeless) contains two types `Event` and `Context`.
466-
502+
The Ballerina functions should import the package `kubeless/kubeless`. This [package](https://central.ballerina.io/kubeless/kubeless) contains two types `Event` and `Context`.
503+
467504
```console
468-
$ kubeless function deploy foo
469-
--runtime ballerina0.981.0
470-
--from-file foo.bal
471-
--handler foo.foo
505+
$ kubeless function deploy foo
506+
--runtime ballerina0.981.0
507+
--from-file foo.bal
508+
--handler foo.foo
472509
```
473510

474511
When using the Ballerina runtime, it is possible to provide a configuration via `kubeless.toml` file. The values in kubeless.toml file are available for the function. The function(.bal file) and conf file should be in the same directory.
@@ -482,8 +519,8 @@ foo
482519
$ zip -r -j foo.zip foo/
483520

484521
$ kubeless function deploy foo
485-
--runtime ballerina0.981.0
486-
--from-file foo.zip
522+
--runtime ballerina0.981.0
523+
--from-file foo.zip
487524
--handler hellowithconf.foo
488525
```
489526

0 commit comments

Comments
 (0)