mirror of
https://github.com/aykhans/slash-e.git
synced 2025-07-04 20:28:00 +00:00
chore: retire unused service
This commit is contained in:
@ -1,51 +0,0 @@
|
||||
package metric
|
||||
|
||||
import (
|
||||
"github.com/posthog/posthog-go"
|
||||
|
||||
"github.com/yourselfhosted/slash/server/profile"
|
||||
)
|
||||
|
||||
const (
|
||||
PostHogAPIKey = "phc_YFEi1aqUBW9sX2KDzdvMtK43DNu0mkeoKMKc0EQum2t"
|
||||
)
|
||||
|
||||
var (
|
||||
client *MetricClient
|
||||
)
|
||||
|
||||
type MetricClient struct {
|
||||
workspaceID string
|
||||
profile *profile.Profile
|
||||
phClient *posthog.Client
|
||||
}
|
||||
|
||||
func NewMetricClient(workspaceID string, profile profile.Profile) (*MetricClient, error) {
|
||||
phClient, err := posthog.NewWithConfig(PostHogAPIKey, posthog.Config{
|
||||
Endpoint: "https://app.posthog.com",
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client = &MetricClient{
|
||||
workspaceID: workspaceID,
|
||||
profile: &profile,
|
||||
phClient: &phClient,
|
||||
}
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func Enqueue(event string) {
|
||||
if client == nil {
|
||||
return
|
||||
}
|
||||
if client.profile.Mode != "prod" {
|
||||
return
|
||||
}
|
||||
|
||||
// nolint
|
||||
(*client.phClient).Enqueue(posthog.Capture{
|
||||
DistinctId: `slash-` + client.workspaceID,
|
||||
Event: event,
|
||||
})
|
||||
}
|
@ -24,8 +24,6 @@ type Profile struct {
|
||||
Driver string
|
||||
// Version is the current version of server.
|
||||
Version string
|
||||
// Metric indicate the metric collection is enabled or not.
|
||||
Metric bool
|
||||
}
|
||||
|
||||
func (p *Profile) IsDev() bool {
|
||||
|
@ -17,7 +17,6 @@ import (
|
||||
"github.com/yourselfhosted/slash/plugin/idp/oauth2"
|
||||
v1pb "github.com/yourselfhosted/slash/proto/gen/api/v1"
|
||||
storepb "github.com/yourselfhosted/slash/proto/gen/store"
|
||||
"github.com/yourselfhosted/slash/server/metric"
|
||||
"github.com/yourselfhosted/slash/server/service/license"
|
||||
"github.com/yourselfhosted/slash/store"
|
||||
)
|
||||
@ -53,7 +52,6 @@ func (s *APIV1Service) SignIn(ctx context.Context, request *v1pb.SignInRequest)
|
||||
if err := s.doSignIn(ctx, user, time.Now().Add(AccessTokenDuration)); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, fmt.Sprintf("failed to sign in, err: %s", err))
|
||||
}
|
||||
metric.Enqueue("user sign in")
|
||||
return convertUserFromStore(user), nil
|
||||
}
|
||||
|
||||
@ -181,7 +179,6 @@ func (s *APIV1Service) SignUp(ctx context.Context, request *v1pb.SignUpRequest)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, fmt.Sprintf("failed to create user, err: %s", err))
|
||||
}
|
||||
metric.Enqueue("user sign up")
|
||||
if err := s.doSignIn(ctx, user, time.Now().Add(AccessTokenDuration)); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, fmt.Sprintf("failed to sign in, err: %s", err))
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
|
||||
v1pb "github.com/yourselfhosted/slash/proto/gen/api/v1"
|
||||
storepb "github.com/yourselfhosted/slash/proto/gen/store"
|
||||
"github.com/yourselfhosted/slash/server/metric"
|
||||
"github.com/yourselfhosted/slash/server/service/license"
|
||||
"github.com/yourselfhosted/slash/store"
|
||||
)
|
||||
@ -131,7 +130,6 @@ func (s *APIV1Service) CreateCollection(ctx context.Context, request *v1pb.Creat
|
||||
return nil, status.Errorf(codes.Internal, "failed to create collection, err: %v", err)
|
||||
}
|
||||
|
||||
metric.Enqueue("collection create")
|
||||
return convertCollectionFromStore(collection), nil
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,6 @@ import (
|
||||
|
||||
v1pb "github.com/yourselfhosted/slash/proto/gen/api/v1"
|
||||
storepb "github.com/yourselfhosted/slash/proto/gen/store"
|
||||
"github.com/yourselfhosted/slash/server/metric"
|
||||
"github.com/yourselfhosted/slash/server/service/license"
|
||||
"github.com/yourselfhosted/slash/store"
|
||||
)
|
||||
@ -175,7 +174,6 @@ func (s *APIV1Service) CreateShortcut(ctx context.Context, request *v1pb.CreateS
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to convert shortcut, err: %v", err)
|
||||
}
|
||||
metric.Enqueue("shortcut create")
|
||||
return composedShortcut, nil
|
||||
}
|
||||
|
||||
@ -322,7 +320,6 @@ func (s *APIV1Service) GetShortcutAnalytics(ctx context.Context, request *v1pb.G
|
||||
browserMap[browserName]++
|
||||
}
|
||||
|
||||
metric.Enqueue("shortcut analytics")
|
||||
response := &v1pb.GetShortcutAnalyticsResponse{
|
||||
References: mapToAnalyticsSlice(referenceMap),
|
||||
Devices: mapToAnalyticsSlice(deviceMap),
|
||||
|
@ -17,7 +17,6 @@ import (
|
||||
"github.com/yourselfhosted/slash/internal/util"
|
||||
storepb "github.com/yourselfhosted/slash/proto/gen/store"
|
||||
"github.com/yourselfhosted/slash/server/common"
|
||||
"github.com/yourselfhosted/slash/server/metric"
|
||||
"github.com/yourselfhosted/slash/server/profile"
|
||||
"github.com/yourselfhosted/slash/store"
|
||||
)
|
||||
@ -96,7 +95,6 @@ func (s *FrontendService) registerRoutes(e *echo.Echo) {
|
||||
if err := s.createShortcutViewActivity(ctx, c.Request(), shortcut); err != nil {
|
||||
slog.Warn("failed to create shortcut view activity", slog.String("error", err.Error()))
|
||||
}
|
||||
metric.Enqueue("shortcut view")
|
||||
|
||||
// Inject shortcut metadata into `index.html`.
|
||||
indexHTML := strings.ReplaceAll(rawIndexHTML, headerMetadataPlaceholder, generateShortcutMetadata(shortcut).String())
|
||||
@ -114,7 +112,6 @@ func (s *FrontendService) registerRoutes(e *echo.Echo) {
|
||||
return c.HTML(http.StatusOK, rawIndexHTML)
|
||||
}
|
||||
|
||||
metric.Enqueue("collection view")
|
||||
// Inject collection metadata into `index.html`.
|
||||
indexHTML := strings.ReplaceAll(rawIndexHTML, headerMetadataPlaceholder, generateCollectionMetadata(collection).String())
|
||||
return c.HTML(http.StatusOK, indexHTML)
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
|
||||
storepb "github.com/yourselfhosted/slash/proto/gen/store"
|
||||
"github.com/yourselfhosted/slash/server/metric"
|
||||
"github.com/yourselfhosted/slash/server/profile"
|
||||
apiv1 "github.com/yourselfhosted/slash/server/route/api/v1"
|
||||
"github.com/yourselfhosted/slash/server/route/frontend"
|
||||
@ -93,7 +92,6 @@ func (s *Server) Start(ctx context.Context) error {
|
||||
}
|
||||
}()
|
||||
|
||||
metric.Enqueue("server start")
|
||||
return s.e.Start(fmt.Sprintf(":%d", s.Profile.Port))
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user