Skip to content

Commit

Permalink
feat(web-server): run a web server to listen for commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsimonemms committed Dec 12, 2022
1 parent f2a2850 commit 2fc183e
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ ports:
name: PostgreSQL
visibility: private

- port: 5670
name: Gobblr web server
visibility: private

- port: 27017
name: MongoDB
visibility: private
Expand Down
17 changes: 14 additions & 3 deletions cmd/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ import (
)

var dbOpts struct {
DataPath string
Driver drivers.Driver
Retries uint64
DataPath string
Driver drivers.Driver
Retries uint64
RunWebServer bool
WebPort int
}

// dbCmd represents the db command
Expand All @@ -49,6 +51,11 @@ var dbCmd = &cobra.Command{
return err
}

if dbOpts.RunWebServer {
// Runs the execution as a server to make it easy to trigger it from integration tests etc
return gobblr.Serve(dbOpts.DataPath, dbOpts.Driver, dbOpts.Retries, dbOpts.WebPort)
}

jsonData, err := json.MarshalIndent(inserted, "", " ")
if err != nil {
return err
Expand All @@ -67,6 +74,10 @@ func init() {

viper.SetDefault("path", path.Join(currentPath, "data"))
viper.SetDefault("retries", 0)
viper.SetDefault("run", false)
viper.SetDefault("run-port", 5670) // Default to a random, normally-unused port
dbCmd.PersistentFlags().StringVar(&dbOpts.DataPath, "path", viper.GetString("path"), "location of the data files")
dbCmd.PersistentFlags().Uint64Var(&dbOpts.Retries, "retries", viper.GetUint64("retries"), "number of retries before declaring a failure")
dbCmd.PersistentFlags().BoolVar(&dbOpts.RunWebServer, "run", viper.GetBool("run"), "run as a web server")
dbCmd.PersistentFlags().IntVar(&dbOpts.WebPort, "run-port", viper.GetInt("run-port"), "port for web server to listen on")
}
19 changes: 19 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ go 1.19

require (
github.com/cenkalti/backoff/v4 v4.2.0
github.com/gin-contrib/requestid v0.0.6
github.com/gin-gonic/gin v1.8.1
github.com/mrsimonemms/gin-structured-logger v0.1.0
github.com/rs/zerolog v1.28.0
github.com/spf13/cobra v1.6.1
github.com/spf13/viper v1.14.0
go.mongodb.org/mongo-driver v1.11.0
Expand All @@ -16,10 +20,16 @@ require (

require (
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.10.0 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/goccy/go-json v0.9.7 // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
Expand All @@ -32,11 +42,17 @@ require (
github.com/jackc/pgx/v4 v4.17.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-sqlite3 v1.14.15 // indirect
github.com/microsoft/go-mssqldb v0.17.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/montanaflynn/stats v0.6.6 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
Expand All @@ -46,14 +62,17 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.1 // indirect
github.com/xdg-go/stringprep v1.0.3 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
golang.org/x/crypto v0.0.0-20221005025214-4161e89ecf1b // indirect
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.0.0-20220908164124-27713097b956 // indirect
golang.org/x/text v0.4.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 2fc183e

Please sign in to comment.