go.anx.io/e5e


The highest tagged major version is v2.

go-e5e

PkgGoDev Build Status codecov Go Report Card

go-e5e is a support library to help Go developers build Anexia e5e functions.

Install

With a correctly configured Go toolchain:

1go get -u go.anx.io/e5e

Getting started

 1package main
 2
 3import (
 4	"runtime"
 5	
 6	"go.anx.io/e5e"
 7)
 8
 9type SumEventData struct {
10	A int `json:"a"`
11	B int `json:"b"`
12}
13
14type SumEvent struct {
15	e5e.Event
16	Data SumEventData `json:"data,omitempty"`
17}
18
19// Using a custom `e5e.Context` class is optional and only needed to access the `Data` attribute on the
20// context. This attribute may be used to get the return value of an authorizer function, for example. If access
21// to the `Data` attribute is not needed, the `e5e.Context` type can be used on the entrypoint directly.
22
23type SumContextData struct {
24	AuthKey string `json:"auth_key"`
25}
26
27type SumContext struct {
28	e5e.Context
29	Data SumContextData `json:"data,omitempty"`
30}
31
32type entrypoints struct{}
33
34func (f *entrypoints) MyEntrypoint(event SumEvent, context SumContext) (e5e.Result, error) {
35	return e5e.Result{
36		Status: 200,
37		ResponseHeaders: map[string]string{
38			"x-custom-response-header": "This is a custom response header",
39		},
40		Data: map[string]interface{}{
41			"sum": event.Data.A + event.Data.B,
42			"version": runtime.Version(),
43		},
44	}, nil
45}
46
47func main() {
48	e5e.Start(&entrypoints{})
49}

List of developers