-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
612 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
run: | ||
build-tags: | ||
- wireinject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package di | ||
|
||
import ( | ||
"github.com/google/wire" | ||
"github.com/planetary-social/go-notification-service/service/app" | ||
) | ||
|
||
var downloaderSet = wire.NewSet( | ||
app.NewDownloader, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,113 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/boreq/errors" | ||
"github.com/nbd-wtf/go-nostr" | ||
"github.com/nbd-wtf/go-nostr/nip19" | ||
"github.com/planetary-social/go-notification-service/cmd/notification-service/di" | ||
"github.com/planetary-social/go-notification-service/internal/fixtures" | ||
"github.com/planetary-social/go-notification-service/service/app" | ||
"github.com/planetary-social/go-notification-service/service/config" | ||
"github.com/planetary-social/go-notification-service/service/domain" | ||
) | ||
|
||
func main() { | ||
if err := run(); err != nil { | ||
fmt.Printf("error: %s", err) | ||
os.Exit(1) | ||
} | ||
|
||
} | ||
|
||
func run() error { | ||
return errors.New("not implemented") | ||
ctx := context.Background() | ||
cfg, err := config.NewConfig("", "test-project-id") | ||
if err != nil { | ||
return errors.Wrap(err, "error creating a config") | ||
} | ||
|
||
service, cleanup, err := di.BuildService(ctx, cfg) | ||
if err != nil { | ||
return errors.Wrap(err, "error building a service") | ||
} | ||
defer cleanup() | ||
|
||
addMyRegistration(ctx, service) // todo remove | ||
|
||
return service.Run(ctx) | ||
|
||
} | ||
|
||
func addMyRegistration(ctx context.Context, service di.Service) { | ||
nsec := os.Getenv("NSEC") | ||
_, value, err := nip19.Decode(nsec) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
secretKey := value.(string) | ||
publicKeyString, err := nostr.GetPublicKey(secretKey) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
publicKey, err := domain.NewPublicKey(publicKeyString) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
relayAddress, err := domain.NewRelayAddress("wss://relay.damus.io") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
libEvent := nostr.Event{ | ||
CreatedAt: nostr.Now(), | ||
Kind: 12345, | ||
Tags: nostr.Tags{}, | ||
Content: fmt.Sprintf(` | ||
{ | ||
"publicKeys": [ | ||
{ | ||
"publicKey": "%s", | ||
"relays": [ | ||
{ | ||
"address": "%s" | ||
} | ||
] | ||
} | ||
], | ||
"locale": "%s", | ||
"apnsToken": "%s" | ||
} | ||
`, | ||
publicKey.Hex(), | ||
relayAddress.String(), | ||
fixtures.SomeString(), | ||
fixtures.SomeString()), | ||
} | ||
|
||
err = libEvent.Sign(secretKey) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
event, err := domain.NewEvent(libEvent) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
registration, err := domain.NewRegistrationFromEvent(event) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
cmd := app.NewSaveRegistration(registration) | ||
err = service.App().Commands.SaveRegistration.Handle(ctx, cmd) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package internal | ||
|
||
type Set[T comparable] struct { | ||
values map[T]struct{} | ||
} | ||
|
||
func NewEmptySet[T comparable]() *Set[T] { | ||
return &Set[T]{ | ||
values: make(map[T]struct{}), | ||
} | ||
} | ||
|
||
func NewSet[T comparable](values []T) *Set[T] { | ||
v := NewEmptySet[T]() | ||
for _, value := range values { | ||
v.Put(value) | ||
} | ||
return v | ||
} | ||
|
||
func (s *Set[T]) Contains(v T) bool { | ||
_, ok := s.values[v] | ||
return ok | ||
} | ||
|
||
func (s *Set[T]) Put(v T) { | ||
s.values[v] = struct{}{} | ||
} | ||
|
||
func (s *Set[T]) Clear() { | ||
s.values = make(map[T]struct{}) | ||
} | ||
|
||
func (s *Set[T]) Delete(v T) { | ||
delete(s.values, v) | ||
} | ||
|
||
func (s *Set[T]) List() []T { | ||
var result []T | ||
for v := range s.values { | ||
result = append(result, v) | ||
} | ||
return result | ||
} | ||
|
||
func (s *Set[T]) Len() int { | ||
return len(s.values) | ||
} |
Oops, something went wrong.