Skip to content

Commit

Permalink
Merge pull request #52 from ettec/golang-updates
Browse files Browse the repository at this point in the history
updated all golang services
  • Loading branch information
ettec authored Nov 28, 2023
2 parents 61be95e + 6263b40 commit fca1aad
Show file tree
Hide file tree
Showing 63 changed files with 865 additions and 745 deletions.
2 changes: 1 addition & 1 deletion go/authorization-service/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
github.com/envoyproxy/go-control-plane v0.9.5
github.com/ettec/otp-common v1.4.0
github.com/ettec/otp-common v1.4.2
github.com/gogo/googleapis v1.4.0
github.com/golang/protobuf v1.4.2
github.com/google/uuid v1.1.1
Expand Down
6 changes: 6 additions & 0 deletions go/authorization-service/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ github.com/ettec/otp-common v1.3.1-0.20231121170433-6f1dd05c001e h1:oSJ6u7EUItXe
github.com/ettec/otp-common v1.3.1-0.20231121170433-6f1dd05c001e/go.mod h1:68PDrJp1ccRawgvPg0vYmSDPUi03ZCtBp4YJOJzeUjc=
github.com/ettec/otp-common v1.4.0 h1:cjwwHtqsP9Kwr08DSN6yqhcR3HnEqhtCy795tkSRRZQ=
github.com/ettec/otp-common v1.4.0/go.mod h1:68PDrJp1ccRawgvPg0vYmSDPUi03ZCtBp4YJOJzeUjc=
github.com/ettec/otp-common v1.4.1-0.20231128151006-7b41d465cd74 h1:R9dxpl1H76ImUpTiUPAqEzS59zug785h9zw+fqgNgmk=
github.com/ettec/otp-common v1.4.1-0.20231128151006-7b41d465cd74/go.mod h1:68PDrJp1ccRawgvPg0vYmSDPUi03ZCtBp4YJOJzeUjc=
github.com/ettec/otp-common v1.4.1 h1:Im44hSM83Jy56BnurMw/ZJwtwTlnzUNlCdTFzFTn65o=
github.com/ettec/otp-common v1.4.1/go.mod h1:68PDrJp1ccRawgvPg0vYmSDPUi03ZCtBp4YJOJzeUjc=
github.com/ettec/otp-common v1.4.2 h1:qmgPXctGWyHAwsyz0WnSgRFvhll8OGF4sfZkSZi+1tA=
github.com/ettec/otp-common v1.4.2/go.mod h1:68PDrJp1ccRawgvPg0vYmSDPUi03ZCtBp4YJOJzeUjc=
github.com/gogo/googleapis v1.4.0 h1:zgVt4UpGxcqVOw97aRGxT4svlcmdK35fynLNctY32zI=
github.com/gogo/googleapis v1.4.0/go.mod h1:5YRNX2z1oM5gXdAkurHa942MDgEJyk02w4OecKY87+c=
github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
Expand Down
62 changes: 41 additions & 21 deletions go/authorization-service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import (
"google.golang.org/genproto/googleapis/rpc/status"
"google.golang.org/grpc"
"log"
"log/slog"
"net"
"os"
"os/signal"
"strings"
"syscall"
)

var logFlags = log.Ltime | log.Lshortfile
var errLog = log.New(os.Stderr, "", logFlags)

type user struct {
id string
desk string
Expand All @@ -34,7 +34,7 @@ type authService struct {
users map[string]user
}

func (a authService) Login(_ context.Context, params *loginservice.LoginParams) (*loginservice.Token, error) {
func (a *authService) Login(_ context.Context, params *loginservice.LoginParams) (*loginservice.Token, error) {

log.Printf("logging in")

Expand All @@ -53,7 +53,7 @@ func (a *authService) Check(_ context.Context, req *auth.CheckRequest) (*auth.Ch
path, ok := req.Attributes.Request.Http.Headers[":path"]

if ok && strings.HasPrefix(path, "/loginservice.LoginService") {
log.Printf("permitted login for path:%v", path)
slog.Info("permitted login for path", "path", path)
return newOkResponse(), nil
}

Expand Down Expand Up @@ -147,8 +147,7 @@ const (

func main() {

log.SetOutput(os.Stdout)
log.SetFlags(logFlags)
slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{AddSource: true})))

dbString := bootstrap.GetEnvVar(DatabaseConnectionString)
dbDriverName := bootstrap.GetEnvVar(DatabaseDriverName)
Expand All @@ -159,13 +158,13 @@ func main() {
}
defer func() {
if err := db.Close(); err != nil {
errLog.Printf("error when closing database connection: %v", err)
slog.Error("error when closing database connection", "error", err)
}
}()

err = db.Ping()
if err != nil {
log.Panic("could not establish a connection with the database: ", err)
log.Panicf("could not establish a connection with the database: %v", err)
}

r, err := db.Query("SELECT id, desk, permissionflags FROM users.users")
Expand All @@ -184,24 +183,35 @@ func main() {
users[u.id] = u
}

log.Printf("loaded %v users", len(users))
slog.Info("loaded users", "userCount", len(users))

authServer := &authService{users: users}

go func() {

loginPort := "50551"
lis, err := net.Listen("tcp", ":"+loginPort)
if err != nil {
log.Panicf("failed to listen: %v", err)
}
log.Printf("listening on %s", lis.Addr())

grpcServer := grpc.NewServer()
loginservice.RegisterLoginServiceServer(grpcServer, authServer)

log.Print("starting login server of port:", loginPort)
if err := grpcServer.Serve(lis); err != nil {
log.Fatalf("Failed to start server: %v", err)
slog.Info("authentication server listening", "listenAddress", lis.Addr())

authenticationGrpcServer := grpc.NewServer()
loginservice.RegisterLoginServiceServer(authenticationGrpcServer, authServer)

sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh,
syscall.SIGKILL,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
<-sigCh
authenticationGrpcServer.GracefulStop()
}()

slog.Info("starting authentication server", "port", loginPort)
if err := authenticationGrpcServer.Serve(lis); err != nil {
log.Panicf("Failed to start authentication server: %v", err)
}
}()

Expand All @@ -210,15 +220,25 @@ func main() {
if err != nil {
log.Panicf("failed to listen: %v", err)
}
log.Printf("listening on %s", lis.Addr())
slog.Info("authorisation server listening", "listenAddress", lis.Addr())

grpcServer := grpc.NewServer()

auth.RegisterAuthorizationServer(grpcServer, authServer)

log.Print("starting authorization server of port:", authPort)
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh,
syscall.SIGKILL,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
<-sigCh
grpcServer.GracefulStop()
}()

slog.Info("starting authorization server", "port", authPort)
if err := grpcServer.Serve(lis); err != nil {
log.Panicf("Failed to start server: %v", err)
log.Panicf("Failed to start authorization server: %v", err)
}

}
2 changes: 1 addition & 1 deletion go/client-config-service/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/ettech/open-trading-platform/go/client-config-service
go 1.21

require (
github.com/ettec/otp-common v1.4.0
github.com/ettec/otp-common v1.4.2
github.com/golang/protobuf v1.4.2
github.com/lib/pq v1.2.0
google.golang.org/grpc v1.25.1
Expand Down
6 changes: 6 additions & 0 deletions go/client-config-service/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ github.com/ettec/otp-common v1.3.1-0.20231121170433-6f1dd05c001e h1:oSJ6u7EUItXe
github.com/ettec/otp-common v1.3.1-0.20231121170433-6f1dd05c001e/go.mod h1:68PDrJp1ccRawgvPg0vYmSDPUi03ZCtBp4YJOJzeUjc=
github.com/ettec/otp-common v1.4.0 h1:cjwwHtqsP9Kwr08DSN6yqhcR3HnEqhtCy795tkSRRZQ=
github.com/ettec/otp-common v1.4.0/go.mod h1:68PDrJp1ccRawgvPg0vYmSDPUi03ZCtBp4YJOJzeUjc=
github.com/ettec/otp-common v1.4.1-0.20231128151006-7b41d465cd74 h1:R9dxpl1H76ImUpTiUPAqEzS59zug785h9zw+fqgNgmk=
github.com/ettec/otp-common v1.4.1-0.20231128151006-7b41d465cd74/go.mod h1:68PDrJp1ccRawgvPg0vYmSDPUi03ZCtBp4YJOJzeUjc=
github.com/ettec/otp-common v1.4.1 h1:Im44hSM83Jy56BnurMw/ZJwtwTlnzUNlCdTFzFTn65o=
github.com/ettec/otp-common v1.4.1/go.mod h1:68PDrJp1ccRawgvPg0vYmSDPUi03ZCtBp4YJOJzeUjc=
github.com/ettec/otp-common v1.4.2 h1:qmgPXctGWyHAwsyz0WnSgRFvhll8OGF4sfZkSZi+1tA=
github.com/ettec/otp-common v1.4.2/go.mod h1:68PDrJp1ccRawgvPg0vYmSDPUi03ZCtBp4YJOJzeUjc=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
Expand Down
31 changes: 18 additions & 13 deletions go/client-config-service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
"log"
"log/slog"
"net"
"os"
"os/signal"
"syscall"
)

var logFlags = log.Ltime|log.Lshortfile
var errLog = log.New(os.Stderr, "", logFlags)

type service struct {
db *sql.DB
}
Expand Down Expand Up @@ -56,11 +56,9 @@ func (s *service) StoreClientConfig(_ context.Context, params *api.StoreConfigPa

}



func (s *service) GetClientConfig(_ context.Context, parameters *api.GetConfigParameters) (*api.Config, error) {

lq := fmt.Sprintf( "select config from clientconfig.reactclientconfig where userid = '%v'", parameters.UserId)
lq := fmt.Sprintf("select config from clientconfig.reactclientconfig where userid = '%v'", parameters.UserId)

r, err := s.db.Query(lq)

Expand All @@ -75,7 +73,6 @@ func (s *service) GetClientConfig(_ context.Context, parameters *api.GetConfigPa
return nil, fmt.Errorf("failed to fetch config from database:%w", err)
}


return &api.Config{
Config: config,
}, nil
Expand All @@ -97,7 +94,7 @@ func newService(driverName, dbConnString string) (*service, error) {

err = db.Ping()
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to ping database: %w", err)
}

return s, nil
Expand All @@ -107,16 +104,14 @@ func (s *service) Close() {
if s.db != nil {
err := s.db.Close()
if err != nil {
errLog.Printf("erron closing database connection %v", err)
slog.Error("error closing database connection", "error", err)
}
}
}


func main() {

log.SetOutput(os.Stdout)
log.SetFlags(logFlags)
slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{AddSource: true})))

dbString := bootstrap.GetEnvVar("DB_CONN_STRING")
dbDriverName := bootstrap.GetEnvVar("DB_DRIVER_NAME")
Expand All @@ -137,8 +132,18 @@ func main() {
s := grpc.NewServer()
api.RegisterClientConfigServiceServer(s, service)

sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh,
syscall.SIGKILL,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
<-sigCh
s.GracefulStop()
}()

reflection.Register(s)
fmt.Println("Started client config service on port:" + port)
slog.Info("Started client config service", "port", port)
if err := s.Serve(lis); err != nil {
log.Panicf("Error while serving : %v", err)
}
Expand Down
4 changes: 3 additions & 1 deletion go/execution-venues/fix-sim-execution-venue/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ module github.com/ettec/open-trading-platform/go/execution-venues/fix-sim-execut
go 1.21

require (
github.com/ettec/otp-common v1.4.0
github.com/ettec/otp-common v1.4.2
github.com/golang/protobuf v1.4.2
github.com/google/uuid v1.1.1
github.com/quickfixgo/quickfix v0.6.0
github.com/shopspring/decimal v0.0.0-20191009025716-f1972eb1d1f5
github.com/stretchr/testify v1.4.0
google.golang.org/grpc v1.25.1
)

Expand All @@ -21,6 +22,7 @@ require (
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/segmentio/kafka-go v0.3.4 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975 // indirect
Expand Down
8 changes: 6 additions & 2 deletions go/execution-venues/fix-sim-execution-venue/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkg
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/ettec/otp-common v1.3.1-0.20231121170433-6f1dd05c001e h1:oSJ6u7EUItXeraZhKn5pdLH7JnawKFQjib+ejRqoxOY=
github.com/ettec/otp-common v1.3.1-0.20231121170433-6f1dd05c001e/go.mod h1:68PDrJp1ccRawgvPg0vYmSDPUi03ZCtBp4YJOJzeUjc=
github.com/ettec/otp-common v1.4.0 h1:cjwwHtqsP9Kwr08DSN6yqhcR3HnEqhtCy795tkSRRZQ=
github.com/ettec/otp-common v1.4.0/go.mod h1:68PDrJp1ccRawgvPg0vYmSDPUi03ZCtBp4YJOJzeUjc=
github.com/ettec/otp-common v1.4.1-0.20231128151006-7b41d465cd74 h1:R9dxpl1H76ImUpTiUPAqEzS59zug785h9zw+fqgNgmk=
github.com/ettec/otp-common v1.4.1-0.20231128151006-7b41d465cd74/go.mod h1:68PDrJp1ccRawgvPg0vYmSDPUi03ZCtBp4YJOJzeUjc=
github.com/ettec/otp-common v1.4.1 h1:Im44hSM83Jy56BnurMw/ZJwtwTlnzUNlCdTFzFTn65o=
github.com/ettec/otp-common v1.4.1/go.mod h1:68PDrJp1ccRawgvPg0vYmSDPUi03ZCtBp4YJOJzeUjc=
github.com/ettec/otp-common v1.4.2 h1:qmgPXctGWyHAwsyz0WnSgRFvhll8OGF4sfZkSZi+1tA=
github.com/ettec/otp-common v1.4.2/go.mod h1:68PDrJp1ccRawgvPg0vYmSDPUi03ZCtBp4YJOJzeUjc=
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
api "github.com/ettec/otp-common/api/executionvenue"
"github.com/ettec/otp-common/model"
"log"
"log/slog"
)

type orderManager interface {
Expand All @@ -15,7 +15,6 @@ type orderManager interface {
SetOrderStatus(orderId string, status model.OrderStatus) error
SetErrorMsg(orderId string, msg string) error
AddExecution(orderId string, lastPrice model.Decimal64, lastQty model.Decimal64, execId string) error
Close()
}

type ExecVenueService struct {
Expand All @@ -29,7 +28,7 @@ func New(om orderManager) *ExecVenueService {

func (s *ExecVenueService) CreateAndRouteOrder(_ context.Context, params *api.CreateAndRouteOrderParams) (*api.OrderId, error) {

log.Printf("Received order parameters-> %v", params)
slog.Info("Received order parameters", "params", params)

if params.GetQuantity() == nil {
return nil, fmt.Errorf("quantity required on params:%v", params)
Expand All @@ -53,31 +52,28 @@ func (s *ExecVenueService) CreateAndRouteOrder(_ context.Context, params *api.Cr

result, err := s.orderManager.CreateAndRouteOrder(params)
if err != nil {
log.Printf("error when creating and routing order:%v", err)
return nil, err
return nil, fmt.Errorf("error when creating and routing order:%w", err)
}

log.Printf("created order id:%v", result.OrderId)
slog.Info("created order", "orderId", result.OrderId)

return &api.OrderId{
OrderId: result.OrderId,
}, nil
}

func (s *ExecVenueService) CancelOrder(_ context.Context, p *api.CancelOrderParams) (*model.Empty, error) {
err := s.orderManager.CancelOrder(p)
if err != nil {
return nil, err
if err := s.orderManager.CancelOrder(p); err != nil {
return nil, fmt.Errorf("error when cancelling order:%w", err)
}

return &model.Empty{}, nil
}

func (s *ExecVenueService) ModifyOrder(_ context.Context, params *api.ModifyOrderParams) (*model.Empty, error) {

err := s.orderManager.ModifyOrder(params)
if err != nil {
return nil, err
if err := s.orderManager.ModifyOrder(params); err != nil {
return nil, fmt.Errorf("error when modifying order:%w", err)
}

return &model.Empty{}, nil
Expand All @@ -86,9 +82,3 @@ func (s *ExecVenueService) ModifyOrder(_ context.Context, params *api.ModifyOrde
func (s *ExecVenueService) GetExecutionParametersMetaData(context.Context, *model.Empty) (*api.ExecParamsMetaDataJson, error) {
return &api.ExecParamsMetaDataJson{}, nil
}

func (s *ExecVenueService) Close() {
if s.orderManager != nil {
s.orderManager.Close()
}
}
Loading

0 comments on commit fca1aad

Please sign in to comment.