Skip to content

v2.0.0

Choose a tag to compare

@beachmachine beachmachine released this 10 Jan 10:28
· 11 commits to main since this release
03b6068

Changed

  • Set minimum Go version to 1.18.
  • Rewritten the library to follow the Mux pattern of the net/http library.
    This ensures that there are no longer runtime errors for wrong entrypoint signatures, since everything
    needs to implement the new e5e.Handler interface now.
  • Add support for cancellation using context.Context.
  • Add support for strongly-typed request parameters, using the generics of Go 1.18.

A possible migration looks like this (old version first, new version second).

package main

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

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

func (e entrypoints) Sum(d SumEventData, _ e5e.Context) (e5e.Result, error) {
  return e5e.Result{Data: d.A + d.B}, nil
}

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

import (
  "context"
  "log"
  "go.anx.io/e5e/v2"
)

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

func Sum(ctx context.Context, request e5e.Request[SumEventData, any]) (*e5e.Result, error) {
  d := request.Data()
  return &e5e.Result{Data: d.A + d.B}, nil
}

func main() {
  e5e.AddHandlerFunc("Sum", Sum)
  e5e.Start(context.Background())
}

Added

  • Table-driven tests for tests
  • Add detailed documentation for all public types