Fix join (#2)

* fix: baseurl join

* chore: update graphql gen
This commit is contained in:
Jon Lundy 2022-09-07 12:26:14 -06:00 committed by GitHub
parent c5fdb1319c
commit 700d6370f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 9 deletions

View File

@ -6,9 +6,10 @@ import (
"crypto/sha256" "crypto/sha256"
"fmt" "fmt"
"log" "log"
"path" "net/url"
"strings" "strings"
"github.com/keys-pub/keys" "github.com/keys-pub/keys"
"github.com/oklog/ulid/v2" "github.com/oklog/ulid/v2"
"github.com/sour-is/ev/pkg/es/event" "github.com/sour-is/ev/pkg/es/event"
@ -52,9 +53,9 @@ func (a *SaltyUser) OnUserRegister(name string, pubkey *keys.EdX25519PublicKey)
func (a *SaltyUser) Nick() string { return a.name } func (a *SaltyUser) Nick() string { return a.name }
func (a *SaltyUser) Inbox() string { return a.inbox.String() } func (a *SaltyUser) Inbox() string { return a.inbox.String() }
func (a *SaltyUser) Pubkey() string { return a.pubkey.String() } func (a *SaltyUser) Pubkey() string { return a.pubkey.String() }
func (s *SaltyUser) Endpoint(ctx context.Context) string { func (s *SaltyUser) Endpoint(ctx context.Context) (string, error) {
svc := gql.FromContext[contextKey, *service](ctx, saltyKey) svc := gql.FromContext[contextKey, *service](ctx, saltyKey)
return path.Join(svc.BaseURL(), s.inbox.String()) return url.JoinPath(svc.BaseURL(), s.inbox.String())
} }
type UserRegistered struct { type UserRegistered struct {

View File

@ -8,7 +8,7 @@ import (
"fmt" "fmt"
"net" "net"
"net/http" "net/http"
"path" "net/url"
"strings" "strings"
"github.com/keys-pub/keys" "github.com/keys-pub/keys"
@ -124,12 +124,14 @@ func (s *service) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
basePath, _ := url.JoinPath(s.baseURL, a.inbox.String())
err = json.NewEncoder(w).Encode( err = json.NewEncoder(w).Encode(
struct { struct {
Endpoint string `json:"endpoint"` Endpoint string `json:"endpoint"`
Key string `json:"key"` Key string `json:"key"`
}{ }{
Endpoint: path.Join(s.baseURL, a.inbox.String()), Endpoint: basePath,
Key: a.pubkey.ID().String(), Key: a.pubkey.ID().String(),
}) })
if err != nil { if err != nil {

2
go.mod
View File

@ -1,6 +1,6 @@
module github.com/sour-is/ev module github.com/sour-is/ev
go 1.18 go 1.19
require ( require (
github.com/99designs/gqlgen v0.17.13 github.com/99designs/gqlgen v0.17.13

View File

@ -2267,7 +2267,7 @@ func (ec *executionContext) _SaltyUser_endpoint(ctx context.Context, field graph
}() }()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children ctx = rctx // use context from middleware stack in children
return obj.Endpoint(ctx), nil return obj.Endpoint(ctx)
}) })
if err != nil { if err != nil {
ec.Error(ctx, err) ec.Error(ctx, err)

10
main.go
View File

@ -4,9 +4,9 @@ import (
"context" "context"
"log" "log"
"net/http" "net/http"
"net/url"
"os" "os"
"os/signal" "os/signal"
"path"
"strings" "strings"
"time" "time"
@ -81,7 +81,13 @@ func run(ctx context.Context) error {
if enable.Has("salty") { if enable.Has("salty") {
span.AddEvent("Enable Salty") span.AddEvent("Enable Salty")
salty, err := salty.New(ctx, es, path.Join(env("EV_BASE_URL", "http://"+s.Addr), "inbox")) base, err := url.JoinPath(env("EV_BASE_URL", "http://"+s.Addr), "inbox")
if err != nil {
span.RecordError(err)
return err
}
salty, err := salty.New(ctx, es, base)
if err != nil { if err != nil {
span.RecordError(err) span.RecordError(err)
return err return err