fix: webfinger redirects

This commit is contained in:
Jon Lundy
2023-04-02 21:00:22 -06:00
parent 9168f5c7bc
commit b8c2f9f510
15 changed files with 79 additions and 114 deletions

View File

@@ -12,7 +12,7 @@ type Aggregate interface {
// ApplyEvent applies the event to the aggrigate state
ApplyEvent(...Event)
AggregateRootInterface
AggregateRoot
}
func Start(a Aggregate, i uint64) {
@@ -49,7 +49,7 @@ func ShouldExist(a Aggregate) error {
return nil
}
type AggregateRootInterface interface {
type AggregateRoot interface {
// Events returns the aggregate events
// pass true for only uncommitted events
Events(bool) Events
@@ -68,9 +68,9 @@ type AggregateRootInterface interface {
Commit()
}
var _ AggregateRootInterface = &AggregateRoot{}
var _ AggregateRoot = &IsAggregate{}
type AggregateRoot struct {
type IsAggregate struct {
events Events
streamID string
firstIndex uint64
@@ -79,12 +79,12 @@ type AggregateRoot struct {
mu sync.RWMutex
}
func (a *AggregateRoot) Commit() { a.lastIndex = uint64(len(a.events)) }
func (a *AggregateRoot) StreamID() string { return a.streamID }
func (a *AggregateRoot) SetStreamID(streamID string) { a.streamID = streamID }
func (a *AggregateRoot) StreamVersion() uint64 { return a.lastIndex }
func (a *AggregateRoot) Version() uint64 { return a.firstIndex + uint64(len(a.events)) }
func (a *AggregateRoot) Events(new bool) Events {
func (a *IsAggregate) Commit() { a.lastIndex = uint64(len(a.events)) }
func (a *IsAggregate) StreamID() string { return a.streamID }
func (a *IsAggregate) SetStreamID(streamID string) { a.streamID = streamID }
func (a *IsAggregate) StreamVersion() uint64 { return a.lastIndex }
func (a *IsAggregate) Version() uint64 { return a.firstIndex + uint64(len(a.events)) }
func (a *IsAggregate) Events(new bool) Events {
a.mu.RLock()
defer a.mu.RUnlock()
@@ -99,13 +99,13 @@ func (a *AggregateRoot) Events(new bool) Events {
return lis
}
func (a *AggregateRoot) start(i uint64) {
func (a *IsAggregate) start(i uint64) {
a.firstIndex = i
a.lastIndex = i
}
//lint:ignore U1000 is called by embeded interface
func (a *AggregateRoot) raise(lis ...Event) { //nolint
func (a *IsAggregate) raise(lis ...Event) { //nolint
a.mu.Lock()
defer a.mu.Unlock()
@@ -115,7 +115,7 @@ func (a *AggregateRoot) raise(lis ...Event) { //nolint
}
//lint:ignore U1000 is called by embeded interface
func (a *AggregateRoot) append(lis ...Event) {
func (a *IsAggregate) append(lis ...Event) {
a.mu.Lock()
defer a.mu.Unlock()
@@ -125,7 +125,7 @@ func (a *AggregateRoot) append(lis ...Event) {
a.lastIndex += uint64(len(lis))
}
func (a *AggregateRoot) posStartAt(lis ...Event) {
func (a *IsAggregate) posStartAt(lis ...Event) {
for i, e := range lis {
m := e.EventMeta()
m.Position = a.lastIndex + uint64(i) + 1

View File

@@ -1,7 +1,6 @@
package event_test
import (
"encoding/json"
"testing"
"go.sour.is/ev/pkg/es/event"
@@ -10,7 +9,7 @@ import (
type Agg struct {
Value string
event.AggregateRoot
event.IsAggregate
}
var _ event.Aggregate = (*Agg)(nil)
@@ -38,13 +37,6 @@ type ValueApplied struct {
var _ event.Event = (*ValueApplied)(nil)
func (e *ValueApplied) MarshalBinary() ([]byte, error) {
return json.Marshal(e)
}
func (e *ValueApplied) UnmarshalBinary(b []byte) error {
return json.Unmarshal(b, e)
}
func TestAggregate(t *testing.T) {
agg := &Agg{}
event.Append(agg, &ValueApplied{Value: "one"})

View File

@@ -4,7 +4,6 @@ package event
import (
"context"
"crypto/rand"
"encoding"
"fmt"
"io"
"strconv"
@@ -32,9 +31,6 @@ func getULID() ulid.ULID {
type Event interface {
EventMeta() Meta
SetEventMeta(Meta)
encoding.BinaryMarshaler
encoding.BinaryUnmarshaler
}
// Events is a list of events

View File

@@ -3,6 +3,7 @@ package event
import (
"bytes"
"context"
"encoding"
"encoding/json"
"fmt"
"net/url"
@@ -151,7 +152,8 @@ func GetContainer(ctx context.Context, s string) Event {
return e
}
func MarshalBinary(e Event) (txt []byte, err error) {
func MarshalBinary(e Event) ([]byte, error) {
var err error
b := &bytes.Buffer{}
m := e.EventMeta()
@@ -167,10 +169,22 @@ func MarshalBinary(e Event) (txt []byte, err error) {
return nil, err
}
b.WriteRune('\t')
if txt, err = e.MarshalBinary(); err != nil {
return nil, err
switch e := e.(type) {
case encoding.BinaryMarshaler:
var txt []byte
if txt, err = e.MarshalBinary(); err != nil {
return nil, err
}
_, err = b.Write(txt)
case encoding.TextMarshaler:
var txt []byte
if txt, err = e.MarshalText(); err != nil {
return nil, err
}
_, err = b.Write(txt)
default:
err = json.NewEncoder(b).Encode(e)
}
_, err = b.Write(txt)
return b.Bytes(), err
}
@@ -200,12 +214,23 @@ func UnmarshalBinary(ctx context.Context, txt []byte, pos uint64) (e Event, err
eventType := string(sp[2])
e = GetContainer(ctx, eventType)
span.AddEvent(fmt.Sprintf("%s == %T", eventType, e))
if err = e.UnmarshalBinary(sp[3]); err != nil {
span.RecordError(err)
return nil, err
switch e := e.(type) {
case encoding.BinaryUnmarshaler:
if err = e.UnmarshalBinary(sp[3]); err != nil {
span.RecordError(err)
return nil, err
}
case encoding.TextUnmarshaler:
if err = e.UnmarshalText(sp[3]); err != nil {
span.RecordError(err)
return nil, err
}
default:
if err = json.Unmarshal(sp[3], e); err != nil {
span.RecordError(err)
return nil, err
}
}
e.SetEventMeta(m)
return e, nil

View File

@@ -2,6 +2,8 @@ package es
import (
"context"
"encoding"
"encoding/json"
"errors"
"fmt"
"net/http"
@@ -164,8 +166,17 @@ func (e *GQLEvent) Values() map[string]interface{} {
return event.Values(e.e)
}
func (e *GQLEvent) Bytes() (string, error) {
b, err := e.e.MarshalBinary()
return string(b), err
switch e := e.e.(type) {
case encoding.BinaryMarshaler:
b, err := e.MarshalBinary()
return string(b), err
case encoding.TextMarshaler:
b, err := e.MarshalText()
return string(b), err
default:
b, err := json.Marshal(e)
return string(b), err
}
}
func (e *GQLEvent) Meta() *event.Meta {
meta := e.e.EventMeta()

View File

@@ -82,10 +82,10 @@ func Handler(title string, endpoint string) http.HandlerFunc {
"endpoint": endpoint,
"endpointIsAbsolute": endpointHasScheme(endpoint),
"subscriptionEndpoint": getSubscriptionEndpoint(endpoint),
"version": "2.0.13",
"version": "2.4.1",
"reactVersion": "17.0.2",
"cssSRI": "sha256-qKvndYgkAMQOBoa1SZF9NlbIig+kQ3Fk4f8wlrEqBLw=",
"jsSRI": "sha256-dExtzxjgqXfOgQ94xw079jAjd4dPAFrO2Qz6I3Yd9Ko=",
"cssSRI": "sha256-bGeEsMhcAqeXBjh2w0eQzBTFAxwlxhM0PKIKqMshlnk=",
"jsSRI": "sha256-s+f7CFAPSUIygFnRC2nfoiEKd3liCUy+snSdYFAoLUc=",
"reactSRI": "sha256-Ipu/TQ50iCCVZBUsZyNJfxrDk0E2yhaEIz0vqI+kFG8=",
"reactDOMSRI": "sha256-nbMykgB6tsOFJ7OdVmPpdqMFVk4ZsqWocT6issAPUF0=",
})