e5e

package module
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2023 License: MIT Imports: 7 Imported by: 0

README

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:

go get -u go.anx.io/e5e

Getting started

package main

import (
	"runtime"
	
	"go.anx.io/e5e"
)

type SumEventData struct {
	A int `json:"a"`
	B int `json:"b"`
}

type SumEvent struct {
	e5e.Event
	Data SumEventData `json:"data,omitempty"`
}

// Using a custom `e5e.Context` class is optional and only needed to access the `Data` attribute on the
// context. This attribute may be used to get the return value of an authorizer function, for example. If access
// to the `Data` attribute is not needed, the `e5e.Context` type can be used on the entrypoint directly.

type SumContextData struct {
	AuthKey string `json:"auth_key"`
}

type SumContext struct {
	e5e.Context
	Data SumContextData `json:"data,omitempty"`
}

type entrypoints struct{}

func (f *entrypoints) MyEntrypoint(event SumEvent, context SumContext) (e5e.Result, error) {
	return e5e.Result{
		Status: 200,
		ResponseHeaders: map[string]string{
			"x-custom-response-header": "This is a custom response header",
		},
		Data: map[string]interface{}{
			"sum": event.Data.A + event.Data.B,
			"version": runtime.Version(),
		},
	}, nil
}

func main() {
	e5e.Start(&entrypoints{})
}

List of developers

Documentation

Index

Constants

View Source
const LibraryVersion = "1.2.0"

LibraryVersion represents the implemented custom binary interface version.

Variables

This section is empty.

Functions

func Start

func Start(entrypoints interface{})

Start takes the struct containing the available entrypoint methods and handles the invocation of the entrypoint as well as the communication with the e5e platform itself. Control will not be handed back after function execution. In case of an error a Go panic will be raised otherwise an os.Exit(0) occurs.

Rules:

  • Entrypoint functions must take 2 input parameters (Event and Context). Both types may be encapsulated within an user defined struct type.
  • Entrypoint functions must return 2 values (Result and error). Type encapsulation is also allowed here.
  • The input parameters as well as the return values must be compatible with "encoding/json" standard library.

Types

type Context

type Context struct {
	Async bool   `json:"async,omitempty"`
	Date  string `json:"date,omitempty"`
	Type  string `json:"type,omitempty"`
}

Context represents the passed `context` object of an e5e function. Contains all fields but `data`, as the user code is expected to encapsulate this struct within its own struct containing the `data` definition when necessary.

type Event

type Event struct {
	Params         map[string][]string `json:"params,omitempty"`
	RequestHeaders map[string]string   `json:"request_headers,omitempty"`
	Type           string              `json:"type,omitempty"`
}

Event represents the passed `event` object of an e5e function. Contains all fields but `data`, as the user code is expected to encapsulate this struct within its own struct containing the `data` definition.

type Result

type Result struct {
	Status          int               `json:"status,omitempty"`
	ResponseHeaders map[string]string `json:"response_headers,omitempty"`
	Data            interface{}       `json:"data"`
	Type            string            `json:"type,omitempty"`
}

Result represents the function result value passed back to E5E.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL