e5e

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2020 License: MIT Imports: 7 Imported by: 1

README

go-e5e

PkgGoDev Build Status codecov Go Report Card

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

Install

With a correctly configured Go toolchain:

go get -u github.com/anexia-it/go-e5e

Getting started

package main

import (
	"runtime"

	"github.com/anexia-it/go-e5e"
)

type entrypoints struct{}

func (f *entrypoints) MyEntrypoint(event e5e.Event, context e5e.Context) (*e5e.Return, error) {
	return &e5e.Return{
		Status: 200,
		ResponseHeaders: map[string]string{
			"x-custom-response-header": "This is a custom response header",
		},
		Data: map[string]interface{}{
			"version": runtime.Version(),
		},
	}, nil
}

func main() {
	if err := e5e.Start(&entrypoints{}); err != nil {
		panic(err)
	}
}

List of developers

Documentation

Index

Constants

View Source
const (
	CustomBinaryInterfaceVersion = 2
)

Export a constant that indicates the implemented custom binary interface version.

Variables

This section is empty.

Functions

func Start

func Start(entrypoints interface{}) error

This function 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. Does not return if everything went well but does return an error if there are errors in the invocation or the entrypoint signature.

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"`
}

The struct for e5e context instances.

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"`
}

The struct for e5e event instances. Contains all fields but `data`, as the user code is expected to encapsulate this struct within it's own struct containing the `data` definition.

type Return

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

The struct for the result value of an entrypoint function.

Jump to

Keyboard shortcuts

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