refactor: split go-pkg

This commit is contained in:
xuu
2023-07-12 17:35:02 -06:00
parent d67d768c1e
commit 0f665d3484
80 changed files with 785 additions and 3993 deletions

37
app/gql/common.graphqls Normal file
View File

@@ -0,0 +1,37 @@
scalar Time
scalar Map
type Connection @goModel(model: "go.sour.is/pkg/gql.Connection") {
paging: PageInfo!
edges: [Edge!]!
}
input PageInput @goModel(model: "go.sour.is/pkg/gql.PageInput") {
after: Int = 0
before: Int
count: Int = 30
}
type PageInfo @goModel(model: "go.sour.is/pkg/gql.PageInfo") {
next: Boolean!
prev: Boolean!
begin: Int!
end: Int!
}
interface Edge @goModel(model: "go.sour.is/pkg/gql.Edge"){
id: ID!
}
directive @goModel(
model: String
models: [String!]
) on OBJECT | INPUT_OBJECT | SCALAR | ENUM | INTERFACE | UNION
directive @goField(
forceResolver: Boolean
name: String
) on INPUT_FIELD_DEFINITION | FIELD_DEFINITION
directive @goTag(
key: String!
value: String
) on INPUT_FIELD_DEFINITION | FIELD_DEFINITION

View File

@@ -4,12 +4,13 @@ import (
"context"
"github.com/99designs/gqlgen/graphql"
"go.sour.is/pkg/gql"
"go.sour.is/pkg/gql/resolver"
"go.sour.is/ev/app/msgbus"
"go.sour.is/ev/app/salty"
"go.sour.is/ev/internal/graph/generated"
"go.sour.is/ev/pkg/es"
"go.sour.is/ev/pkg/gql"
"go.sour.is/ev/pkg/gql/resolver"
)
type Resolver struct {

View File

@@ -14,24 +14,23 @@ import (
"time"
"github.com/gorilla/websocket"
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/metric/instrument/syncint64"
"go.opentelemetry.io/otel/metric/unit"
"go.opentelemetry.io/otel/metric"
"go.uber.org/multierr"
"go.sour.is/ev"
"go.sour.is/ev/internal/lg"
"go.sour.is/ev/pkg/es/event"
"go.sour.is/ev/pkg/gql"
"go.sour.is/ev/pkg/event"
"go.sour.is/pkg/gql"
"go.sour.is/pkg/lg"
)
type service struct {
es *ev.EventStore
m_gql_posts syncint64.Counter
m_gql_post_added syncint64.Counter
m_gql_post_added_event syncint64.Counter
m_req_time syncint64.Histogram
m_gql_posts metric.Int64Counter
m_gql_post_added metric.Int64Counter
m_gql_post_added_event metric.Int64Counter
m_req_time metric.Int64Histogram
}
type MsgbusResolver interface {
@@ -56,24 +55,24 @@ func New(ctx context.Context, es *ev.EventStore) (*service, error) {
svc := &service{es: es}
var err, errs error
svc.m_gql_posts, err = m.SyncInt64().Counter("msgbus_posts",
instrument.WithDescription("msgbus graphql posts requests"),
svc.m_gql_posts, err = m.Int64Counter("msgbus_posts",
metric.WithDescription("msgbus graphql posts requests"),
)
errs = multierr.Append(errs, err)
svc.m_gql_post_added, err = m.SyncInt64().Counter("msgbus_post_added",
instrument.WithDescription("msgbus graphql post added subcription requests"),
svc.m_gql_post_added, err = m.Int64Counter("msgbus_post_added",
metric.WithDescription("msgbus graphql post added subcription requests"),
)
errs = multierr.Append(errs, err)
svc.m_gql_post_added_event, err = m.SyncInt64().Counter("msgbus_post_event",
instrument.WithDescription("msgbus graphql post added subscription events"),
svc.m_gql_post_added_event, err = m.Int64Counter("msgbus_post_event",
metric.WithDescription("msgbus graphql post added subscription events"),
)
errs = multierr.Append(errs, err)
svc.m_req_time, err = m.SyncInt64().Histogram("msgbus_request_time",
instrument.WithDescription("msgbus graphql post added subscription events"),
instrument.WithUnit(unit.Unit("ns")),
svc.m_req_time, err = m.Int64Histogram("msgbus_request_time",
metric.WithDescription("msgbus graphql post added subscription events"),
metric.WithUnit("ns"),
)
errs = multierr.Append(errs, err)

View File

@@ -5,7 +5,7 @@ import (
"github.com/tj/go-semver"
"go.sour.is/ev/pkg/es/event"
"go.sour.is/ev/pkg/event"
)
type Info struct {

View File

@@ -7,8 +7,9 @@ import (
"time"
"github.com/keys-pub/keys/json"
"go.sour.is/ev/pkg/es/event"
"go.sour.is/ev/pkg/set"
"go.sour.is/pkg/set"
"go.sour.is/ev/pkg/event"
)
type Time time.Time

View File

@@ -9,8 +9,8 @@ import (
"time"
"github.com/oklog/ulid"
"go.sour.is/ev/pkg/es/event"
"go.sour.is/ev/pkg/set"
"go.sour.is/ev/pkg/event"
"go.sour.is/pkg/set"
)
type Request struct {

View File

@@ -19,10 +19,10 @@ import (
"github.com/oklog/ulid/v2"
contentnegotiation "gitlab.com/jamietanna/content-negotiation-go"
"go.opentelemetry.io/otel/attribute"
"go.sour.is/pkg/lg"
"go.sour.is/ev"
"go.sour.is/ev/internal/lg"
"go.sour.is/ev/pkg/es/event"
"go.sour.is/ev/pkg/event"
)
var (
@@ -656,7 +656,6 @@ func fnOrderByPeer(rq *Request) listPeer {
v := peers[i]
sort.Sort(v.Results)
v.Name = v.Results[0].Name
v.Country = v.Results[0].Country
v.Latency = v.Results[0].Latency

View File

@@ -10,9 +10,9 @@ import (
"time"
"go.sour.is/ev"
"go.sour.is/ev/internal/lg"
"go.sour.is/ev/pkg/es/event"
"go.sour.is/ev/pkg/set"
"go.sour.is/ev/pkg/event"
"go.sour.is/pkg/lg"
"go.sour.is/pkg/set"
)
// RefreshJob retrieves peer info from the peerdb

View File

@@ -6,11 +6,12 @@ import (
"sync/atomic"
"time"
"go.sour.is/ev"
"go.sour.is/ev/internal/lg"
"go.sour.is/ev/pkg/es/event"
"go.sour.is/ev/pkg/locker"
"go.sour.is/pkg/lg"
"go.sour.is/pkg/locker"
"go.uber.org/multierr"
"go.sour.is/ev"
"go.sour.is/ev/pkg/event"
)
const (

View File

@@ -11,10 +11,9 @@ import (
"path/filepath"
"strings"
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/metric/instrument/syncint64"
"go.sour.is/ev/internal/lg"
"go.sour.is/ev/pkg/authreq"
"go.opentelemetry.io/otel/metric"
"go.sour.is/pkg/authreq"
"go.sour.is/pkg/lg"
"go.uber.org/multierr"
)
@@ -30,9 +29,9 @@ func WithBlobStore(path string) *withBlobStore {
type withBlobStore struct {
path string
m_get_blob syncint64.Counter
m_put_blob syncint64.Counter
m_delete_blob syncint64.Counter
m_get_blob metric.Int64Counter
m_put_blob metric.Int64Counter
m_delete_blob metric.Int64Counter
}
func (o *withBlobStore) ApplySalty(s *service) {}
@@ -49,18 +48,18 @@ func (o *withBlobStore) Setup(ctx context.Context) error {
}
m := lg.Meter(ctx)
o.m_get_blob, err = m.SyncInt64().Counter("salty_get_blob",
instrument.WithDescription("salty get blob called"),
o.m_get_blob, err = m.Int64Counter("salty_get_blob",
metric.WithDescription("salty get blob called"),
)
errs = multierr.Append(errs, err)
o.m_put_blob, err = m.SyncInt64().Counter("salty_put_blob",
instrument.WithDescription("salty put blob called"),
o.m_put_blob, err = m.Int64Counter("salty_put_blob",
metric.WithDescription("salty put blob called"),
)
errs = multierr.Append(errs, err)
o.m_delete_blob, err = m.SyncInt64().Counter("salty_delete_blob",
instrument.WithDescription("salty delete blob called"),
o.m_delete_blob, err = m.Int64Counter("salty_delete_blob",
metric.WithDescription("salty delete blob called"),
)
errs = multierr.Append(errs, err)

View File

@@ -11,7 +11,7 @@ import (
"github.com/keys-pub/keys"
"go.sour.is/ev/internal/lg"
"go.sour.is/pkg/lg"
)
// Config represents a Salty Config for a User which at a minimum is required

View File

@@ -12,8 +12,8 @@ import (
"github.com/keys-pub/keys"
"github.com/oklog/ulid/v2"
"go.sour.is/ev/pkg/es/event"
"go.sour.is/ev/pkg/gql"
"go.sour.is/ev/pkg/event"
"go.sour.is/pkg/gql"
)
type SaltyUser struct {

View File

@@ -14,15 +14,13 @@ import (
"github.com/keys-pub/keys"
"go.mills.io/saltyim"
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/metric/instrument/syncint64"
"go.opentelemetry.io/otel/metric/unit"
"go.opentelemetry.io/otel/metric"
"go.uber.org/multierr"
"go.sour.is/ev"
"go.sour.is/ev/internal/lg"
"go.sour.is/ev/pkg/es/event"
"go.sour.is/ev/pkg/gql"
"go.sour.is/ev/pkg/event"
"go.sour.is/pkg/gql"
"go.sour.is/pkg/lg"
)
type DNSResolver interface {
@@ -34,13 +32,13 @@ type service struct {
es *ev.EventStore
dns DNSResolver
m_create_user syncint64.Counter
m_get_user syncint64.Counter
m_api_ping syncint64.Counter
m_api_register syncint64.Counter
m_api_lookup syncint64.Counter
m_api_send syncint64.Counter
m_req_time syncint64.Histogram
m_create_user metric.Int64Counter
m_get_user metric.Int64Counter
m_api_ping metric.Int64Counter
m_api_register metric.Int64Counter
m_api_lookup metric.Int64Counter
m_api_send metric.Int64Counter
m_req_time metric.Int64Histogram
opts []Option
}
@@ -93,39 +91,39 @@ func New(ctx context.Context, es *ev.EventStore, opts ...Option) (*service, erro
}
var err, errs error
svc.m_create_user, err = m.SyncInt64().Counter("salty_create_user",
instrument.WithDescription("salty create user graphql called"),
svc.m_create_user, err = m.Int64Counter("salty_create_user",
metric.WithDescription("salty create user graphql called"),
)
errs = multierr.Append(errs, err)
svc.m_get_user, err = m.SyncInt64().Counter("salty_get_user",
instrument.WithDescription("salty get user graphql called"),
svc.m_get_user, err = m.Int64Counter("salty_get_user",
metric.WithDescription("salty get user graphql called"),
)
errs = multierr.Append(errs, err)
svc.m_api_ping, err = m.SyncInt64().Counter("salty_api_ping",
instrument.WithDescription("salty api ping called"),
svc.m_api_ping, err = m.Int64Counter("salty_api_ping",
metric.WithDescription("salty api ping called"),
)
errs = multierr.Append(errs, err)
svc.m_api_register, err = m.SyncInt64().Counter("salty_api_register",
instrument.WithDescription("salty api register"),
svc.m_api_register, err = m.Int64Counter("salty_api_register",
metric.WithDescription("salty api register"),
)
errs = multierr.Append(errs, err)
svc.m_api_lookup, err = m.SyncInt64().Counter("salty_api_lookup",
instrument.WithDescription("salty api ping lookup"),
svc.m_api_lookup, err = m.Int64Counter("salty_api_lookup",
metric.WithDescription("salty api ping lookup"),
)
errs = multierr.Append(errs, err)
svc.m_api_send, err = m.SyncInt64().Counter("salty_api_send",
instrument.WithDescription("salty api ping send"),
svc.m_api_send, err = m.Int64Counter("salty_api_send",
metric.WithDescription("salty api ping send"),
)
errs = multierr.Append(errs, err)
svc.m_req_time, err = m.SyncInt64().Histogram("salty_request_time",
instrument.WithDescription("histogram of requests"),
instrument.WithUnit(unit.Unit("ns")),
svc.m_req_time, err = m.Int64Histogram("salty_request_time",
metric.WithDescription("histogram of requests"),
metric.WithUnit("ns"),
)
errs = multierr.Append(errs, err)

View File

@@ -1,7 +1,7 @@
package webfinger
import (
"go.sour.is/ev/pkg/es/event"
"go.sour.is/ev/pkg/event"
)
type SubjectSet struct {

View File

@@ -8,10 +8,11 @@ import (
"hash/fnv"
"sort"
"go.sour.is/ev/pkg/es/event"
"go.sour.is/ev/pkg/set"
"go.sour.is/ev/pkg/slice"
"go.sour.is/pkg/set"
"go.sour.is/pkg/slice"
"gopkg.in/yaml.v3"
"go.sour.is/ev/pkg/event"
)
func StreamID(subject string) string {

View File

@@ -12,14 +12,14 @@ import (
jwt "github.com/golang-jwt/jwt/v4"
"github.com/matryer/is"
"go.sour.is/ev"
"go.uber.org/multierr"
"go.sour.is/ev"
"go.sour.is/ev/app/webfinger"
memstore "go.sour.is/ev/pkg/es/driver/mem-store"
"go.sour.is/ev/pkg/es/driver/projecter"
"go.sour.is/ev/pkg/es/driver/streamer"
"go.sour.is/ev/pkg/es/event"
memstore "go.sour.is/ev/pkg/driver/mem-store"
"go.sour.is/ev/pkg/driver/projecter"
"go.sour.is/ev/pkg/driver/streamer"
"go.sour.is/ev/pkg/event"
)
func TestParseJRD(t *testing.T) {

View File

@@ -20,10 +20,11 @@ import (
"strings"
"github.com/golang-jwt/jwt/v4"
"go.sour.is/pkg/lg"
"go.sour.is/pkg/set"
"go.sour.is/ev"
"go.sour.is/ev/internal/lg"
"go.sour.is/ev/pkg/es/event"
"go.sour.is/ev/pkg/set"
"go.sour.is/ev/pkg/event"
)
var (