removed dependencies

This commit is contained in:
2023-08-13 00:09:57 +03:00
parent dc0c660021
commit 85d1191dd9
15 changed files with 117 additions and 275 deletions

View File

@@ -72,7 +72,7 @@ func (c *client) Done() <-chan struct{} {
}
func runner(ctx context.Context, st storage.Storage, req *pb.AddPackageReq) {
modules, err := getGoModule(ctx, req.Url.Value)
modules, err := getGoModule(ctx, req.Url)
if err != nil {
logger.Error(ctx, err)
return

View File

@@ -3,12 +3,12 @@ package client_git
import (
"context"
"database/sql"
"embed"
"fmt"
pb "go.unistack.org/unistack-org/pkgdash/proto"
"go.unistack.org/unistack-org/pkgdash/storage"
"go.unistack.org/unistack-org/pkgdash/storage/postgres"
"go.unistack.org/unistack-org/pkgdash/storage/sqlite"
"google.golang.org/protobuf/types/known/wrapperspb"
"testing"
)
@@ -23,11 +23,8 @@ func TestClientPG(t *testing.T) {
t.Fatal(err)
}
st, err := postgres.NewStorage(conn)
if err != nil {
t.Fatal(err)
}
fucntion := postgres.NewStorage()
st := fucntion(conn, embed.FS{})
s, ok := st.(storage.Storage)
if !ok {
t.Fatal("typecast error")
@@ -40,8 +37,8 @@ func TestClientPG(t *testing.T) {
ch := cli.Run(ctx, s)
data := &pb.AddPackageReq{
Name: wrapperspb.String("test"),
Url: wrapperspb.String("https://github.com/dantedenis/service_history.git"),
Name: "test",
Url: "https://github.com/dantedenis/service_history.git",
}
ch <- data
@@ -59,11 +56,8 @@ func TestClientLite(t *testing.T) {
t.Fatal(err)
}
st, err := sqlite.NewStorage(conn)
if err != nil {
t.Fatal(err)
}
function := sqlite.NewStorage()
st := function(conn, embed.FS{})
s, ok := st.(storage.Storage)
if !ok {
t.Fatal("typecast error")
@@ -76,8 +70,8 @@ func TestClientLite(t *testing.T) {
ch := cli.Run(ctx, s)
data := &pb.AddPackageReq{
Name: wrapperspb.String("test"),
Url: wrapperspb.String("https://github.com/dantedenis/service_history.git"),
Name: "test",
Url: "https://github.com/dantedenis/service_history.git",
}
ch <- data

View File

@@ -1,9 +0,0 @@
package service
import (
service "go.unistack.org/cms-service"
)
func init() {
service.RegisterService("pkgdash", NewService)
}

View File

@@ -2,8 +2,8 @@ package service
import (
"context"
cmsstorage "go.unistack.org/cms-service/storage" // TODO
httpsrv "go.unistack.org/micro-server-http/v3"
"database/sql"
httpsrv "go.unistack.org/micro-server-http/v4"
"go.unistack.org/micro/v4"
"go.unistack.org/micro/v4/config"
microcfg "go.unistack.org/micro/v4/config"
@@ -16,6 +16,8 @@ import (
pb "go.unistack.org/unistack-org/pkgdash/proto"
"go.unistack.org/unistack-org/pkgdash/service/client_git"
"go.unistack.org/unistack-org/pkgdash/storage"
"net/url"
"strings"
)
func NewService(ctx context.Context) (micro.Service, error) {
@@ -72,45 +74,60 @@ func NewService(ctx context.Context) (micro.Service, error) {
)
return svc.Init(micro.Logger(log))
}),
micro.BeforeStart(func(_ context.Context) error { // TODO
micro.BeforeStart(func(ctx context.Context) error {
var connstr string
if v, ok := cfg.StorageDSN[cfg.App.Name]; ok {
connstr = v
} else if v, ok = cfg.StorageDSN["all"]; ok {
connstr = v
}
scheme, dsn, err := cmsstorage.StorageOptions(connstr)
scheme, dsn, err := storageOptions(connstr)
if err != nil {
return err
}
db, dbok := cmsstorage.FromContext(svc.Options().Context)
if !dbok {
db, err = cmsstorage.NewStorage(scheme, dsn)
if err != nil {
return err
}
}
store, err := storage.NewStorage(scheme, db)
conn, err := connectDataBase(scheme, dsn)
if err != nil {
return err
}
return svc.Init(micro.Context(cmsstorage.InterfaceNewContext(svc.Options().Context, store)))
store, err := storage.NewStorage(scheme, conn)
if err != nil {
return err
}
ctx = storage.InContext(ctx, store)
return svc.Init(micro.Context(ctx))
}),
); err != nil {
return nil, err
}
//mux := http.NewServeMux()
//mux.HandleFunc("/listPackage", handler.Methods(http.MethodGet, h.ListPackage))
//mux.HandleFunc("/updatePackage", handler.Methods(http.MethodPost, h.UpdatePackage))
//mux.HandleFunc("/addComment", handler.Methods(http.MethodPut, h.AddComment))
//mux.HandleFunc("/addPackage", handler.Methods(http.MethodPost, h.AddPackage))
//mux.HandleFunc("/getModule", handler.Methods(http.MethodGet, h.GetModule))
if err := pb.RegisterPkgdashServiceServer(mgsrv, h); err != nil {
logger.Fatalf(ctx, "failed to register handler: %v", err)
}
return svc, nil
}
func storageOptions(dsn string) (string, string, error) {
u, err := url.Parse(dsn)
if err != nil {
return "", "", err
}
scheme := u.Scheme
if idx := strings.Index(u.Scheme, "+"); idx > 0 {
scheme = u.Scheme[:idx]
u.Scheme = u.Scheme[idx+1:]
}
return scheme, u.String(), nil
}
func connectDataBase(driverName, dsn string) (*sql.DB, error) {
conn, err := sql.Open(driverName, dsn)
if err != nil {
return nil, err
}
if err = conn.Ping(); err != nil {
return nil, err
}
return conn, err
}