From 8348eff4d22017920812119bbfa794329bc80d26 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 20 May 2021 10:16:27 +0100 Subject: [PATCH 01/11] Add london map, fix station size so visible on SE map --- darwingraph/maps/mapbuilder.go | 14 +++++++++++--- darwingraph/maps/mapdef.go | 24 ++++++++++++++++++++---- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/darwingraph/maps/mapbuilder.go b/darwingraph/maps/mapbuilder.go index 5e68893..fc15429 100644 --- a/darwingraph/maps/mapbuilder.go +++ b/darwingraph/maps/mapbuilder.go @@ -11,17 +11,25 @@ import ( ) type MapBuilder struct { - ctx *sm.Context + ctx *sm.Context + stationRadius float64 } type MapTask func(builder *MapBuilder) func NewMapBuilder() *MapBuilder { - m := &MapBuilder{ctx: sm.NewContext()} + m := &MapBuilder{ + ctx: sm.NewContext(), + stationRadius: 100.0, + } m.ctx.SetCenter(s2.LatLngFromDegrees(54.413, -3.878)) m.ctx.SetZoom(6) return m } +func (m *MapBuilder) StationRadius(r float64) *MapBuilder { + m.stationRadius = r + return m +} func (m *MapBuilder) TileProvider(p *sm.TileProvider) *MapBuilder { p.IgnoreNotFound = true @@ -119,7 +127,7 @@ func (m *MapBuilder) AppendStation(s *darwingraph.StationNode) *MapBuilder { s2.LatLngFromDegrees(float64(t.Lat), float64(t.Lon)), color.RGBA{R: 0xff, A: 0xff}, color.RGBA{R: 0xff, A: 0xff}, - 100.0, + m.stationRadius, 5.0, )) } diff --git a/darwingraph/maps/mapdef.go b/darwingraph/maps/mapdef.go index f522297..86fd42d 100644 --- a/darwingraph/maps/mapdef.go +++ b/darwingraph/maps/mapdef.go @@ -13,6 +13,7 @@ func (m *MapService) initMapDefs() { m.mapDefs = []MapDef{ {Name: "uk", Handler: m.ukMap}, {Name: "se", Handler: m.seMap}, + {Name: "london", Handler: m.londonMap}, } } @@ -29,11 +30,26 @@ func (m *MapService) ukMap(b *MapBuilder) { }) } -// ukMap generate a map of the South East +// seMap generate a map of the South East func (m *MapService) seMap(b *MapBuilder) { - b.Size(600, 710). - Center(0.5, 51). - Zoom(8). + b.Size(1000, 710). + Center(0.25, 51.25). + Zoom(9). + StationRadius(125). + ForEachStationEdge(m.darwinGraph, func(b *MapBuilder, e *darwingraph.StationEdge) { + b.AppendStationEdge(e) + }). + ForEachStationNode(m.darwinGraph, func(b *MapBuilder, n *darwingraph.StationNode) { + b.AppendStation(n) + }) +} + +// londonMap generate a map of London +func (m *MapService) londonMap(b *MapBuilder) { + b.Size(1000, 710). + Center(-.125, 51.5). + Zoom(11). + StationRadius(30). ForEachStationEdge(m.darwinGraph, func(b *MapBuilder, e *darwingraph.StationEdge) { b.AppendStationEdge(e) }). From 8d18f1a39c457e1e8d71931bf0987cdf38f7683b Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 20 May 2021 10:27:47 +0100 Subject: [PATCH 02/11] Change station colours dependent on being public or CRS x* or Z* --- darwingraph/importNreFeedsCache.go | 3 ++- darwingraph/maps/mapbuilder.go | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/darwingraph/importNreFeedsCache.go b/darwingraph/importNreFeedsCache.go index bca7239..0ece4c6 100644 --- a/darwingraph/importNreFeedsCache.go +++ b/darwingraph/importNreFeedsCache.go @@ -6,6 +6,7 @@ import ( "log" "os" "path/filepath" + "strings" ) func (d *DarwinGraph) importNreFeedsCache() error { @@ -43,7 +44,7 @@ func (d *nreFeedImport) process(path string, info os.FileInfo, err error) error } // Ignore Bus & Ship services - if !(sched.TrainId == "0B00" || sched.TrainId == "0S00") { + if !(strings.HasPrefix(sched.TrainId, "0B") || strings.HasPrefix(sched.TrainId, "0S")) { d.importCount++ err = d.importNreFeedsSchedule(sched) if err != nil { diff --git a/darwingraph/maps/mapbuilder.go b/darwingraph/maps/mapbuilder.go index fc15429..6909388 100644 --- a/darwingraph/maps/mapbuilder.go +++ b/darwingraph/maps/mapbuilder.go @@ -123,13 +123,20 @@ func (m *MapBuilder) ForEachStationNode(d *darwingraph.DarwinGraph, f func(*MapB func (m *MapBuilder) AppendStation(s *darwingraph.StationNode) *MapBuilder { s.ForEachTiploc(func(t *darwingraph.TiplocNode) { if t.HasPosition() { - m.AddObject(sm.NewCircle( - s2.LatLngFromDegrees(float64(t.Lat), float64(t.Lon)), - color.RGBA{R: 0xff, A: 0xff}, - color.RGBA{R: 0xff, A: 0xff}, - m.stationRadius, - 5.0, - )) + col := color.RGBA{R: 0xff, A: 0xff} + w := 5.0 + if s.Crs[0] == 'X' || s.Crs[0] == 'Z' { + col.R = 0 + col.B = 0xff + w = 4.0 + } + if !t.IsPublic() { + col.R = 0x80 + col.G = 0x80 + col.B = 0x80 + w = 3.0 + } + m.AddObject(sm.NewCircle(s2.LatLngFromDegrees(float64(t.Lat), float64(t.Lon)), col, col, m.stationRadius, w)) } }) return m From 0b19d1722279464aacc2d16f2558afee884e016e Mon Sep 17 00:00:00 2001 From: peter Date: Sat, 31 Dec 2022 08:59:55 +0000 Subject: [PATCH 03/11] Update to rabbitmq library --- bin/graphite.go | 2 +- darwind3/consumer.go | 2 +- darwind3/feedHeaders.go | 2 +- darwingraph/maps/mapbuilder.go | 7 ++++++- go.mod | 3 +-- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bin/graphite.go b/bin/graphite.go index 7bdc972..e110f5c 100644 --- a/bin/graphite.go +++ b/bin/graphite.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/peter-mount/go-kernel" "github.com/peter-mount/golib/statistics" - "github.com/streadway/amqp" + amqp "github.com/rabbitmq/amqp091-go" ) type Graphite struct { diff --git a/darwind3/consumer.go b/darwind3/consumer.go index b55bd73..fccbbc8 100644 --- a/darwind3/consumer.go +++ b/darwind3/consumer.go @@ -5,7 +5,7 @@ import ( "encoding/xml" "github.com/peter-mount/go-kernel/rabbitmq" "github.com/peter-mount/golib/statistics" - "github.com/streadway/amqp" + amqp "github.com/rabbitmq/amqp091-go" ) // BindConsumer binds a consumer to a RabbitMQ queue to receive D3 messages diff --git a/darwind3/feedHeaders.go b/darwind3/feedHeaders.go index 6d1485b..d47b29f 100644 --- a/darwind3/feedHeaders.go +++ b/darwind3/feedHeaders.go @@ -1,7 +1,7 @@ package darwind3 import ( - "github.com/streadway/amqp" + amqp "github.com/rabbitmq/amqp091-go" ) // FeedHeaders holds the relevant headers from the feed diff --git a/darwingraph/maps/mapbuilder.go b/darwingraph/maps/mapbuilder.go index 6909388..52c640e 100644 --- a/darwingraph/maps/mapbuilder.go +++ b/darwingraph/maps/mapbuilder.go @@ -83,13 +83,18 @@ func (o wrapperPath) Draw(gc *gg.Context, trans *sm.Transformer) { first := true + // Margin around the image bounds to allow points + margin := 10.0 + maxW := float64(gc.Width()) + margin + maxH := float64(gc.Height()) + margin + gc.ClearPath() gc.SetLineWidth(o.p.Weight) gc.SetLineCap(gg.LineCapRound) gc.SetLineJoin(gg.LineJoinRound) for _, ll := range o.p.Positions { x, y := trans.LatLngToXY(ll) - if x < 0 || y < 0 || int(x) >= gc.Width() || int(y) >= gc.Height() { + if x < -margin || y < -margin || x >= maxW || y >= maxH { first = true } else if first { gc.MoveTo(x, y) diff --git a/go.mod b/go.mod index 64c45f4..eb7cfb8 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,6 @@ require ( github.com/gorilla/handlers v1.5.1 github.com/gorilla/mux v1.7.3 // indirect github.com/jlaffaye/ftp v0.0.0-20190828173736-6aaa91c7796e - github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5 // indirect github.com/lib/pq v1.2.0 github.com/peter-mount/filecache v0.0.0-20190909121939-281dcdcbbbfd github.com/peter-mount/go-kernel v0.0.0-20210827013724-c3ef1ed4eab3 @@ -23,7 +22,7 @@ require ( github.com/peter-mount/nrod-cif v0.0.0-20190716191943-8c7234b142cc github.com/peter-mount/sortfold v0.2.1 github.com/pkg/errors v0.9.1 - github.com/streadway/amqp v1.0.0 + github.com/rabbitmq/amqp091-go v1.3.4 github.com/stretchr/testify v1.4.0 // indirect golang.org/x/net v0.0.0-20190923162816-aa69164e4478 // indirect gonum.org/v1/gonum v0.9.1 From 1c6b3a7db5ea67d6c0ca8b8f9bfd000425c49e1c Mon Sep 17 00:00:00 2001 From: peter Date: Sat, 31 Dec 2022 10:26:45 +0000 Subject: [PATCH 04/11] Update to go 1.19 & latest stable kernel --- .dockerignore | 7 ++++ admin/admin.go | 54 +++++++++++++-------------- admin/bin/main.go | 18 ++++----- admin/messages/messages.go | 26 ++++++------- admin/messages/pruneMessage.go | 36 +++++++++--------- bin/config.go | 4 +- bin/graphite.go | 2 +- darwind3/bin/main.go | 2 +- darwind3/consumer.go | 2 +- darwind3/event.go | 2 +- darwind3/service/alarms.go | 2 +- darwind3/service/schedule.go | 2 +- darwind3/service/service.go | 6 +-- darwind3/service/stationMessage.go | 2 +- darwind3/service/status.go | 2 +- darwindb/bin/main.go | 2 +- darwindb/darwindb.go | 2 +- darwindb/service/getService.go | 2 +- darwindb/service/getServices.go | 2 +- darwindb/service/service.go | 6 +-- darwingraph/bin/main.go | 2 +- darwingraph/graph.go | 2 +- darwingraph/maps/mapService.go | 2 +- darwingraph/service/service.go | 6 +-- darwinkb/bin/main.go | 2 +- darwinkb/companies.go | 2 +- darwinkb/darwinkb.go | 6 +-- darwinkb/incident.go | 2 +- darwinkb/service/companies.go | 2 +- darwinkb/service/incidents.go | 2 +- darwinkb/service/service.go | 4 +- darwinkb/service/serviceIndicators.go | 2 +- darwinkb/service/station.go | 2 +- darwinkb/service/ticketTypes.go | 2 +- darwinkb/serviceIndicators.go | 2 +- darwinkb/station.go | 2 +- darwinkb/ticketTypes.go | 2 +- darwinkb/util.go | 2 +- darwinref/bin/main.go | 2 +- darwinref/service/crs.go | 2 +- darwinref/service/reasons.go | 2 +- darwinref/service/search.go | 2 +- darwinref/service/service.go | 6 +-- darwinref/service/tiploc.go | 2 +- darwinref/service/toc.go | 2 +- darwinref/service/via.go | 2 +- darwinref/service/viaResolver.go | 2 +- darwinref/update/service.go | 2 +- darwinrest/journey.go | 2 +- darwinrest/rest.go | 2 +- darwintimetable/bin/main.go | 2 +- darwintimetable/service/journey.go | 2 +- darwintimetable/service/service.go | 6 +-- darwintimetable/update/service.go | 2 +- go.mod | 29 ++++++++++---- ldb/bin/main.go | 2 +- ldb/service/restService.go | 2 +- ldb/service/restStation.go | 2 +- ldb/service/service.go | 6 +-- test.sh | 13 +++---- xmas/bin/main.go | 2 +- xmas/xmas.go | 2 +- 62 files changed, 171 insertions(+), 154 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..252188d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.git +.idea +go_* +Dockerfile* +config*.yaml +*.cif +# go.sum diff --git a/admin/admin.go b/admin/admin.go index ae03c7c..29e7958 100644 --- a/admin/admin.go +++ b/admin/admin.go @@ -1,47 +1,47 @@ package admin import ( - "github.com/peter-mount/go-kernel" - "github.com/peter-mount/nre-feeds/bin" - "github.com/peter-mount/nre-feeds/darwind3/client" - "github.com/peter-mount/nre-feeds/util/worker" + "github.com/peter-mount/go-kernel/v2" + "github.com/peter-mount/nre-feeds/bin" + "github.com/peter-mount/nre-feeds/darwind3/client" + "github.com/peter-mount/nre-feeds/util/worker" ) type Admin struct { - taskQueue *worker.TaskQueue - config *bin.Config + taskQueue *worker.TaskQueue + config *bin.Config } func (a *Admin) Name() string { - return "Admin" + return "Admin" } func (a *Admin) Init(k *kernel.Kernel) error { - service, err := k.AddService(&bin.Config{}) - if err != nil { - return err - } - a.config = service.(*bin.Config) - - service, err = k.AddService(&worker.TaskQueue{}) - if err != nil { - return err - } - a.taskQueue = service.(*worker.TaskQueue) - - return err + service, err := k.AddService(&bin.Config{}) + if err != nil { + return err + } + a.config = service.(*bin.Config) + + service, err = k.AddService(&worker.TaskQueue{}) + if err != nil { + return err + } + a.taskQueue = service.(*worker.TaskQueue) + + return err } func (a *Admin) Start() error { - a.taskQueue.SetContext("d3", &client.DarwinD3Client{Url: a.config.Services.DarwinD3}) + a.taskQueue.SetContext("d3", &client.DarwinD3Client{Url: a.config.Services.DarwinD3}) - a.config.RabbitMQ.ConnectionName = "darwin admin" + a.config.RabbitMQ.ConnectionName = "darwin admin" - if err := a.config.RabbitMQ.Connect(); err != nil { - return err - } + if err := a.config.RabbitMQ.Connect(); err != nil { + return err + } - a.taskQueue.SetContext("mq", &a.config.RabbitMQ) + a.taskQueue.SetContext("mq", &a.config.RabbitMQ) - return nil + return nil } diff --git a/admin/bin/main.go b/admin/bin/main.go index 5ba04b2..af222a5 100644 --- a/admin/bin/main.go +++ b/admin/bin/main.go @@ -1,16 +1,16 @@ package main import ( - "github.com/peter-mount/go-kernel" - "github.com/peter-mount/nre-feeds/admin/messages" - "log" + "github.com/peter-mount/go-kernel/v2" + "github.com/peter-mount/nre-feeds/admin/messages" + "log" ) func main() { - err := kernel.Launch( - &messages.Messages{}, - ) - if err != nil { - log.Fatal(err) - } + err := kernel.Launch( + &messages.Messages{}, + ) + if err != nil { + log.Fatal(err) + } } diff --git a/admin/messages/messages.go b/admin/messages/messages.go index acf630a..5ff3198 100644 --- a/admin/messages/messages.go +++ b/admin/messages/messages.go @@ -1,31 +1,31 @@ package messages import ( - "github.com/peter-mount/go-kernel" - "github.com/peter-mount/nre-feeds/admin" - "github.com/peter-mount/nre-feeds/util/worker" + "github.com/peter-mount/go-kernel/v2" + "github.com/peter-mount/nre-feeds/admin" + "github.com/peter-mount/nre-feeds/util/worker" ) // Messages manages cleaning up station messages type Messages struct { - taskQueue *worker.TaskQueue + taskQueue *worker.TaskQueue } func (m *Messages) Name() string { - return "AdminMessages" + return "AdminMessages" } func (m *Messages) Init(k *kernel.Kernel) error { - service, err := k.AddService(&worker.TaskQueue{}) - if err != nil { - return err - } - m.taskQueue = service.(*worker.TaskQueue) + service, err := k.AddService(&worker.TaskQueue{}) + if err != nil { + return err + } + m.taskQueue = service.(*worker.TaskQueue) - return k.DependsOn(&admin.Admin{}) + return k.DependsOn(&admin.Admin{}) } func (m *Messages) Start() error { - m.taskQueue.AddTask(&getStationMessages{}) - return nil + m.taskQueue.AddTask(&getStationMessages{}) + return nil } diff --git a/admin/messages/pruneMessage.go b/admin/messages/pruneMessage.go index 91a9f60..6152103 100644 --- a/admin/messages/pruneMessage.go +++ b/admin/messages/pruneMessage.go @@ -1,36 +1,36 @@ package messages import ( - "context" - "fmt" - "github.com/peter-mount/go-kernel/rabbitmq" - "time" + "context" + "fmt" + "github.com/peter-mount/go-kernel/v2/rabbitmq" + "time" ) type pruneStationMessage struct { - ID int64 + ID int64 } func (m *pruneStationMessage) Name() string { - return fmt.Sprintf("Remove Station Message %d", m.ID) + return fmt.Sprintf("Remove Station Message %d", m.ID) } const ( - TIMESTAMP = "2006-01-02T15:04:05Z" + TIMESTAMP = "2006-01-02T15:04:05Z" ) func (m *pruneStationMessage) Run(ctx context.Context) error { - //d3Client := ctx.Value("d3").(*client.DarwinD3Client) - mq := ctx.Value("mq").(*rabbitmq.RabbitMQ) + //d3Client := ctx.Value("d3").(*client.DarwinD3Client) + mq := ctx.Value("mq").(*rabbitmq.RabbitMQ) - mq.Publish( - "nre.darwin.pushport-v16", - []byte(fmt.Sprintf(""+ - ""+ - "Deleted"+ - "", - time.Now().UTC().Format(TIMESTAMP), - m.ID))) + mq.Publish( + "nre.darwin.pushport-v16", + []byte(fmt.Sprintf(""+ + ""+ + "Deleted"+ + "", + time.Now().UTC().Format(TIMESTAMP), + m.ID))) - return nil + return nil } diff --git a/bin/config.go b/bin/config.go index 7a71764..0fdfde1 100644 --- a/bin/config.go +++ b/bin/config.go @@ -3,8 +3,8 @@ package bin import ( "flag" - "github.com/peter-mount/go-kernel" - "github.com/peter-mount/go-kernel/rabbitmq" + "github.com/peter-mount/go-kernel/v2" + "github.com/peter-mount/go-kernel/v2/rabbitmq" "github.com/peter-mount/nre-feeds/util/s3" "gopkg.in/yaml.v2" "io/ioutil" diff --git a/bin/graphite.go b/bin/graphite.go index e110f5c..52f7eff 100644 --- a/bin/graphite.go +++ b/bin/graphite.go @@ -2,7 +2,7 @@ package bin import ( "fmt" - "github.com/peter-mount/go-kernel" + "github.com/peter-mount/go-kernel/v2" "github.com/peter-mount/golib/statistics" amqp "github.com/rabbitmq/amqp091-go" ) diff --git a/darwind3/bin/main.go b/darwind3/bin/main.go index 3d1c3c1..d88726c 100644 --- a/darwind3/bin/main.go +++ b/darwind3/bin/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/peter-mount/go-kernel" + "github.com/peter-mount/go-kernel/v2" "github.com/peter-mount/nre-feeds/bin" "github.com/peter-mount/nre-feeds/darwind3/service" "log" diff --git a/darwind3/consumer.go b/darwind3/consumer.go index fccbbc8..9c6f17b 100644 --- a/darwind3/consumer.go +++ b/darwind3/consumer.go @@ -3,7 +3,7 @@ package darwind3 import ( "bytes" "encoding/xml" - "github.com/peter-mount/go-kernel/rabbitmq" + "github.com/peter-mount/go-kernel/v2/rabbitmq" "github.com/peter-mount/golib/statistics" amqp "github.com/rabbitmq/amqp091-go" ) diff --git a/darwind3/event.go b/darwind3/event.go index c56039b..58c6356 100644 --- a/darwind3/event.go +++ b/darwind3/event.go @@ -3,7 +3,7 @@ package darwind3 import ( "encoding/json" "fmt" - "github.com/peter-mount/go-kernel/rabbitmq" + "github.com/peter-mount/go-kernel/v2/rabbitmq" "log" "os" ) diff --git a/darwind3/service/alarms.go b/darwind3/service/alarms.go index af38aa6..16b7d73 100644 --- a/darwind3/service/alarms.go +++ b/darwind3/service/alarms.go @@ -1,6 +1,6 @@ package service -import "github.com/peter-mount/go-kernel/rest" +import "github.com/peter-mount/go-kernel/v2/rest" func (d *DarwinD3Service) AlarmHandler(r *rest.Rest) error { r.Status(200). diff --git a/darwind3/service/schedule.go b/darwind3/service/schedule.go index 64e59ed..e52ec2a 100644 --- a/darwind3/service/schedule.go +++ b/darwind3/service/schedule.go @@ -1,7 +1,7 @@ package service import ( - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2/rest" ) func (d *DarwinD3Service) ScheduleHandler(r *rest.Rest) error { diff --git a/darwind3/service/service.go b/darwind3/service/service.go index e910406..2b94ec7 100644 --- a/darwind3/service/service.go +++ b/darwind3/service/service.go @@ -4,9 +4,9 @@ import ( "github.com/gorilla/handlers" "github.com/peter-mount/filecache" fcsve "github.com/peter-mount/filecache/service" - "github.com/peter-mount/go-kernel" - "github.com/peter-mount/go-kernel/cron" - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2" + "github.com/peter-mount/go-kernel/v2/cron" + "github.com/peter-mount/go-kernel/v2/rest" "github.com/peter-mount/nre-feeds/bin" "github.com/peter-mount/nre-feeds/darwind3" "runtime/debug" diff --git a/darwind3/service/stationMessage.go b/darwind3/service/stationMessage.go index fe84fac..0895374 100644 --- a/darwind3/service/stationMessage.go +++ b/darwind3/service/stationMessage.go @@ -1,7 +1,7 @@ package service import ( - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2/rest" "github.com/peter-mount/nre-feeds/darwind3" "strconv" ) diff --git a/darwind3/service/status.go b/darwind3/service/status.go index 83b9063..a7e91cd 100644 --- a/darwind3/service/status.go +++ b/darwind3/service/status.go @@ -1,6 +1,6 @@ package service -import "github.com/peter-mount/go-kernel/rest" +import "github.com/peter-mount/go-kernel/v2/rest" type badgeResponse struct { SchemaVersion int `json:"schemaVersion"` diff --git a/darwindb/bin/main.go b/darwindb/bin/main.go index ab8d4f8..57d2281 100644 --- a/darwindb/bin/main.go +++ b/darwindb/bin/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/peter-mount/go-kernel" + "github.com/peter-mount/go-kernel/v2" "github.com/peter-mount/nre-feeds/bin" "github.com/peter-mount/nre-feeds/darwindb/service" "log" diff --git a/darwindb/darwindb.go b/darwindb/darwindb.go index 1e07c67..cdca57a 100644 --- a/darwindb/darwindb.go +++ b/darwindb/darwindb.go @@ -3,7 +3,7 @@ package darwindb import ( "database/sql" _ "github.com/lib/pq" - "github.com/peter-mount/go-kernel/rabbitmq" + "github.com/peter-mount/go-kernel/v2/rabbitmq" "github.com/peter-mount/golib/statistics" "github.com/peter-mount/nre-feeds/bin" "log" diff --git a/darwindb/service/getService.go b/darwindb/service/getService.go index 625e22f..4944546 100644 --- a/darwindb/service/getService.go +++ b/darwindb/service/getService.go @@ -1,7 +1,7 @@ package service import ( - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2/rest" "log" "net/http" "strings" diff --git a/darwindb/service/getServices.go b/darwindb/service/getServices.go index db24802..ef38d9f 100644 --- a/darwindb/service/getServices.go +++ b/darwindb/service/getServices.go @@ -1,7 +1,7 @@ package service import ( - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2/rest" "log" "net/http" "strconv" diff --git a/darwindb/service/service.go b/darwindb/service/service.go index 414c12a..78017fe 100644 --- a/darwindb/service/service.go +++ b/darwindb/service/service.go @@ -1,9 +1,9 @@ package service import ( - "github.com/peter-mount/go-kernel" - "github.com/peter-mount/go-kernel/cron" - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2" + "github.com/peter-mount/go-kernel/v2/cron" + "github.com/peter-mount/go-kernel/v2/rest" "github.com/peter-mount/nre-feeds/bin" "github.com/peter-mount/nre-feeds/darwind3" "github.com/peter-mount/nre-feeds/darwindb" diff --git a/darwingraph/bin/main.go b/darwingraph/bin/main.go index 618e6dc..f475b43 100644 --- a/darwingraph/bin/main.go +++ b/darwingraph/bin/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/peter-mount/go-kernel" + "github.com/peter-mount/go-kernel/v2" "github.com/peter-mount/nre-feeds/darwingraph/maps" "github.com/peter-mount/nre-feeds/darwingraph/service" "log" diff --git a/darwingraph/graph.go b/darwingraph/graph.go index e3e3afc..b608dd1 100644 --- a/darwingraph/graph.go +++ b/darwingraph/graph.go @@ -4,7 +4,7 @@ import ( "encoding/xml" "errors" "flag" - "github.com/peter-mount/go-kernel" + "github.com/peter-mount/go-kernel/v2" "log" "os" "sync" diff --git a/darwingraph/maps/mapService.go b/darwingraph/maps/mapService.go index b1a4543..dce5942 100644 --- a/darwingraph/maps/mapService.go +++ b/darwingraph/maps/mapService.go @@ -4,7 +4,7 @@ import ( "errors" "flag" "fmt" - "github.com/peter-mount/go-kernel" + "github.com/peter-mount/go-kernel/v2" "github.com/peter-mount/nre-feeds/darwingraph" "log" "os" diff --git a/darwingraph/service/service.go b/darwingraph/service/service.go index 564fdc1..0978a55 100644 --- a/darwingraph/service/service.go +++ b/darwingraph/service/service.go @@ -2,9 +2,9 @@ package service import ( "github.com/gorilla/handlers" - "github.com/peter-mount/go-kernel" - "github.com/peter-mount/go-kernel/cron" - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2" + "github.com/peter-mount/go-kernel/v2/cron" + "github.com/peter-mount/go-kernel/v2/rest" "github.com/peter-mount/nre-feeds/bin" "github.com/peter-mount/nre-feeds/darwingraph" ) diff --git a/darwinkb/bin/main.go b/darwinkb/bin/main.go index 73f2ed5..3138ae5 100644 --- a/darwinkb/bin/main.go +++ b/darwinkb/bin/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/peter-mount/go-kernel" + "github.com/peter-mount/go-kernel/v2" "github.com/peter-mount/nre-feeds/darwinkb/service" "log" ) diff --git a/darwinkb/companies.go b/darwinkb/companies.go index ecb858c..a6aa3cf 100644 --- a/darwinkb/companies.go +++ b/darwinkb/companies.go @@ -1,7 +1,7 @@ package darwinkb import ( - "github.com/peter-mount/go-kernel/bolt" + "github.com/peter-mount/go-kernel/v2/bolt" "github.com/peter-mount/sortfold" "log" "sort" diff --git a/darwinkb/darwinkb.go b/darwinkb/darwinkb.go index 92440da..b30026f 100644 --- a/darwinkb/darwinkb.go +++ b/darwinkb/darwinkb.go @@ -1,9 +1,9 @@ package darwinkb import ( - "github.com/peter-mount/go-kernel" - "github.com/peter-mount/go-kernel/bolt" - "github.com/peter-mount/go-kernel/cron" + "github.com/peter-mount/go-kernel/v2" + "github.com/peter-mount/go-kernel/v2/bolt" + "github.com/peter-mount/go-kernel/v2/cron" "github.com/peter-mount/nre-feeds/bin" "os" ) diff --git a/darwinkb/incident.go b/darwinkb/incident.go index 42aad89..3c8c9f4 100644 --- a/darwinkb/incident.go +++ b/darwinkb/incident.go @@ -1,7 +1,7 @@ package darwinkb import ( - "github.com/peter-mount/go-kernel/bolt" + "github.com/peter-mount/go-kernel/v2/bolt" "github.com/peter-mount/sortfold" "log" "sort" diff --git a/darwinkb/service/companies.go b/darwinkb/service/companies.go index f89dbbe..cda7b49 100644 --- a/darwinkb/service/companies.go +++ b/darwinkb/service/companies.go @@ -1,7 +1,7 @@ package service import ( - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2/rest" "log" ) diff --git a/darwinkb/service/incidents.go b/darwinkb/service/incidents.go index 0bae13b..be85b9b 100644 --- a/darwinkb/service/incidents.go +++ b/darwinkb/service/incidents.go @@ -1,7 +1,7 @@ package service import ( - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2/rest" "log" ) diff --git a/darwinkb/service/service.go b/darwinkb/service/service.go index ec83209..42eaa1d 100644 --- a/darwinkb/service/service.go +++ b/darwinkb/service/service.go @@ -2,8 +2,8 @@ package service import ( "github.com/gorilla/handlers" - "github.com/peter-mount/go-kernel" - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2" + "github.com/peter-mount/go-kernel/v2/rest" "github.com/peter-mount/nre-feeds/bin" "github.com/peter-mount/nre-feeds/darwinkb" ) diff --git a/darwinkb/service/serviceIndicators.go b/darwinkb/service/serviceIndicators.go index 025eaf1..67ed41a 100644 --- a/darwinkb/service/serviceIndicators.go +++ b/darwinkb/service/serviceIndicators.go @@ -1,7 +1,7 @@ package service import ( - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2/rest" "log" ) diff --git a/darwinkb/service/station.go b/darwinkb/service/station.go index 8cef23f..5650e8f 100644 --- a/darwinkb/service/station.go +++ b/darwinkb/service/station.go @@ -1,7 +1,7 @@ package service import ( - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2/rest" "log" ) diff --git a/darwinkb/service/ticketTypes.go b/darwinkb/service/ticketTypes.go index 6447887..d70c466 100644 --- a/darwinkb/service/ticketTypes.go +++ b/darwinkb/service/ticketTypes.go @@ -1,7 +1,7 @@ package service import ( - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2/rest" "log" ) diff --git a/darwinkb/serviceIndicators.go b/darwinkb/serviceIndicators.go index 65a8dbb..5628a10 100644 --- a/darwinkb/serviceIndicators.go +++ b/darwinkb/serviceIndicators.go @@ -1,7 +1,7 @@ package darwinkb import ( - "github.com/peter-mount/go-kernel/bolt" + "github.com/peter-mount/go-kernel/v2/bolt" "log" ) diff --git a/darwinkb/station.go b/darwinkb/station.go index 3f08a2f..97b4a21 100644 --- a/darwinkb/station.go +++ b/darwinkb/station.go @@ -1,7 +1,7 @@ package darwinkb import ( - "github.com/peter-mount/go-kernel/bolt" + "github.com/peter-mount/go-kernel/v2/bolt" "log" ) diff --git a/darwinkb/ticketTypes.go b/darwinkb/ticketTypes.go index 0614279..afb289e 100644 --- a/darwinkb/ticketTypes.go +++ b/darwinkb/ticketTypes.go @@ -1,7 +1,7 @@ package darwinkb import ( - "github.com/peter-mount/go-kernel/bolt" + "github.com/peter-mount/go-kernel/v2/bolt" "github.com/peter-mount/sortfold" "log" "sort" diff --git a/darwinkb/util.go b/darwinkb/util.go index e93fd53..956353f 100644 --- a/darwinkb/util.go +++ b/darwinkb/util.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "errors" - "github.com/peter-mount/go-kernel/bolt" + "github.com/peter-mount/go-kernel/v2/bolt" ) func (r *DarwinKB) View(n string, f func(*bolt.Bucket) error) error { diff --git a/darwinref/bin/main.go b/darwinref/bin/main.go index 1dfc151..24be72f 100644 --- a/darwinref/bin/main.go +++ b/darwinref/bin/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/peter-mount/go-kernel" + "github.com/peter-mount/go-kernel/v2" "github.com/peter-mount/nre-feeds/darwinref/service" "github.com/peter-mount/nre-feeds/darwinref/update" "log" diff --git a/darwinref/service/crs.go b/darwinref/service/crs.go index 66488a5..77b8fee 100644 --- a/darwinref/service/crs.go +++ b/darwinref/service/crs.go @@ -3,7 +3,7 @@ package service import ( "encoding/json" bolt "github.com/etcd-io/bbolt" - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2/rest" "github.com/peter-mount/nre-feeds/darwinref" ) diff --git a/darwinref/service/reasons.go b/darwinref/service/reasons.go index 9cfdce9..b2d6200 100644 --- a/darwinref/service/reasons.go +++ b/darwinref/service/reasons.go @@ -2,7 +2,7 @@ package service import ( bolt "github.com/etcd-io/bbolt" - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2/rest" "github.com/peter-mount/nre-feeds/darwinref" "sort" "strconv" diff --git a/darwinref/service/search.go b/darwinref/service/search.go index 8b1940c..9f0b365 100644 --- a/darwinref/service/search.go +++ b/darwinref/service/search.go @@ -4,7 +4,7 @@ import ( "encoding/json" "fmt" bolt "github.com/etcd-io/bbolt" - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2/rest" "github.com/peter-mount/nre-feeds/darwinref" "sort" "strings" diff --git a/darwinref/service/service.go b/darwinref/service/service.go index d90c0ae..f2b2f81 100644 --- a/darwinref/service/service.go +++ b/darwinref/service/service.go @@ -2,9 +2,9 @@ package service import ( "github.com/gorilla/handlers" - "github.com/peter-mount/go-kernel" - "github.com/peter-mount/go-kernel/cron" - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2" + "github.com/peter-mount/go-kernel/v2/cron" + "github.com/peter-mount/go-kernel/v2/rest" "github.com/peter-mount/nre-feeds/bin" "github.com/peter-mount/nre-feeds/darwinref" ) diff --git a/darwinref/service/tiploc.go b/darwinref/service/tiploc.go index 4b342e5..23a978d 100644 --- a/darwinref/service/tiploc.go +++ b/darwinref/service/tiploc.go @@ -2,7 +2,7 @@ package service import ( bolt "github.com/etcd-io/bbolt" - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2/rest" "github.com/peter-mount/nre-feeds/darwinref" ) diff --git a/darwinref/service/toc.go b/darwinref/service/toc.go index 414fcb7..3659d14 100644 --- a/darwinref/service/toc.go +++ b/darwinref/service/toc.go @@ -2,7 +2,7 @@ package service import ( bolt "github.com/etcd-io/bbolt" - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2/rest" "github.com/peter-mount/nre-feeds/darwinref" ) diff --git a/darwinref/service/via.go b/darwinref/service/via.go index c47d94b..d193c05 100644 --- a/darwinref/service/via.go +++ b/darwinref/service/via.go @@ -2,7 +2,7 @@ package service import ( bolt "github.com/etcd-io/bbolt" - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2/rest" "log" ) diff --git a/darwinref/service/viaResolver.go b/darwinref/service/viaResolver.go index 11c008d..bae1e64 100644 --- a/darwinref/service/viaResolver.go +++ b/darwinref/service/viaResolver.go @@ -1,7 +1,7 @@ package service import ( - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2/rest" "github.com/peter-mount/nre-feeds/darwinref" ) diff --git a/darwinref/update/service.go b/darwinref/update/service.go index fb024b9..a3628b0 100644 --- a/darwinref/update/service.go +++ b/darwinref/update/service.go @@ -1,7 +1,7 @@ package update import ( - "github.com/peter-mount/go-kernel" + "github.com/peter-mount/go-kernel/v2" "github.com/peter-mount/nre-feeds/bin" "github.com/peter-mount/nre-feeds/darwind3" "github.com/peter-mount/nre-feeds/darwinref/service" diff --git a/darwinrest/journey.go b/darwinrest/journey.go index ebd0157..2880cbf 100644 --- a/darwinrest/journey.go +++ b/darwinrest/journey.go @@ -3,7 +3,7 @@ package darwinrest import ( "encoding/xml" bolt "github.com/etcd-io/bbolt" - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2/rest" "github.com/peter-mount/nre-feeds/darwinref" "github.com/peter-mount/nre-feeds/darwintimetable" ) diff --git a/darwinrest/rest.go b/darwinrest/rest.go index 3752a1f..9fc521f 100644 --- a/darwinrest/rest.go +++ b/darwinrest/rest.go @@ -3,7 +3,7 @@ package darwinrest import ( - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2/rest" "github.com/peter-mount/nre-feeds/darwinref" "github.com/peter-mount/nre-feeds/darwintimetable" ) diff --git a/darwintimetable/bin/main.go b/darwintimetable/bin/main.go index 7b28978..1eac9e5 100644 --- a/darwintimetable/bin/main.go +++ b/darwintimetable/bin/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/peter-mount/go-kernel" + "github.com/peter-mount/go-kernel/v2" "github.com/peter-mount/nre-feeds/darwintimetable/service" "github.com/peter-mount/nre-feeds/darwintimetable/update" "log" diff --git a/darwintimetable/service/journey.go b/darwintimetable/service/journey.go index f582592..228b732 100644 --- a/darwintimetable/service/journey.go +++ b/darwintimetable/service/journey.go @@ -2,7 +2,7 @@ package service import ( bolt "github.com/etcd-io/bbolt" - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2/rest" ) func (dt *DarwinTimetableService) JourneyHandler(r *rest.Rest) error { diff --git a/darwintimetable/service/service.go b/darwintimetable/service/service.go index 59daa9a..01657d5 100644 --- a/darwintimetable/service/service.go +++ b/darwintimetable/service/service.go @@ -2,9 +2,9 @@ package service import ( "github.com/gorilla/handlers" - "github.com/peter-mount/go-kernel" - "github.com/peter-mount/go-kernel/cron" - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2" + "github.com/peter-mount/go-kernel/v2/cron" + "github.com/peter-mount/go-kernel/v2/rest" "github.com/peter-mount/nre-feeds/bin" "github.com/peter-mount/nre-feeds/darwintimetable" ) diff --git a/darwintimetable/update/service.go b/darwintimetable/update/service.go index e807e3a..9fb0ade 100644 --- a/darwintimetable/update/service.go +++ b/darwintimetable/update/service.go @@ -1,7 +1,7 @@ package update import ( - "github.com/peter-mount/go-kernel" + "github.com/peter-mount/go-kernel/v2" "github.com/peter-mount/nre-feeds/bin" "github.com/peter-mount/nre-feeds/darwind3" "github.com/peter-mount/nre-feeds/darwintimetable/service" diff --git a/go.mod b/go.mod index eb7cfb8..192103c 100644 --- a/go.mod +++ b/go.mod @@ -1,31 +1,44 @@ module github.com/peter-mount/nre-feeds -go 1.13 +go 1.19 require ( github.com/aws/aws-sdk-go v1.24.4 - github.com/bitly/go-simplejson v0.5.0 // indirect - github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect github.com/etcd-io/bbolt v1.3.3 github.com/flopp/go-staticmaps v0.0.0-20210425143944-2e6e19a99c28 github.com/fogleman/gg v1.3.0 github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 github.com/gorilla/handlers v1.5.1 - github.com/gorilla/mux v1.7.3 // indirect github.com/jlaffaye/ftp v0.0.0-20190828173736-6aaa91c7796e github.com/lib/pq v1.2.0 github.com/peter-mount/filecache v0.0.0-20190909121939-281dcdcbbbfd - github.com/peter-mount/go-kernel v0.0.0-20210827013724-c3ef1ed4eab3 + github.com/peter-mount/go-kernel/v2 v2.0.2 github.com/peter-mount/golib v0.0.0-20190924084925-7f296a747319 github.com/peter-mount/goxml2json v1.1.0 github.com/peter-mount/nrod-cif v0.0.0-20190716191943-8c7234b142cc github.com/peter-mount/sortfold v0.2.1 github.com/pkg/errors v0.9.1 github.com/rabbitmq/amqp091-go v1.3.4 + gonum.org/v1/gonum v0.9.1 + gopkg.in/yaml.v2 v2.4.0 +) + +require ( + github.com/Wessie/appdirs v0.0.0-20141031215813-6573e894f8e2 // indirect + github.com/bitly/go-simplejson v0.5.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/felixge/httpsnoop v1.0.1 // indirect + github.com/flopp/go-coordsparser v0.0.0-20201115094714-8baaeb7062d5 // indirect + github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect + github.com/gorilla/mux v1.7.3 // indirect + github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect + github.com/peter-mount/go.uuid v1.2.1-0.20180103174451-36e9d2ebbde5 // indirect github.com/stretchr/testify v1.4.0 // indirect + github.com/tkrajina/gpxgo v1.0.1 // indirect + golang.org/x/image v0.0.0-20210216034530-4410531fe030 // indirect golang.org/x/net v0.0.0-20190923162816-aa69164e4478 // indirect - gonum.org/v1/gonum v0.9.1 + golang.org/x/sys v0.0.0-20210304124612-50617c2ba197 // indirect + golang.org/x/text v0.3.5 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect - gopkg.in/yaml.v2 v2.2.2 + gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5 // indirect ) diff --git a/ldb/bin/main.go b/ldb/bin/main.go index fbf1d65..5b1bec2 100644 --- a/ldb/bin/main.go +++ b/ldb/bin/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/peter-mount/go-kernel" + "github.com/peter-mount/go-kernel/v2" "github.com/peter-mount/nre-feeds/bin" "github.com/peter-mount/nre-feeds/ldb/service" "log" diff --git a/ldb/service/restService.go b/ldb/service/restService.go index 346bd77..ab888ba 100644 --- a/ldb/service/restService.go +++ b/ldb/service/restService.go @@ -1,7 +1,7 @@ package service import ( - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2/rest" "github.com/peter-mount/nre-feeds/darwind3" d3client "github.com/peter-mount/nre-feeds/darwind3/client" "github.com/peter-mount/nre-feeds/darwinref" diff --git a/ldb/service/restStation.go b/ldb/service/restStation.go index 6b825e1..8ef8f94 100644 --- a/ldb/service/restStation.go +++ b/ldb/service/restStation.go @@ -1,7 +1,7 @@ package service import ( - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2/rest" "github.com/peter-mount/nre-feeds/darwind3" d3client "github.com/peter-mount/nre-feeds/darwind3/client" "github.com/peter-mount/nre-feeds/darwinref" diff --git a/ldb/service/service.go b/ldb/service/service.go index be9b887..944ed0b 100644 --- a/ldb/service/service.go +++ b/ldb/service/service.go @@ -2,9 +2,9 @@ package service import ( "github.com/gorilla/handlers" - "github.com/peter-mount/go-kernel" - "github.com/peter-mount/go-kernel/cron" - "github.com/peter-mount/go-kernel/rest" + "github.com/peter-mount/go-kernel/v2" + "github.com/peter-mount/go-kernel/v2/cron" + "github.com/peter-mount/go-kernel/v2/rest" "github.com/peter-mount/nre-feeds/bin" "github.com/peter-mount/nre-feeds/darwind3" "github.com/peter-mount/nre-feeds/ldb" diff --git a/test.sh b/test.sh index ebc303c..cd97fd0 100755 --- a/test.sh +++ b/test.sh @@ -7,6 +7,7 @@ MODULE=ldb #MODULE=darwinkb #MODULE=darwindb +#MODULE=darwinkb # db directory DB=/home/peter/tmp/nre @@ -32,14 +33,10 @@ ARGS="$ARGS test:${MODULE}-amd64-latest" echo $ARGS -./build.sh test amd64 latest ${MODULE} &&\ -exec docker run $ARGS - +./build.sh test amd64 latest ${MODULE} +exit 0 -{"Type":"timeTableUpdate","TimeTableId":{"timeTableId":"20190617020748","ttfile":"20190617020748_v8.xml.gz"}} - -{"Type":"timeTableUpdate","TimeTableId":{"timeTableId":"20190617020748","ttfile":"20190617020748_v7.xml.gz"}} - -{"Type":"timeTableUpdate","TimeTableId":{"timeTableId":"20190617020748","ttreffile":"20190615020704_ref_v3.xml.gz"}} +# &&\ +exec docker run $ARGS diff --git a/xmas/bin/main.go b/xmas/bin/main.go index 6059056..17967a5 100644 --- a/xmas/bin/main.go +++ b/xmas/bin/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/peter-mount/go-kernel" + "github.com/peter-mount/go-kernel/v2" "github.com/peter-mount/nre-feeds/xmas" "log" ) diff --git a/xmas/xmas.go b/xmas/xmas.go index 4d1c663..de34433 100644 --- a/xmas/xmas.go +++ b/xmas/xmas.go @@ -3,7 +3,7 @@ package xmas import ( "errors" "flag" - "github.com/peter-mount/go-kernel" + "github.com/peter-mount/go-kernel/v2" "github.com/peter-mount/nre-feeds/util" "time" ) From 01f51fbf97b0abe446c9a325f8bdbba9aa528faa Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 26 Jan 2023 20:00:27 +0000 Subject: [PATCH 05/11] Update to new unified build environment --- Go.include | 104 ++++++++++++++++++ Makefile | 72 ++++++++++++ Makefile.include | 26 +++++ {darwind3 => tools/darwind3}/bin/main.go | 0 {darwindb => tools/darwindb}/bin/main.go | 0 .../darwingraph}/bin/main.go | 0 {darwinkb => tools/darwinkb}/bin/main.go | 0 {darwinref => tools/darwinref}/bin/main.go | 0 .../darwintimetable}/bin/main.go | 0 version.go | 3 + 10 files changed, 205 insertions(+) create mode 100644 Go.include create mode 100644 Makefile create mode 100644 Makefile.include rename {darwind3 => tools/darwind3}/bin/main.go (100%) rename {darwindb => tools/darwindb}/bin/main.go (100%) rename {darwingraph => tools/darwingraph}/bin/main.go (100%) rename {darwinkb => tools/darwinkb}/bin/main.go (100%) rename {darwinref => tools/darwinref}/bin/main.go (100%) rename {darwintimetable => tools/darwintimetable}/bin/main.go (100%) create mode 100644 version.go diff --git a/Go.include b/Go.include new file mode 100644 index 0000000..065ac0f --- /dev/null +++ b/Go.include @@ -0,0 +1,104 @@ + +# Extract args from platform definition. +# Here PLATFORM is os:arch:arm, usually arm is "" unless arch=="arm" when it +# is then one of "5","6" or "7" +GO-OS =$(word 1,$(subst :, ,$(PLATFORM))) +GO-ARCH =$(word 2,$(subst :, ,$(PLATFORM))) +GO-ARM =$(word 3,$(subst :, ,$(PLATFORM))) +GO-ARCH-DIR =$(call GO-OS,$1)/$(call GO-ARCH,$1)$(call GO-ARM,$1) + +# $(call GO-BUILD,platform,destination,src) +GO-BUILD = $(call cmd,"GO BUILD","$(subst /, ,$(call GO-ARCH-DIR,$1)) $(shell basename $2)");\ + mkdir -p $(shell dirname $2);\ + CGO_ENABLED=0 GOOS=$(call GO-OS,$1) GOARCH=$(call GO-ARCH,$1) GOARM=$(GO-ARM,$1) \ + go build \ + -ldflags="-X '$(PACKAGE_PREFIX).Version=$(shell basename $2) ($(VERSION) $(subst /, ,$(call GO-ARCH-DIR,$1)) $(shell id -u -n) $(shell date))'" \ + -o $2 \ + $3 + +GO-CLEAN = $(call cmd,"GO CLEAN",$1);go clean $1 +GO-MOD = $(call cmd,"GO MOD",$1);go mod $1 + +# Append -test.v to GO_TEST to show status of each test. +# Without it, only shows total time per module if they pass +GO-TEST = $(GO_TEST)$(call cmd,"GO TEST",$1);(cd $1;go test ./...) + +# Init goInit +.PHONY: go-init +go-init: validate-go-version resolve-platforms + $(call GO-MOD,download) + +# Target to run all tests, results into builds directory +.PHONY: go-test +go-test: + @mkdir -p $(BUILDS) + $(call cmd,"GO TEST",$(BUILDS)/go-test.txt);go test ./... >$(BUILDS)/go-test.txt 2>&1 || cat $(BUILDS)/go-test.txt + +# Rule to build a go application +# For this to work: the main function is in tools//bin/main.go +# The compiled binary will be placed in $(BUILDS)/// +$(BUILDS)/%: tools/%/bin/main.go + $(foreach PLATFORM,$(PLATFORMS),\ + $(call GO-BUILD,$(PLATFORM),$(BUILDS)/$(call GO-ARCH-DIR,$(PLATFORM))/$(BINDIR)$(shell basename $@),$<)${\n}\ + ) + +# Validates the installed version of go against the version declared in go.mod +MINIMUM_SUPPORTED_GO_MAJOR_VERSION = $(shell grep "^go" go.mod | cut -f2 -d' ' | cut -f1 -d'.') +MINIMUM_SUPPORTED_GO_MINOR_VERSION = $(shell grep "^go" go.mod | cut -f2 -d' ' | cut -f2 -d'.') +GO_MAJOR_VERSION = $(shell go version | cut -f3 -d' ' | cut -c 3- | cut -f1 -d' ' | cut -f1 -d'.') +GO_MINOR_VERSION = $(shell go version | cut -f3 -d' ' | cut -c 3- | cut -f1 -d' ' | cut -f2 -d'.') +GO_VERSION_VALIDATION_ERR_MSG = Golang version $(GO_MAJOR_VERSION).$(GO_MINOR_VERSION) is not supported, please update to at least $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION).$(MINIMUM_SUPPORTED_GO_MINOR_VERSION) +.PHONY: validate-go-version +validate-go-version: + @if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \ + exit 0 ;\ + elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \ + $(ECHO) '$(GO_VERSION_VALIDATION_ERR_MSG)';\ + exit 1; \ + elif [ $(GO_MINOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \ + $(ECHO) '$(GO_VERSION_VALIDATION_ERR_MSG)';\ + exit 1; \ + fi + +# This discovers all platforms supported by the locally installed go compiler. +# This will only expand then if the PLATFORMS environment variable was not set +# when invoking make +.PHONY: resolve-platforms +resolve-platforms: +ifeq ("$(PLATFORMS)","") + $(eval DISC_PLATFORMS=) + $(foreach DISC_PLATFORM,$(shell go tool dist list), \ + $(eval GOOS=$(word 1,$(subst /, ,$(DISC_PLATFORM)))) \ + $(if $(filter android,$(GOOS)),,\ + $(if $(filter ios,$(GOOS)),,\ + $(eval GOARCH=$(word 2,$(subst /, ,$(DISC_PLATFORM)))) \ + $(foreach GOARM, \ + $(if $(filter arm,$(GOARCH)),6 7,:), \ + $(eval DISC_PLATFORMS=$(DISC_PLATFORMS) $(GOOS):$(GOARCH):$(GOARM)) \ + ) \ + )\ + )\ + ) + $(eval export PLATFORMS=$(DISC_PLATFORMS)) +endif + +# Generates platforms.md based on the local go installation. +# This does nothing other than keep that page in sync with what is currently +# supported by go and the build system. +platforms.md: resolve-platforms + $(shell ( \ + echo "# Supported Platforms"; \ + echo; \ + echo "The following platforms are supported by virtue of how the build system works:"; \ + echo; \ + echo "| Operating System | CPU Architectures |"; \ + echo "| ---------------- | ----------------- |"; \ + $(foreach OS, $(shell ls $(BUILDS)), echo "| $(OS) | $(foreach ARCH,$(shell ls $(BUILDS)/$(OS)),$(ARCH)) |"; ) \ + echo; \ + echo "Operating Systems: $(shell ls $(BUILDS)|wc -l) CPU Architectures: $(shell ls -d $(BUILDS)/*/*| cut -f3 -d'/' | sort |uniq | wc -l)"; \ + echo; \ + echo "This is all non-mobile platforms supported by go version \`$(GO_MAJOR_VERSION).$(GO_MINOR_VERSION)\`" ;\ + echo; \ + echo "This page is automatically generated from the output of \`go tool dist list\`"; \ + ) >$@ \ + ) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..149ff9c --- /dev/null +++ b/Makefile @@ -0,0 +1,72 @@ +# +# By default this will build the project on every non-mobile platform +# supported by the installed go environment. +# +# To limit a build to a single environment, you can force it to just a +# single platform by prefixing make with: +# +# PLATFORMS=linux:amd64: make clean all +# +# Just change the entry for your OS and CPU. These are listed in platforms.md +# +# Note: For 32 bit arm processors the 3rd parameter is important. +# e.g. use linux:arm:6 or linux:arm:7 +# +# For all other processors, including arm64, leave the third field blank. +# +# To disable tests, you can prefix make with: +# +# GO_TEST="#" make clean all +# +# The quotes are important! +# +# You can combine the two as necessary. +# +# e.g. GO_TEST="#" PLATFORMS=linux:amd64: make clean all +# +# For a parallel builds you can use the -j parameter to make as usual. +# +# e.g.: make -j 8 clean all +# +# Pick a value suitable to the number of cores/thread your machine has. +# This is useful for a full build of all platforms as it will build all +# of the binaries in parallel speeding up the full build. +# + +# The repository name/package prefix. +# This should match the value of module in go.mod +PACKAGE_PREFIX = $(shell grep ^module go.mod | cut -f2 -d' ' | head -1) +PACKAGE_NAME = $(shell basename $(PACKAGE_PREFIX)) +VERSION ?= $(shell git describe --tags --always --dirty --match=v* 2> /dev/null | sed "s/-/./g") +DIST_PREFIX = $(PACKAGE_NAME)_$(VERSION) +BUILD_DATE = $(shell date) + +# Where to place build artifacts. These must be subdirectories here and not +# a path elsewhere, otherwise it will break the build! +BUILDS = builds +DIST = dist + +# BINDIR is the prefix before any built tools. Set to "" for none, otherwise +# it must end with / +BINDIR ?= bin/ + +.PHONY: all clean init test tools dist + +all: init test tools + +include Makefile.include +include Go.include + +clean: + $(call GO-CLEAN,-testcache) + $(call REMOVE,$(BUILDS) $(DIST)) + +init: go-init + +test: go-test + +tools: $(subst /bin/main.go,,$(subst tools,$(BUILDS),$(shell ls tools/*/bin/main.go))) + +dist: all + $(MKDIR) $(DIST) + $(foreach PLATFORM,$(shell cd $(BUILDS);ls -d */*),$(call TAR,$(PLATFORM))${\n}) diff --git a/Makefile.include b/Makefile.include new file mode 100644 index 0000000..8761d5d --- /dev/null +++ b/Makefile.include @@ -0,0 +1,26 @@ + +cmd = @set -e;printf "%-8s %s\n" $1 $2 + +# Tool names +CP = @cp -p +ECHO = echo + +MKDIR = @mkdir -p $1 + +# limited to 5 entries as no way to get all args +REMOVE = $(call cmd,"RM","$1");set +e;rm -rf $1 + +TAR = @$(eval TARFILE=$(DIST_PREFIX)-$(shell echo $1 | sed "s|/|_|g").tgz)${\n}\ + @$(eval BUILD=$(BUILDS)/$1)${\n}\ + $(call cmd,"TAR",$(TARFILE));\ + mkdir -p $(DIST);\ + tar -P --transform "s|^$(BUILD)|$(PACKAGE_NAME)|" -czpf $(DIST)/$(TARFILE) $(BUILD) + +PRINTF = printf + +# Used to separate commands in foreach. +# NOTE this MUST have 2 empty lines between define and endef for it to work! +define \n + + +endef diff --git a/darwind3/bin/main.go b/tools/darwind3/bin/main.go similarity index 100% rename from darwind3/bin/main.go rename to tools/darwind3/bin/main.go diff --git a/darwindb/bin/main.go b/tools/darwindb/bin/main.go similarity index 100% rename from darwindb/bin/main.go rename to tools/darwindb/bin/main.go diff --git a/darwingraph/bin/main.go b/tools/darwingraph/bin/main.go similarity index 100% rename from darwingraph/bin/main.go rename to tools/darwingraph/bin/main.go diff --git a/darwinkb/bin/main.go b/tools/darwinkb/bin/main.go similarity index 100% rename from darwinkb/bin/main.go rename to tools/darwinkb/bin/main.go diff --git a/darwinref/bin/main.go b/tools/darwinref/bin/main.go similarity index 100% rename from darwinref/bin/main.go rename to tools/darwinref/bin/main.go diff --git a/darwintimetable/bin/main.go b/tools/darwintimetable/bin/main.go similarity index 100% rename from darwintimetable/bin/main.go rename to tools/darwintimetable/bin/main.go diff --git a/version.go b/version.go new file mode 100644 index 0000000..e3b69ff --- /dev/null +++ b/version.go @@ -0,0 +1,3 @@ +package common + +var Version string From 38a85cfe7966a788c744b734a3d02db5dce50458 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 26 Jan 2023 21:44:04 +0000 Subject: [PATCH 06/11] Filter out some platforms due to bbolt not supported & disabled darwingraph which isn't ready & doesn't work on some platforms either --- Go.include | 19 +++++++++++++++++-- go.mod | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Go.include b/Go.include index 065ac0f..ddd9cc8 100644 --- a/Go.include +++ b/Go.include @@ -31,12 +31,17 @@ go-init: validate-go-version resolve-platforms # Target to run all tests, results into builds directory .PHONY: go-test go-test: - @mkdir -p $(BUILDS) + $(MKDIR) $(BUILDS) $(call cmd,"GO TEST",$(BUILDS)/go-test.txt);go test ./... >$(BUILDS)/go-test.txt 2>&1 || cat $(BUILDS)/go-test.txt # Rule to build a go application # For this to work: the main function is in tools//bin/main.go # The compiled binary will be placed in $(BUILDS)/// + +# This takes precedence of the main one, it allows us to ignore a tool if the .donotbuild file exists +$(BUILDS)/%: tools/%/bin/main.go tools/%/.donotbuild + $(call cmd,"IGNORE",$(shell basename $@)) + $(BUILDS)/%: tools/%/bin/main.go $(foreach PLATFORM,$(PLATFORMS),\ $(call GO-BUILD,$(PLATFORM),$(BUILDS)/$(call GO-ARCH-DIR,$(PLATFORM))/$(BINDIR)$(shell basename $@),$<)${\n}\ @@ -64,6 +69,8 @@ validate-go-version: # This will only expand then if the PLATFORMS environment variable was not set # when invoking make .PHONY: resolve-platforms +# For now filter out various platforms due to: +# incompatibilities with bbolt (missing syscalls) resolve-platforms: ifeq ("$(PLATFORMS)","") $(eval DISC_PLATFORMS=) @@ -74,7 +81,15 @@ ifeq ("$(PLATFORMS)","") $(eval GOARCH=$(word 2,$(subst /, ,$(DISC_PLATFORM)))) \ $(foreach GOARM, \ $(if $(filter arm,$(GOARCH)),6 7,:), \ - $(eval DISC_PLATFORMS=$(DISC_PLATFORMS) $(GOOS):$(GOARCH):$(GOARM)) \ + $(if $(filter loong64,$(GOARCH)),,\ + $(if $(filter aix,$(GOOS)),,\ + $(if $(filter js,$(GOOS)),,\ + $(if $(filter plan9,$(GOOS)),,\ + $(eval DISC_PLATFORMS=$(DISC_PLATFORMS) $(GOOS):$(GOARCH):$(GOARM)) \ + )\ + )\ + )\ + )\ ) \ )\ )\ diff --git a/go.mod b/go.mod index 192103c..365512d 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 github.com/gorilla/handlers v1.5.1 github.com/jlaffaye/ftp v0.0.0-20190828173736-6aaa91c7796e - github.com/lib/pq v1.2.0 + github.com/lib/pq v1.10.4 github.com/peter-mount/filecache v0.0.0-20190909121939-281dcdcbbbfd github.com/peter-mount/go-kernel/v2 v2.0.2 github.com/peter-mount/golib v0.0.0-20190924084925-7f296a747319 From fb91626ce27b84a68d03d634404ad2b829b2f5fc Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 5 Apr 2023 13:54:46 +0100 Subject: [PATCH 07/11] Add telstar support --- .dockerignore | 10 +- .gitignore | 1 - Docker.include | 115 +++++++++++++++++++ Dockerfile | 95 +-------------- Go.include | 33 ++++-- Makefile | 28 +++-- Makefile.include | 10 +- tools/darwintelstar/bin/main.go | 14 +++ tools/darwintelstar/telstar.go | 113 ++++++++++++++++++ util/telstar/frame.go | 198 ++++++++++++++++++++++++++++++++ util/telstar/frameBuilder.go | 120 +++++++++++++++++++ util/telstar/response.go | 120 +++++++++++++++++++ 12 files changed, 740 insertions(+), 117 deletions(-) create mode 100644 Docker.include create mode 100644 tools/darwintelstar/bin/main.go create mode 100644 tools/darwintelstar/telstar.go create mode 100644 util/telstar/frame.go create mode 100644 util/telstar/frameBuilder.go create mode 100644 util/telstar/response.go diff --git a/.dockerignore b/.dockerignore index 252188d..383f7e6 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,7 +1,3 @@ -.git -.idea -go_* -Dockerfile* -config*.yaml -*.cif -# go.sum +# Exclude absolutely everything then negate rules on what we want to be sent to docker for the build +* +!builds diff --git a/.gitignore b/.gitignore index 1a06216..b4a00d0 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,6 @@ docs Dockerfile.* *.iml -Dockerfile.* config.yaml .idea go.sum diff --git a/Docker.include b/Docker.include new file mode 100644 index 0000000..e0c8bfc --- /dev/null +++ b/Docker.include @@ -0,0 +1,115 @@ +# Makefile extensions for docker containers + +DOCKER_IMAGE ?= test:latest +DOCKER_BUILDER ?= builder + +BUILDX = docker buildx + +DOCKER-RM = $(call cmd,"BLDX RM",$(DOCKER_BUILDER)); $(BUILDX) rm $(DOCKER_BUILDER) || true + +DOCKER-CREATE = $(call cmd,"BLDX CREATE",$(DOCKER_BUILDER));\ + $(BUILDX) inspect $(DOCKER_BUILDER) >/dev/null 2>&1 || $(BUILDX) create --name $(DOCKER_BUILDER) --driver docker-container --bootstrap + +DOCKER-SWITCH = $(call cmd,"BLDX USE",$(DOCKER_BUILDER));\ + $(BUILDX) use $(DOCKER_BUILDER) + +DOCKER-BUILDX = $(call cmd,"BLDX BUILD",$1);\ + $(BUILDX) build --platform $2 -t $1 --push . + +targets-init += docker-init +.PHONY: docker-init +docker-init: + $(DOCKER-CREATE) + $(DOCKER-SWITCH) + +targets-real-clean += docker-real-clean +.PHONY: docker-real-clean +docker-real-clean: + $(DOCKER-RM) + +targets-dist += docker-dist +.PHONY: docker-tools +docker-dist: init + $(call DOCKER-BUILDX,$(DOCKER-TAG),"$(shell $(BUILDX) inspect $(DOCKER_BUILDER) | grep Platforms | cut -f2- -d ':'|sed -e "s/ //g")",".") + +docker-version = $(shell printf '%02d' $(shell echo "$1" | tr . ' ' | sed -e "s/ 0*/ /g") 2>/dev/null) + +resolve-platforms = resolve-docker-platforms +.PHONY: resolve-docker-platforms +resolve-docker-platforms: +ifeq ("$(PLATFORMS)","") + $(call cmd,"BLDX INSPCT",$(DOCKER_BUILDER)) + $(eval DISC_PLATFORMS=) + $(eval export PLATFORMS=$(foreach PLATFORM,\ + $(shell $(BUILDX) inspect $(DOCKER_BUILDER) | grep Platforms | cut -f2- -d ':'|sed -e "s/ //g" -e "s/,/ /g"),\ + $(eval GOOS=$(word 1,$(subst /, ,$(PLATFORM))))\ + $(eval GOARCH=$(word 2,$(subst /, ,$(PLATFORM))))\ + $(eval GOARM=$(shell echo -n $(word 3,$(subst /, ,$(PLATFORM))) | sed -e "s/v2//" -e "s/v//" ))\ + $(eval DISC_PLATFORMS=$(DISC_PLATFORMS) $(GOOS):$(GOARCH):$(GOARM)) \ + )) + $(eval export PLATFORMS=$(DISC_PLATFORMS)) +endif + +# Verify qemu is correct +targets-validate += validate-docker-version +.PHONY: validate-docker-version +validate-docker-version: + $(call cmd,"CHECK-VERSN","docker") + @if ! command -v docker >/dev/null 2>&1; then \ + $(ECHO) "Can't find docker. Install with 'sudo apt-get install docker-ce' or docker.io.";\ + exit 1;\ + fi + + $(eval docker_version="$(shell docker --version | cut -d' ' -f3 | tr -cd '0-9.')") + @if [ $(call docker-version,$(docker_version)) -lt "19" ]; then \ + $(ECHO) "docker $(docker_version) too old. Need >= 19.03";\ + exit 1;\ + fi + + @if [ $(shell docker version | grep Experimental: | grep -c true) -eq 0 ]; then\ + $(ECHO) "docker experimental flag not enabled: Set with 'export DOCKER_CLI_EXPERIMENTAL=enabled'";\ + exit 1; \ + fi + + $(call cmd,"CHECK-VERSN","kernel") + $(eval kernel_version="$(shell uname -r|cut -f1 -d'-')") + @if [ $(call docker-version,$(kernel_version)) -lt $(call docker-version,'4.8') ]]; then\ + $(ECHO) "Kernel $(kernel_version) too old - need >= 4.8. Install a newer kernel.";\ + exit 1; \ + fi + + $(call cmd,"CHECK-VERSN","binfmt_misc") + @if [ $(shell mount | grep -c /proc/sys/fs/binfmt_misc) -eq 0 ]; then\ + $(ECHO) "/proc/sys/fs/binfmt_misc not mounted. Mount with 'sudo mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc'";\ + exit 1; \ + fi + + @if ! command -v update-binfmts >/dev/null 2>&1; then\ + $(ECHO) "Can't find update-binfmts. Install with 'sudo apt-get install binfmt-support'.";\ + exit 1; \ + fi + + $(eval binfmt_version="$(shell update-binfmts --version | cut -f2 -d' ')") + @if [ $(call docker-version,$(binfmt_version)) -lt $(call docker-version,"2.2") ]; then\ + $(ECHO) "update-binfmts $(binfmt_version) too old. Need >= 2.1.7";\ + exit 1; \ + fi + + $(call cmd,"CHECK-VERSN","qemu-aarch64") + @if [ ! -e /proc/sys/fs/binfmt_misc/qemu-aarch64 ]; then\ + if [ ! -e /usr/bin/qemu-aarch64-static ]; then\ + $(ECHO) "Missing QEMU. Install with 'sudo apt-get install qemu-user-static'.";\ + exit 1;\ + fi;\ + fi + + @if [ ! -e '/proc/sys/fs/binfmt_misc/qemu-aarch64' ]; then\ + $(ECHO) 'QEMU not registered in binfmt_misc.';\ + exit 1;\ + fi + + $(eval qemu_flags="$(shell grep flags: /proc/sys/fs/binfmt_misc/qemu-aarch64 2>/dev/null | cut -d' ' -f2)") + @if [ $(shell echo $(qemu_flags) | grep -c F) -eq 0 ]; then\ + $(ECHO) 'QEMU not registered in binfmt_misc with fix-binary (F) flag.';\ + exit 1;\ + fi diff --git a/Dockerfile b/Dockerfile index 6ad19e8..795347c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,90 +1,5 @@ -ARG arch=amd64 -ARG goos=linux - -# ============================================================ -# Build container containing our pre-pulled libraries. -# As this changes rarely it means we can use the cache between -# building each microservice. -FROM golang:alpine as build - -# The golang alpine image is missing git so ensure we have additional tools -RUN apk add --no-cache \ - curl \ - git \ - tzdata \ - zip - -WORKDIR /work -COPY go.mod . -RUN go mod download - -# ============================================================ -# source container contains the source as it exists within the -# repository. -FROM build as source -WORKDIR /work -ADD . . - -# ============================================================ -# Run all tests in a new container so any output won't affect -# the final build. -FROM source as test -RUN CGO_ENABLED=0 go test -v \ - ./util \ - ./darwinref \ - ./darwind3 \ - ./ldb \ - ./issues - -# ============================================================ -# Compile the source. -FROM source as compiler -ARG module= -ARG arch -ARG goos -ARG goarch -ARG goarm -WORKDIR /work - -# NB: CGO_ENABLED=0 forces a static build -RUN PACKAGE=${module};\ - if [ "$PACKAGE" = "darwintt" ];\ - then\ - PACKAGE="darwintimetable";\ - fi;\ - echo "Building ${module} as ${PACKAGE}";\ - CGO_ENABLED=0 \ - GOOS=${goos} \ - GOARCH=${goarch} \ - GOARM=${goarm} \ - go build \ - -o /dest/${module} \ - ./${PACKAGE}/bin - -# ============================================================ -# Optional stage, upload the binaries as a tar file -FROM compiler AS upload -ARG uploadPath= -ARG uploadCred= -ARG uploadName= -RUN if [ -n "${uploadCred}" -a -n "${uploadPath}" -a -n "${uploadName}" ] ;\ - then \ - cd /dest; \ - tar cvzpf /tmp/${uploadName}.tgz * && \ - zip /tmp/${uploadName}.zip * && \ - curl -u ${uploadCred} --upload-file /tmp/${uploadName}.tgz ${uploadPath}/ && \ - curl -u ${uploadCred} --upload-file /tmp/${uploadName}.zip ${uploadPath}/; \ - fi - -# ============================================================ -# Finally build the final runtime container for the specific -# microservice -FROM alpine -RUN apk add --no-cache \ - curl \ - tzdata - -COPY --from=compiler /dest/ /usr/bin/ - -ENTRYPOINT ["@@entrypoint@@"] -CMD [ "-c", "/config.yaml"] +# syntax=docker/dockerfile:1 +FROM --platform=$BUILDPLATFORM golang:alpine AS build +ARG TARGETPLATFORM +ARG BUILDPLATFORM +RUN echo "Running on $BUILDPLATFORM, building for $TARGETPLATFORM" >/log diff --git a/Go.include b/Go.include index ddd9cc8..9aa03f6 100644 --- a/Go.include +++ b/Go.include @@ -23,17 +23,28 @@ GO-MOD = $(call cmd,"GO MOD",$1);go mod $1 # Without it, only shows total time per module if they pass GO-TEST = $(GO_TEST)$(call cmd,"GO TEST",$1);(cd $1;go test ./...) +targets-clean += go-clean +.PHONY: go-clean +go-clean: + $(call GO-CLEAN,-testcache) + # Init goInit +targets-init += go-init .PHONY: go-init -go-init: validate-go-version resolve-platforms +go-init: $(call GO-MOD,download) # Target to run all tests, results into builds directory +targets-test += go-test .PHONY: go-test go-test: $(MKDIR) $(BUILDS) $(call cmd,"GO TEST",$(BUILDS)/go-test.txt);go test ./... >$(BUILDS)/go-test.txt 2>&1 || cat $(BUILDS)/go-test.txt +targets-tools += go-tools +.PHONY: go-tools +go-tools: $(subst /bin/main.go,,$(subst tools,$(BUILDS),$(shell ls tools/*/bin/main.go))) + # Rule to build a go application # For this to work: the main function is in tools//bin/main.go # The compiled binary will be placed in $(BUILDS)/// @@ -53,8 +64,10 @@ MINIMUM_SUPPORTED_GO_MINOR_VERSION = $(shell grep "^go" go.mod | cut -f2 -d' ' | GO_MAJOR_VERSION = $(shell go version | cut -f3 -d' ' | cut -c 3- | cut -f1 -d' ' | cut -f1 -d'.') GO_MINOR_VERSION = $(shell go version | cut -f3 -d' ' | cut -c 3- | cut -f1 -d' ' | cut -f2 -d'.') GO_VERSION_VALIDATION_ERR_MSG = Golang version $(GO_MAJOR_VERSION).$(GO_MINOR_VERSION) is not supported, please update to at least $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION).$(MINIMUM_SUPPORTED_GO_MINOR_VERSION) +targets-validate += validate-go-version .PHONY: validate-go-version validate-go-version: + $(call cmd,"CHECK_VERSN","go") @if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \ exit 0 ;\ elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \ @@ -68,10 +81,12 @@ validate-go-version: # This discovers all platforms supported by the locally installed go compiler. # This will only expand then if the PLATFORMS environment variable was not set # when invoking make -.PHONY: resolve-platforms +# # For now filter out various platforms due to: # incompatibilities with bbolt (missing syscalls) -resolve-platforms: +resolve-platforms = resolve-go-platforms +.PHONY: resolve-go-platforms +resolve-go-platforms: ifeq ("$(PLATFORMS)","") $(eval DISC_PLATFORMS=) $(foreach DISC_PLATFORM,$(shell go tool dist list), \ @@ -79,12 +94,12 @@ ifeq ("$(PLATFORMS)","") $(if $(filter android,$(GOOS)),,\ $(if $(filter ios,$(GOOS)),,\ $(eval GOARCH=$(word 2,$(subst /, ,$(DISC_PLATFORM)))) \ - $(foreach GOARM, \ - $(if $(filter arm,$(GOARCH)),6 7,:), \ - $(if $(filter loong64,$(GOARCH)),,\ - $(if $(filter aix,$(GOOS)),,\ - $(if $(filter js,$(GOOS)),,\ - $(if $(filter plan9,$(GOOS)),,\ + $(if $(filter loong64,$(GOARCH)),,\ + $(if $(filter aix,$(GOOS)),,\ + $(if $(filter js,$(GOOS)),,\ + $(if $(filter plan9,$(GOOS)),,\ + $(foreach GOARM, \ + $(if $(filter arm,$(GOARCH)),6 7,:), \ $(eval DISC_PLATFORMS=$(DISC_PLATFORMS) $(GOOS):$(GOARCH):$(GOARM)) \ )\ )\ diff --git a/Makefile b/Makefile index 149ff9c..6d246e9 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,9 @@ VERSION ?= $(shell git describe --tags --always --dirty --match=v* 2> /dev/null DIST_PREFIX = $(PACKAGE_NAME)_$(VERSION) BUILD_DATE = $(shell date) +DOCKER-REPOSITORY = docker.europa.area51.dev/ +DOCKER-TAG = $(DOCKER-REPOSITORY)$(PACKAGE_NAME):$(if $(filter dirty,$(VERSION)),"latest",$(VERSION)) + # Where to place build artifacts. These must be subdirectories here and not # a path elsewhere, otherwise it will break the build! BUILDS = builds @@ -50,23 +53,34 @@ DIST = dist # it must end with / BINDIR ?= bin/ -.PHONY: all clean init test tools dist +.PHONY: all clean init test tools dist real-clean all: init test tools include Makefile.include include Go.include +include Docker.include -clean: - $(call GO-CLEAN,-testcache) +clean: $(targets-clean) $(call REMOVE,$(BUILDS) $(DIST)) -init: go-init +real-clean: clean $(targets-real-clean) -test: go-test +init: $(targets-validate) $(resolve-platforms) $(targets-init) + @$(ECHO) "$(PLATFORMS)" -tools: $(subst /bin/main.go,,$(subst tools,$(BUILDS),$(shell ls tools/*/bin/main.go))) +test: $(targets-test) -dist: all +tools: $(targets-tools) + +dist1: all $(MKDIR) $(DIST) $(foreach PLATFORM,$(shell cd $(BUILDS);ls -d */*),$(call TAR,$(PLATFORM))${\n}) + +dist: all + $(foreach PLATFORM,$(shell cd $(BUILDS);ls -d */*),@$(MAKE) $(DIST)/$(call TAR-FILE,$(PLATFORM)){\n}) + @$(MAKE) $(targets-dist) + +$(DIST)/$(PACKAGE_NAME)_$(VERSION)-%.tgz: builds/$(subst _,/,%) + $(MKDIR) $(DIST) + echo "$@ $<" diff --git a/Makefile.include b/Makefile.include index 8761d5d..4c90e26 100644 --- a/Makefile.include +++ b/Makefile.include @@ -1,5 +1,5 @@ -cmd = @set -e;printf "%-8s %s\n" $1 $2 +cmd = @set -e;printf "%-12s %s\n" $1 $2 # Tool names CP = @cp -p @@ -10,8 +10,10 @@ MKDIR = @mkdir -p $1 # limited to 5 entries as no way to get all args REMOVE = $(call cmd,"RM","$1");set +e;rm -rf $1 -TAR = @$(eval TARFILE=$(DIST_PREFIX)-$(shell echo $1 | sed "s|/|_|g").tgz)${\n}\ - @$(eval BUILD=$(BUILDS)/$1)${\n}\ +TAR-FILE = $(DIST_PREFIX)-$(shell echo $1 | sed "s|/|_|g").tgz + +TAR = @$(eval TARFILE=$(call TAR-FILE,$1))\ + @$(eval BUILD=$(BUILDS)/$1)\ $(call cmd,"TAR",$(TARFILE));\ mkdir -p $(DIST);\ tar -P --transform "s|^$(BUILD)|$(PACKAGE_NAME)|" -czpf $(DIST)/$(TARFILE) $(BUILD) @@ -24,3 +26,5 @@ define \n endef + +targets-init = diff --git a/tools/darwintelstar/bin/main.go b/tools/darwintelstar/bin/main.go new file mode 100644 index 0000000..d9dc90e --- /dev/null +++ b/tools/darwintelstar/bin/main.go @@ -0,0 +1,14 @@ +package main + +import ( + "github.com/peter-mount/go-kernel/v2" + telstar "github.com/peter-mount/nre-feeds/tools/darwintelstar" + "log" +) + +func main() { + err := kernel.Launch(&telstar.Telstar{}) + if err != nil { + log.Fatal(err) + } +} diff --git a/tools/darwintelstar/telstar.go b/tools/darwintelstar/telstar.go new file mode 100644 index 0000000..ae93695 --- /dev/null +++ b/tools/darwintelstar/telstar.go @@ -0,0 +1,113 @@ +package telstar + +import ( + "fmt" + "github.com/peter-mount/nre-feeds/ldb/client" + "github.com/peter-mount/nre-feeds/ldb/service" + "github.com/peter-mount/nre-feeds/util/telstar" +) + +type Telstar struct { + PageNumber *int `kernel:"flag,page,Page number"` + Crs *string `kernel:"flag,crs,crs"` +} + +func (t *Telstar) Start() error { + /*if *t.PageNumber > 0 { + return t.boards() + }*/ + if len(*t.Crs) == 3 { + return t.crs(*t.Crs) + } + return nil +} + +func (t *Telstar) boards() error { + pn := *t.PageNumber + var crsa []byte + for pn > 64 { + crsa = append([]byte{byte(pn % 100)}, crsa...) + pn = pn / 100 + } + return t.crs(string(crsa)) +} + +func (t *Telstar) crs(crs string) error { + + crs = "LBG" + + cl := client.DarwinLDBClient{Url: "https://ldb.prod.a51.li"} + result, err := cl.GetSchedule(crs) + if err != nil { + return err + } + + response := telstar.NewResponse(). + Dynamic(). + PageNumber(*t.PageNumber). + FrameId('a') + + f := newDepartureFrame(response, result) + + for _, m := range result.Messages { + + f.NewLine(). + Print(m.Message) + + f.Build() + f = newDepartureFrame(response, result) + } + + count := 0 + for _, departure := range result.Services { + + loc := departure.Location + if !loc.IsDestination() { + + if count > 0 && (count%10) == 0 { + f.Build() + f = newDepartureFrame(response, result) + } + + dest := departure.Dest + destName := dest.Tiploc + tpl, _ := result.Tiplocs.Get(dest.Tiploc) + if tpl != nil { + destName = tpl.Name + } + + plat := "" + if !(loc.Forecast.Platform.CISSuppressed || loc.Forecast.Platform.Suppressed) { + plat = loc.Forecast.Platform.Platform + } + + f.White(). + DoubleHeight(). + Printf("%-23.23s", destName). + White().Printf("%2.2s", plat). + White().Printf("%5.5s %5.5s", loc.Time.String()[:5], "On Time"). + NewLine() + + count++ + } + } + + f.Route(10, *t.PageNumber). + Build() + + s, err := response.Build() + if err == nil { + fmt.Print(s) + } + return err +} + +func newDepartureFrame(response *telstar.Response, result *service.StationResult) *telstar.FrameBuilder { + + stationTiploc, _ := result.Tiplocs.Get(result.Station[0]) + + return response.NewFrame(). + Header("DepartureBoards.mobi"). + NavMessage("[B][n][W]Data as of %s", result.Date.Format("2006 Jan 2 15:04:05")). + Printf("[B][n][W][D]%s\r\n\n", stationTiploc.Name) +} diff --git a/util/telstar/frame.go b/util/telstar/frame.go new file mode 100644 index 0000000..e888b38 --- /dev/null +++ b/util/telstar/frame.go @@ -0,0 +1,198 @@ +package telstar + +import ( + "encoding/json" + "fmt" + "net" +) + +// Frame from https://bitbucket.org/johnnewcombe/telstar-2/src/master/telstar-library/types/frame.go +// however cannot import that module so including it here +type Frame struct { + //ID interface{} `bson:"_id,omitempty"` // this was used by some on stack overflow + //ID primitive.ObjectID `bson:"_id,omitempty"` + PID Pid `json:"pid" bson:"pid"` + Visible bool `json:"visible" bson:"visible"` + HeaderText string `json:"header-text" bson:"header-text"` + Cost int `json:"cost" bson:"cost"` + DisableClear bool `json:"disable-clear" bson:"disable-clear"` + //CacheId string `json:"cache-id" bson:"cache-id"` + FrameType string `json:"frame-type" bson:"frame-type"` + Redirect Pid `json:"redirect" bson:"redirect"` + Content Content `json:"content" bson:"content"` + Footer Title `json:"footer" bson:"footer"` + Title Title `json:"title" bson:"title"` + RoutingTable []int `json:"routing-table" bson:"routing-table"` + // FIXME The Cursor field doesn't seem to be being used at all, either remove it or find a use for it + // the cursor in the nav field is added using markup + Cursor bool `json:"cursor" bson:"cursor"` + Connection Connection `json:"connection" bson:"connection"` + AuthorIdOld string `json:"author-id" bson:"author-id"` + ResponseData ResponseData `json:"response-data" bson:"response-data"` + // a transient page will not be stored in the database e.g. results of response pages etc. + //TransientPage bool `json:"transient-page" bson:"transient-page"` + // these will override the defaults specified in settings at the page level + NavMessage string `json:"navmessage-select" bson:"navmessage-select"` + NavMessageNotFound string `json:"navmessage-notfound" bson:"navmessage-notfound"` +} +type Pid struct { + PageNumber int `json:"page-no" bson:"page-no"` + FrameId string `json:"frame-id" bson:"frame-id"` +} +type Content struct { + //Data interface{} `json:"data" bson:"data"` + Data string `json:"data" bson:"data"` + Type string `json:"type" bson:"type"` +} +type Title struct { + Data string `json:"data" bson:"data"` + Type string `json:"type" bson:"type"` + MergeData []string `json:"merge-data" bson:"merge-data"` +} +type Connection struct { + Address string `json:"address" bson:"address"` + Mode string `json:"mode" bson:"mode"` + Port int `json:"port" bson:"port"` + remoteConnection net.Conn // used by methods only +} +type ResponseData struct { + Fields []ResponseField `json:"response-fields" bson:"responses"` + Action ResponseAction `json:"response-action" bson:"response-action"` +} +type ResponseField struct { + // Label string `json:"label" bson:"label"` + VPos int `json:"vpos" bson:"vpos"` + HPos int `json:"hpos" bson:"hpos"` + Required bool `json:"required" bson:"required"` + Length int `json:"length" bson:"length"` + Type string `json:"type" bson:"type"` + // FIXME: this is specified as 'auto_submit' on many response tmp + // in which case this will always return false, this needs to be fixed + // in the database for v2 + AutoSubmit bool `json:"auto-submit" bson:"auto-submit"` + Password bool `json:"password" bson:"password"` + + // these two removed for v2.0 as theses are results not definitions + //Value string `json:"value" bson:"value"` + //Valid bool `json:"valid" bson:"valid"` +} +type ResponseAction struct { + Exec string `json:"exec" bson:"exec"` + Args []string `json:"args" bson:"args"` + PostActionFrame Pid `json:"post-action-frame" bson:"post-action-frame"` + PostCancelFrame Pid `json:"post-cancel-frame" bson:"post-cancel-frame"` +} + +func (f *Frame) IsValid() bool { + return len(f.PID.FrameId) == 1 +} + +func (f *Frame) GetPageId() string { + return fmt.Sprint(f.PID.PageNumber) + f.PID.FrameId +} + +func (f *Frame) GetRedirectPageId() string { + return fmt.Sprint(f.Redirect.PageNumber) + f.Redirect.FrameId +} + +// GetZeroPageRoute returns the current page appended with 0. For example if the +// current page is 293, the 'zero' page route would be page 2930. +func (f *Frame) GetZeroPageRoute() int { + nextPage := f.PID.PageNumber * 10 + if nextPage > 999999999 { + nextPage = 0 + } + return nextPage +} + +func (c *Connection) IsValid() bool { + if len(c.Address) == 0 || c.Port == 0 || len(c.Mode) == 0 { + return false + } + return true +} + +func (c *Connection) GetUrl() string { + return fmt.Sprintf("%s:%d", c.Address, c.Port) +} + +func (c *Connection) GetRemoteConnection() net.Conn { + return c.remoteConnection +} + +func (c *Connection) SetRemoteConnection(value net.Conn) { + c.remoteConnection = value +} + +// Creates a redirect from the fromPageId to this frame. +func (f *Frame) CreateRedirect(fromPageNumber int, fromFrameId string) Frame { + + // e.g. {"pid": {"page-no": 0, "frame-id": "a"}, "redirect": {"page-no": 9, "frame-id": "a"}, "visible": True,} + + var rf Frame + + rf.PID.PageNumber = fromPageNumber + rf.PID.FrameId = fromFrameId + rf.Redirect.PageNumber = f.PID.PageNumber + rf.Redirect.FrameId = f.PID.FrameId + rf.Visible = true + + return rf +} + +func (f *Frame) CreateDefaultRoutingTable() []int { + + var ( + routingTable []int + pageNumber int + ) + + pageNumber = f.PID.PageNumber + + // default routing + for i := 0; i < len(routingTable); i++ { + routingTable = append(routingTable, i+(pageNumber*10)) + } + + // sort out hash route + pn := pageNumber + for pn > 999 { + pn = pn / 10 + } + routingTable = append(routingTable, pn) + + return routingTable + +} + +// Load populates a Frame object from json byte data +func (f *Frame) Load(jsonBytes []byte) error { + + if !json.Valid(jsonBytes) { + return fmt.Errorf("validating frame: invalid json") + } + + if err := json.Unmarshal(jsonBytes, &f); err != nil { + return fmt.Errorf("parsing json: invalid") + } + + return nil +} + +// Dump Returns a Json byte representation of the Frame +func (f *Frame) Dump() ([]byte, error) { + + var ( + data []byte + err error + ) + + if data, err = json.Marshal(f); err != nil { + return nil, err + } + + return data, nil +} +func (p *Pid) String() string { + return fmt.Sprintf("%d%s", p.PageNumber, p.FrameId) +} diff --git a/util/telstar/frameBuilder.go b/util/telstar/frameBuilder.go new file mode 100644 index 0000000..b6d9e7f --- /dev/null +++ b/util/telstar/frameBuilder.go @@ -0,0 +1,120 @@ +package telstar + +import ( + "fmt" + "strings" +) + +type FrameBuilder struct { + response *Response + header string + content []string + contentType string + navMessage string + navMessageNotFound string + routingTable []int +} + +func (r *Response) NewFrame() *FrameBuilder { + return &FrameBuilder{ + response: r, + contentType: "markup", + routingTable: make([]int, 11), + } +} + +func (b *FrameBuilder) Route(i, p int) *FrameBuilder { + if i >= 0 && i <= 10 { + b.routingTable[i] = p + } + return b +} + +func (b *FrameBuilder) Header(s string, a ...interface{}) *FrameBuilder { + b.header = fmt.Sprintf(s, a...) + return b +} + +func (b *FrameBuilder) NavMessage(s string, a ...interface{}) *FrameBuilder { + b.navMessage = fmt.Sprintf(s, a...) + return b +} + +func (b *FrameBuilder) NavMessageNotFound(s string, a ...interface{}) *FrameBuilder { + b.navMessageNotFound = fmt.Sprintf(s, a...) + return b +} + +func (b *FrameBuilder) ContentType(s string) *FrameBuilder { + b.contentType = s + return b +} + +func (b *FrameBuilder) Print(s string) *FrameBuilder { + b.content = append(b.content, s) + return b +} + +func (b *FrameBuilder) Println(s string) *FrameBuilder { + return b.Print(s).Print("\r\n") +} + +func (b *FrameBuilder) Printf(f string, a ...interface{}) *FrameBuilder { + return b.Print(fmt.Sprintf(f, a...)) +} + +func (b *FrameBuilder) Build() *Response { + if b.contentType == "" { + b.contentType = "markup" + } + + f := &Frame{ + + HeaderText: b.header, + FrameType: "information", + Content: Content{ + Data: strings.Join(b.content, ""), + Type: b.contentType, + }, + RoutingTable: b.routingTable, + Cursor: false, + NavMessage: b.navMessage, + NavMessageNotFound: b.navMessageNotFound, + } + + return b.response.addFrame(f) +} + +func (b *FrameBuilder) Red() *FrameBuilder { return b.Print("[R]") } +func (b *FrameBuilder) Green() *FrameBuilder { return b.Print("[G]") } +func (b *FrameBuilder) Yellow() *FrameBuilder { return b.Print("[Y]") } +func (b *FrameBuilder) Blue() *FrameBuilder { return b.Print("[B]") } +func (b *FrameBuilder) Magenta() *FrameBuilder { return b.Print("[M]") } +func (b *FrameBuilder) Cyan() *FrameBuilder { return b.Print("[C]") } +func (b *FrameBuilder) White() *FrameBuilder { return b.Print("[W]") } + +func (b *FrameBuilder) Flash() *FrameBuilder { return b.Print("[F]") } +func (b *FrameBuilder) Steady() *FrameBuilder { return b.Print("[S]") } + +func (b *FrameBuilder) NormalHeight() *FrameBuilder { return b.Print("[N]") } +func (b *FrameBuilder) DoubleHeight() *FrameBuilder { return b.Print("[D]") } + +func (b *FrameBuilder) NewBackground() *FrameBuilder { return b.Print("[n]") } + +func (b *FrameBuilder) MosaicRed() *FrameBuilder { return b.Print("[r]") } +func (b *FrameBuilder) MosaicGreen() *FrameBuilder { return b.Print("[g]") } +func (b *FrameBuilder) MosaicYellow() *FrameBuilder { return b.Print("[y]") } +func (b *FrameBuilder) MosaicBlue() *FrameBuilder { return b.Print("[b]") } +func (b *FrameBuilder) MosaicMagenta() *FrameBuilder { return b.Print("[m]") } +func (b *FrameBuilder) MosaicCyan() *FrameBuilder { return b.Print("[c]") } +func (b *FrameBuilder) MosaicWhite() *FrameBuilder { return b.Print("[w]") } + +func (b *FrameBuilder) SepGraphDotsHigh() *FrameBuilder { return b.Print("[h.]") } +func (b *FrameBuilder) SepGraphDotsMid() *FrameBuilder { return b.Print("[m.]") } +func (b *FrameBuilder) SepGraphDotsLow() *FrameBuilder { return b.Print("[l.]") } + +func (b *FrameBuilder) SepGraphSolidHigh() *FrameBuilder { return b.Print("[h-]") } +func (b *FrameBuilder) SepGraphSolidMid() *FrameBuilder { return b.Print("[m-]") } +func (b *FrameBuilder) SepGraphSolidLow() *FrameBuilder { return b.Print("[l-]") } + +func (b *FrameBuilder) NewLine() *FrameBuilder { return b.Print("\r\n") } diff --git a/util/telstar/response.go b/util/telstar/response.go new file mode 100644 index 0000000..99f386d --- /dev/null +++ b/util/telstar/response.go @@ -0,0 +1,120 @@ +package telstar + +import ( + "errors" + "fmt" + "os" + "strings" +) + +// Response is returned to Telstar +type Response struct { + pageNumber int + frameId byte + frames []*Frame + dynamic bool +} + +func NewResponse() *Response { + return &Response{frameId: 'a'} +} + +// PageNumber sets the page number of the response +func (r *Response) PageNumber(n int) *Response { + r.pageNumber = n + return r +} + +// FrameId sets the initial frame id. Default is "a" but can be "b" +func (r *Response) FrameId(n byte) *Response { + if n < 'a' || n > 'z' { + panic(fmt.Errorf("invalid frameId %c", n)) + } + r.frameId = n + return r +} + +// Dynamic sets the response as dynamic - for use with our +// fork of Telstar only +func (r *Response) Dynamic() *Response { + r.dynamic = true + return r +} + +// AddFrame adds a frame to the response +func (r *Response) addFrame(f *Frame) *Response { + r.frames = append(r.frames, f) + return r +} + +func (r *Response) Build() (string, error) { + if len(r.frames) == 0 { + return "", errors.New("no frames in response") + } + + frameId := r.frameId + for fn, f := range r.frames { + // Ensure frames have the correct PID's + f.PID.PageNumber = r.pageNumber + f.PID.FrameId = string(frameId) + frameId++ + if frameId > 'z' { + return "", errors.New("too many frames for response") + } + + if fn == 0 && r.dynamic { + // Only set the first frame as dynamic if we are in that mode + f.FrameType = "dynamic" + // Ensure we have this set pointing back to us so subsequent calls to the page refresh + f.ResponseData = ResponseData{ + Fields: nil, + Action: ResponseAction{ + Exec: os.Args[0], + Args: os.Args[1:], + PostActionFrame: f.PID, + }, + } + } else if f.FrameType == "" { + // If not set then set it to information + f.FrameType = "information" + } + + // Ensure we have NavMessage set, if not then it breaks Telstar + if f.NavMessage == "" { + f.NavMessage = "[B][n][Y]Select item or[W]*page# : [_+]" + } + if f.NavMessageNotFound == "" { + f.NavMessageNotFound = "[B][n][Y]Page not Found :[W]" + } + + // Ensure we have a routing table TODO set this to something else? + if len(f.RoutingTable) == 0 { + f.RoutingTable = []int{r.pageNumber, r.pageNumber, r.pageNumber, r.pageNumber, r.pageNumber, r.pageNumber, r.pageNumber, r.pageNumber, r.pageNumber, r.pageNumber} + } + + // Force these + f.AuthorIdOld = "nre-feeds" + f.Visible = true + } + + var output strings.Builder + for _, f := range r.frames { + outputText, err := f.Dump() + if err != nil { + return "", err + } + + _, err = output.Write(outputText) + if err != nil { + return "", err + } + + _, err = output.WriteString(",") + if err != nil { + return "", err + } + } + + outs := output.String() + return fmt.Sprintf("[%s]", outs[:len(outs)-1]), nil +} From d23490bd747c0895838cfc7ddf4217b74fb71e06 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 5 Apr 2023 14:04:06 +0100 Subject: [PATCH 08/11] Support false destinations --- tools/darwintelstar/telstar.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/darwintelstar/telstar.go b/tools/darwintelstar/telstar.go index ae93695..2d43e0a 100644 --- a/tools/darwintelstar/telstar.go +++ b/tools/darwintelstar/telstar.go @@ -71,7 +71,10 @@ func (t *Telstar) crs(crs string) error { dest := departure.Dest destName := dest.Tiploc - tpl, _ := result.Tiplocs.Get(dest.Tiploc) + if loc.FalseDestination != "" { + destName = loc.FalseDestination + } + tpl, _ := result.Tiplocs.Get(destName) if tpl != nil { destName = tpl.Name } From 1a5ffa5befa9cb29ec1f4726f09c563b385bb5e9 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 5 Apr 2023 14:04:20 +0100 Subject: [PATCH 09/11] Move ldb main to new location for tools --- {ldb => tools/darwinldb}/bin/main.go | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {ldb => tools/darwinldb}/bin/main.go (100%) diff --git a/ldb/bin/main.go b/tools/darwinldb/bin/main.go similarity index 100% rename from ldb/bin/main.go rename to tools/darwinldb/bin/main.go From b52cd8113d5512e117bdc58dd5e2efed692713c6 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 5 Apr 2023 16:54:07 +0100 Subject: [PATCH 10/11] Cleanup telstar departure board layout --- tools/darwintelstar/telstar.go | 185 +++++++++++++++++++++++++++++---- util/telstar/frameBuilder.go | 2 +- util/telstar/response.go | 5 +- util/telstar/split.go | 29 ++++++ util/telstar/split_test.go | 37 +++++++ 5 files changed, 235 insertions(+), 23 deletions(-) create mode 100644 util/telstar/split.go create mode 100644 util/telstar/split_test.go diff --git a/tools/darwintelstar/telstar.go b/tools/darwintelstar/telstar.go index 2d43e0a..ce79538 100644 --- a/tools/darwintelstar/telstar.go +++ b/tools/darwintelstar/telstar.go @@ -5,6 +5,7 @@ import ( "github.com/peter-mount/nre-feeds/ldb/client" "github.com/peter-mount/nre-feeds/ldb/service" "github.com/peter-mount/nre-feeds/util/telstar" + "strings" ) type Telstar struct { @@ -47,15 +48,33 @@ func (t *Telstar) crs(crs string) error { PageNumber(*t.PageNumber). FrameId('a') - f := newDepartureFrame(response, result) + f := t.newDepartureFrame(response, result) for _, m := range result.Messages { - f.NewLine(). - Print(m.Message) + f.NewLine() + + s := m.Message + if i := strings.Index(s, "More detail"); i > -1 { + s = s[:i] + } + for i, l := range strings.Split(s, ".") { + l = strings.TrimSpace(l) + if l != "" { + for _, s := range telstar.Split(l+".", 38) { + if i == 0 { + f.White() + } else { + f.Yellow() + } + f.Println(s) + } + } + f.NewLine() + } f.Build() - f = newDepartureFrame(response, result) + f = t.newDepartureFrame(response, result) } count := 0 @@ -64,11 +83,6 @@ func (t *Telstar) crs(crs string) error { loc := departure.Location if !loc.IsDestination() { - if count > 0 && (count%10) == 0 { - f.Build() - f = newDepartureFrame(response, result) - } - dest := departure.Dest destName := dest.Tiploc if loc.FalseDestination != "" { @@ -79,24 +93,150 @@ func (t *Telstar) crs(crs string) error { destName = tpl.Name } + via := "" + if v, exists := result.Via[departure.RID]; exists { + via = v.Text + } + plat := "" if !(loc.Forecast.Platform.CISSuppressed || loc.Forecast.Platform.Suppressed) { plat = loc.Forecast.Platform.Platform } - f.White(). - DoubleHeight(). - Printf("%-23.23s", destName). - White().Printf("%2.2s", plat). - White().Printf("%5.5s %5.5s", loc.Time.String()[:5], "On Time"). - NewLine() + var reasonText []string + { + reason := result.Reasons.Late[departure.LateReason.Reason] + if loc.Cancelled && departure.CancelReason.Reason != 0 { + reason = result.Reasons.Cancelled[departure.CancelReason.Reason] + } + if reason != nil { + reasonText = telstar.Split(reason.Text, 38) + } + } + + toc := departure.Toc + if tocName, _ := result.Tocs.Get(toc); tocName != nil { + toc = tocName.Name + } + + lastName := departure.LastReport.Tiploc + if lastName != "" { + if lastName == departure.Location.Tiploc { + // Don't show for this location + lastName = "" + } else { + // resolve the name + tpl, _ = result.Tiplocs.Get(lastName) + if tpl != nil { + lastName = tpl.Name + } + } + } + + // Work out departure height + height := 2 + + // The separator row + if count > 0 { + height++ + } + + if via != "" { + height++ + } + + height += len(reasonText) + + if toc != "" || loc.Length > 0 { + height++ + } + + if lastName != "" { + height++ + } + + // Page break if not enough room + + if (count + height) >= 20 { + f.Build() + f = t.newDepartureFrame(response, result) + count = 0 + } + + // Now render the departure + + if count > 0 { + f.MosaicBlue().SepGraphSolidMid().Print("\r") + } + + if loc.Cancelled { + f.Red() + } else if loc.Forecast.Arrived { + f.White() + } else { + f.Green() + } + f.DoubleHeight(). + Printf("%-28.28s", destName) + + if loc.Cancelled { + f.Red().Flash().Print("Canceled") + } else { + f.Printf(" %2.2s", plat) + + if loc.Forecast.Arrived { + f.White().Print("Arrvd") + } else if loc.Forecast.Delayed { + f.Red().Print("Delyd") + } else { + /*t := loc.Time.Time(time.Now()) + dt := t.Sub(time.Now()).Minutes() + if dt > 0 && dt < 10 { + f.Yellow().Printf("%1.1d min", int(dt)) + } else*/{ + f.Green().Printf("%5.5s", loc.Time.String()[:5]) + } + } + } + f.NewLine().NewLine() + + if via != "" { + f.Yellow().Println(via) + } + + for _, s := range reasonText { + f.Yellow().Println(s) + } + + if toc != "" || loc.Length > 0 { + if toc != "" { + f.Yellow().Printf("%s service ", toc) + } + if loc.Length > 0 { + f.Yellow().Printf("%d coaches", loc.Length) + } + f.NewLine() + } + + if lastName != "" { + s := "Last seen " + departure.LastReport.Time.String()[:5] + /*if departure.LastReport.Departed { + s = s + " departed" + } else { + s = s + " at" + }*/ + s = s + " " + lastName + f.Yellow(). + Printf("%-38.38s", s). + NewLine() + } - count++ + // Move to next entry + count = count + height } } - f.Route(10, *t.PageNumber). - Build() + f.Build() s, err := response.Build() if err == nil { @@ -105,12 +245,15 @@ func (t *Telstar) crs(crs string) error { return err } -func newDepartureFrame(response *telstar.Response, result *service.StationResult) *telstar.FrameBuilder { +func (t *Telstar) newDepartureFrame(response *telstar.Response, result *service.StationResult) *telstar.FrameBuilder { stationTiploc, _ := result.Tiplocs.Get(result.Station[0]) - return response.NewFrame(). - Header("DepartureBoards.mobi"). + f := response.NewFrame(). + Header("[C]DepartureBoards.mobi[W]"). NavMessage("[B][n][W]Data as of %s", result.Date.Format("2006 Jan 2 15:04:05")). Printf("[B][n][W][D]%s\r\n\n", stationTiploc.Name) + f.Route(1, *t.PageNumber). + Route(10, *t.PageNumber) + return f } diff --git a/util/telstar/frameBuilder.go b/util/telstar/frameBuilder.go index b6d9e7f..434af56 100644 --- a/util/telstar/frameBuilder.go +++ b/util/telstar/frameBuilder.go @@ -56,7 +56,7 @@ func (b *FrameBuilder) Print(s string) *FrameBuilder { } func (b *FrameBuilder) Println(s string) *FrameBuilder { - return b.Print(s).Print("\r\n") + return b.Print(s).NewLine() } func (b *FrameBuilder) Printf(f string, a ...interface{}) *FrameBuilder { diff --git a/util/telstar/response.go b/util/telstar/response.go index 99f386d..b016ef4 100644 --- a/util/telstar/response.go +++ b/util/telstar/response.go @@ -43,7 +43,10 @@ func (r *Response) Dynamic() *Response { // AddFrame adds a frame to the response func (r *Response) addFrame(f *Frame) *Response { - r.frames = append(r.frames, f) + // Don't add a frame if we are full - e.g. large responses + if len(r.frames) < int('z'-r.frameId) { + r.frames = append(r.frames, f) + } return r } diff --git a/util/telstar/split.go b/util/telstar/split.go new file mode 100644 index 0000000..dad335f --- /dev/null +++ b/util/telstar/split.go @@ -0,0 +1,29 @@ +package telstar + +import ( + "strings" +) + +func Split(s string, l int) []string { + s = strings.TrimSpace(s) + + var a []string + + for len(s) > l { + i := strings.LastIndex(s[:l], " ") + if i > 0 { + a = append(a, strings.TrimSpace(s[:i])) + s = strings.TrimSpace(s[i:]) + } else { + a = append(a, strings.TrimSpace(s[:l])) + s = strings.TrimSpace(s[l:]) + } + } + + s = strings.TrimSpace(s) + if s != "" { + a = append(a, s) + } + + return a +} diff --git a/util/telstar/split_test.go b/util/telstar/split_test.go new file mode 100644 index 0000000..1396f2f --- /dev/null +++ b/util/telstar/split_test.go @@ -0,0 +1,37 @@ +package telstar + +import ( + "reflect" + "testing" +) + +func TestSplit(t *testing.T) { + type args struct { + s string + l int + } + tests := []struct { + name string + args args + want []string + }{ + { + name: "test", + args: args{ + s: "This train has been delayed by a fault with the signalling system", + l: 40, + }, + want: []string{ + "This train has been delayed by a fault", + "with the signalling system", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := Split(tt.args.s, tt.args.l); !reflect.DeepEqual(got, tt.want) { + t.Errorf("Split() = %v, want %v", got, tt.want) + } + }) + } +} From 235a85a0598406ae1545cb209a5914c985cde06e Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 5 Apr 2023 20:21:09 +0100 Subject: [PATCH 11/11] Cleanup telstar departure board layout --- tools/darwintelstar/telstar.go | 2 +- util/telstar/response.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/darwintelstar/telstar.go b/tools/darwintelstar/telstar.go index ce79538..1422504 100644 --- a/tools/darwintelstar/telstar.go +++ b/tools/darwintelstar/telstar.go @@ -35,7 +35,7 @@ func (t *Telstar) boards() error { func (t *Telstar) crs(crs string) error { - crs = "LBG" + //crs = "LBG" cl := client.DarwinLDBClient{Url: "https://ldb.prod.a51.li"} result, err := cl.GetSchedule(crs) diff --git a/util/telstar/response.go b/util/telstar/response.go index b016ef4..482624c 100644 --- a/util/telstar/response.go +++ b/util/telstar/response.go @@ -44,6 +44,10 @@ func (r *Response) Dynamic() *Response { // AddFrame adds a frame to the response func (r *Response) addFrame(f *Frame) *Response { // Don't add a frame if we are full - e.g. large responses + // e.g. For london bridge, at times you can fill up frames a...y + // and have to cut off frames. + // + // Also, Telstar doesn't allow z in the response - hence why <'z' here if len(r.frames) < int('z'-r.frameId) { r.frames = append(r.frames, f) }