Skip to content

Commit

Permalink
add machineid
Browse files Browse the repository at this point in the history
  • Loading branch information
flarco committed Jan 3, 2023
1 parent c520a17 commit 879ed35
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 34 deletions.
32 changes: 0 additions & 32 deletions dbrest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import (
"syscall"
"time"

"github.com/dbrest-io/dbrest/state"
"github.com/flarco/g"
"github.com/integrii/flaggy"
)

var ctx = g.NewContext(context.Background())
Expand Down Expand Up @@ -51,33 +49,3 @@ func main() {
return
}
}

func cliInit() int {
// init CLI
flaggy.SetName("dbrest")
flaggy.SetDescription("Spin up a REST API for any Major Database | https://github.com/dbrest-io/dbREST")
flaggy.SetVersion(state.Version)
flaggy.DefaultParser.ShowHelpOnUnexpected = true
flaggy.DefaultParser.AdditionalHelpPrepend = "Version " + state.Version

// make CLI sub-commands
cliConns.Make().Add()
cliServe.Make().Add()
cliTokens.Make().Add()

for _, cli := range g.CliArr {
flaggy.AttachSubcommand(cli.Sc, 1)
}

flaggy.ShowHelpOnUnexpectedDisable()
flaggy.Parse()

ok, err := g.CliProcess()
if err != nil {
g.LogFatal(err)
} else if !ok {
flaggy.ShowHelp("")
}

return 0
}
55 changes: 55 additions & 0 deletions dbrest_cli.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package main

import (
"os"
"runtime"
"sort"
"strings"

"github.com/dbrest-io/dbrest/env"
"github.com/dbrest-io/dbrest/server"
"github.com/dbrest-io/dbrest/state"
"github.com/denisbrodbeck/machineid"
"github.com/flarco/dbio/connection"
"github.com/flarco/dbio/iop"
"github.com/flarco/g"
"github.com/flarco/g/net"
"github.com/integrii/flaggy"
"github.com/jedib0t/go-pretty/table"
"github.com/samber/lo"
Expand Down Expand Up @@ -156,6 +160,7 @@ func serve(c *g.CliSC) (ok bool, err error) {
defer s.Close()

go s.Start()
go telemetry("serve")

<-ctx.Ctx.Done()

Expand Down Expand Up @@ -322,3 +327,53 @@ func tokens(c *g.CliSC) (ok bool, err error) {
}
return
}

func cliInit() int {
// init CLI
flaggy.SetName("dbrest")
flaggy.SetDescription("Spin up a REST API for any Major Database | https://github.com/dbrest-io/dbREST")
flaggy.SetVersion(state.Version)
flaggy.DefaultParser.ShowHelpOnUnexpected = true
flaggy.DefaultParser.AdditionalHelpPrepend = "Version " + state.Version

// make CLI sub-commands
cliConns.Make().Add()
cliServe.Make().Add()
cliTokens.Make().Add()

for _, cli := range g.CliArr {
flaggy.AttachSubcommand(cli.Sc, 1)
}

flaggy.ShowHelpOnUnexpectedDisable()
flaggy.Parse()

ok, err := g.CliProcess()
if err != nil {
g.LogFatal(err)
} else if !ok {
flaggy.ShowHelp("")
}

return 0
}

func telemetry(action string) {
if val := os.Getenv("DBREST_TELEMETRY"); val != "" {
if !cast.ToBool(val) {
return
}
}
const telemetryURL = "https://liveflarccszw.dataplane.rudderstack.com/v1/webhook?writeKey=2JpSsZZ81lPlzMmos0mqQsCXNXm"

machineID, _ := machineid.ProtectedID("dbrest")

payload := g.M(
"version", state.Version,
"os", runtime.GOOS,
"action", action,
"anonymous_id", machineID,
)
net.ClientDo("POST", telemetryURL, strings.NewReader(g.Marshal(payload)), nil)

}
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ module github.com/dbrest-io/dbrest
go 1.19

require (
github.com/denisbrodbeck/machineid v1.0.1
github.com/flarco/dbio v0.3.178
github.com/flarco/g v0.1.51
github.com/integrii/flaggy v1.5.2
github.com/jedib0t/go-pretty v4.3.0+incompatible
github.com/jmoiron/sqlx v1.2.0
github.com/json-iterator/go v1.1.12
github.com/labstack/echo/v5 v5.0.0-20220201181537-ed2888cfa198
github.com/samber/lo v1.25.0
github.com/spf13/cast v1.5.0
github.com/stretchr/testify v1.8.1
gopkg.in/yaml.v3 v3.0.1
)

require (
Expand Down Expand Up @@ -106,7 +109,6 @@ require (
github.com/jackc/pgx/v4 v4.15.0 // indirect
github.com/jaypipes/ghw v0.6.1 // indirect
github.com/jaypipes/pcidb v0.5.0 // indirect
github.com/jedib0t/go-pretty v4.3.0+incompatible // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.4 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
Expand Down Expand Up @@ -177,7 +179,6 @@ require (
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/postgres v1.0.5 // indirect
gorm.io/driver/sqlite v1.1.4 // indirect
gorm.io/gorm v1.20.7 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnG
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ=
github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI=
github.com/denisenkom/go-mssqldb v0.9.0 h1:RSohk2RsiZqLZ0zCjtfn3S4Gp4exhpBWHyQ7D0yGjAk=
github.com/denisenkom/go-mssqldb v0.9.0/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
Expand Down

0 comments on commit 879ed35

Please sign in to comment.