Skip to content

Commit

Permalink
Merge pull request #11 from knocknote/feature/migrate-to-go-modules
Browse files Browse the repository at this point in the history
Supports Go Modules ( GO111MODULE=on )
  • Loading branch information
goccy authored Apr 16, 2019
2 parents d4fdcaf + b81c81b commit 6bcac9d
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 26 deletions.
12 changes: 9 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ jobs:
test:
working_directory: /go/src/go.knocknote.io/octillery
docker:
- image: golang:1.11
- image: golang:1.12
environment:
GO111MODULE: "on"
steps:
- checkout
- run:
name: Run go get
name: Download modules
command: |
go get ./...
go mod download
- run:
name: Install octillery CLI
command: |
go get ./cmd/octillery
- run:
name: Install SQLite plugin
command: |
Expand Down
75 changes: 52 additions & 23 deletions cmd/octillery/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,41 +519,42 @@ func (cmd *ConsoleCommand) Execute(args []string) error {
return nil
}

func (cmd *InstallCommand) lookupOctillery() (string, error) {
func (cmd *InstallCommand) lookupOctillery() ([]string, error) {
libraryPath := filepath.Join("go.knocknote.io", "octillery")
installPaths := []string{}
cwd, err := os.Getwd()
if err != nil {
return "", errors.WithStack(err)
return installPaths, errors.WithStack(err)
}
// First, lookup vendor/go.knocknote.io/octillery
vendorPath := filepath.Join(cwd, "vendor", libraryPath)
if _, err := os.Stat(vendorPath); !os.IsNotExist(err) {
return vendorPath, nil
installPaths = append(installPaths, vendorPath)
}
goPath := os.Getenv("GOPATH")
if goPath == "" {
goPath = filepath.Join(os.Getenv("HOME"), "go")
}
// Second, lookup $GOPATH/src/go.knocknote.io/octillery
underGoPath := filepath.Join(os.Getenv("GOPATH"), "src", libraryPath)
underGoPath := filepath.Join(goPath, "src", libraryPath)
if _, err := os.Stat(underGoPath); !os.IsNotExist(err) {
return underGoPath, nil
installPaths = append(installPaths, underGoPath)
}
if os.Getenv("GO111MODULE") == "on" {
// lookup $GOPATH/pkg/mod/go.knocknote.io/octillery@*
modPathPrefix := filepath.Join(goPath, "pkg", "mod", libraryPath)
modPaths, err := filepath.Glob(modPathPrefix + "@*")
if err == nil {
installPaths = append(installPaths, modPaths...)
}
}
if len(installPaths) == 0 {
return installPaths, errors.New("cannot find 'go.knocknote.io/octillery' library")
}
return "", errors.New("cannot find 'go.knocknote.io/octillery' library")
return installPaths, nil
}

// Execute executes install command
func (cmd *InstallCommand) Execute(args []string) error {
var sourcePath string
if len(args) > 0 {
path, err := filepath.Abs(args[0])
if err != nil {
return errors.WithStack(err)
}
sourcePath = path
} else {
path, err := cmd.lookupOctillery()
if err != nil {
return errors.WithStack(err)
}
sourcePath = path
}
func (cmd *InstallCommand) installToPath(sourcePath string) error {
adapterBasePath := filepath.Join(sourcePath, "connection", "adapter", "plugin")
var adapterPath string
if cmd.MySQLAdapter {
Expand All @@ -567,12 +568,40 @@ func (cmd *InstallCommand) Execute(args []string) error {
if err != nil {
return errors.WithStack(err)
}
pluginDir := filepath.Join(sourcePath, "plugin")
if err := os.Chmod(pluginDir, 0755); err != nil {
return errors.WithStack(err)
}
baseName := filepath.Base(adapterPath)
pluginPath := filepath.Join(sourcePath, "plugin", baseName)
pluginPath := filepath.Join(pluginDir, baseName)
log.Printf("install to %s\n", pluginPath)
return errors.WithStack(ioutil.WriteFile(pluginPath, adapterData, 0644))
}

// Execute executes install command
func (cmd *InstallCommand) Execute(args []string) error {
if len(args) > 0 {
path, err := filepath.Abs(args[0])
if err != nil {
return errors.WithStack(err)
}
if err := cmd.installToPath(path); err != nil {
return errors.WithStack(err)
}
return nil
}
paths, err := cmd.lookupOctillery()
if err != nil {
return errors.WithStack(err)
}
for _, path := range paths {
if err := cmd.installToPath(path); err != nil {
return errors.WithStack(err)
}
}
return nil
}

// Execute executes shard command
func (cmd *ShardCommand) Execute(args []string) error {
if len(args) == 0 {
Expand Down
26 changes: 26 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module go.knocknote.io/octillery

go 1.12

require (
github.com/deckarep/golang-set v0.0.0-20180927150649-699df6a3acf6 // indirect
github.com/fatih/color v0.0.0-20160317093153-533cd7fd8a85
github.com/go-sql-driver/mysql v1.3.0
github.com/jessevdk/go-flags v0.0.0-20170212220246-460c7bb0abd6
github.com/juju/errors v0.0.0-20170703010042-c7d06af17c68 // indirect
github.com/juju/loggo v0.0.0-20190212223446-d976af380377 // indirect
github.com/juju/testing v0.0.0-20190415054131-a282c42ba059 // indirect
github.com/knocknote/vitess-sqlparser v0.0.0-20181121014348-1003c43917a3
github.com/mattn/go-colorable v0.0.0-20160220075935-9cbef7c35391 // indirect
github.com/mattn/go-isatty v0.0.0-20151211000621-56b76bdf51f7 // indirect
github.com/mattn/go-sqlite3 v0.0.0-20170407154627-cf7286f069c3
github.com/pkg/errors v0.0.0-20181023235946-059132a15dd0
github.com/schemalex/schemalex v0.0.0-20181009011149-1c8484e3c7bc
github.com/sergi/go-diff v0.0.0-20170409071739-feef008d51ad
github.com/stretchr/testify v1.3.0 // indirect
golang.org/x/net v0.0.0-20170421002609-c8c74377599b // indirect
golang.org/x/sys v0.0.0-20170421005244-ea9bcade75cb // indirect
golang.org/x/text v0.0.0-20180302201248-b7ef84aaf62a // indirect
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect
gopkg.in/yaml.v2 v2.2.2
)
47 changes: 47 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deckarep/golang-set v0.0.0-20180927150649-699df6a3acf6 h1:+CICy2RHjHa2/+i6setnlf/UKQv1h6Oti4PVpk3Hjlk=
github.com/deckarep/golang-set v0.0.0-20180927150649-699df6a3acf6/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ=
github.com/fatih/color v0.0.0-20160317093153-533cd7fd8a85 h1:i30JFHNBhahPa7hSaGn5FoB1uckjcXCjmS5Su+NyKUI=
github.com/fatih/color v0.0.0-20160317093153-533cd7fd8a85/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/go-sql-driver/mysql v1.3.0 h1:pgwjLi/dvffoP9aabwkT3AKpXQM93QARkjFhDDqC1UE=
github.com/go-sql-driver/mysql v1.3.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/jessevdk/go-flags v0.0.0-20170212220246-460c7bb0abd6 h1:3sqgDDcqnooPDgktvzvan9LN4PGl3N0NqSk1ostdtqw=
github.com/jessevdk/go-flags v0.0.0-20170212220246-460c7bb0abd6/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/juju/errors v0.0.0-20170703010042-c7d06af17c68 h1:d2hBkTvi7B89+OXY8+bBBshPlc+7JYacGrG/dFak8SQ=
github.com/juju/errors v0.0.0-20170703010042-c7d06af17c68/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q=
github.com/juju/loggo v0.0.0-20190212223446-d976af380377 h1:n6QjW3g5JNY3xPmIjFt6z1H6tFQA6BhwOC2bvTAm1YU=
github.com/juju/loggo v0.0.0-20190212223446-d976af380377/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U=
github.com/juju/testing v0.0.0-20190415054131-a282c42ba059 h1:vsqkD58dFysYgUZ8XHiVG37CIDCys9Fu2dTLAPUsjM8=
github.com/juju/testing v0.0.0-20190415054131-a282c42ba059/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA=
github.com/knocknote/vitess-sqlparser v0.0.0-20181121014348-1003c43917a3 h1:Nk/bqRokAz+B4j+18CKyAYhkf/scbbY7anWdSZFHjqI=
github.com/knocknote/vitess-sqlparser v0.0.0-20181121014348-1003c43917a3/go.mod h1:bF2oGXw2Ex/jIPGFPaFzEf8BtNRSBWc81ni+N9UaW5Q=
github.com/mattn/go-colorable v0.0.0-20160220075935-9cbef7c35391 h1:x4vT4RoTH2BNkPx0LgrBKeFuPQPviK1aSAIWG6ruc+Y=
github.com/mattn/go-colorable v0.0.0-20160220075935-9cbef7c35391/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.0-20151211000621-56b76bdf51f7 h1:owMyzMR4QR+jSdlfkX9jPU3rsby4++j99BfbtgVr6ZY=
github.com/mattn/go-isatty v0.0.0-20151211000621-56b76bdf51f7/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-sqlite3 v0.0.0-20170407154627-cf7286f069c3 h1:a/pBXmDboAJ2dwrZIDgQAEpeFKCYbrCh6Gz9OtJ9iHo=
github.com/mattn/go-sqlite3 v0.0.0-20170407154627-cf7286f069c3/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/pkg/errors v0.0.0-20181023235946-059132a15dd0 h1:R+lX9nKwNd1n7UE5SQAyoorREvRn3aLF6ZndXBoIWqY=
github.com/pkg/errors v0.0.0-20181023235946-059132a15dd0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/schemalex/schemalex v0.0.0-20181009011149-1c8484e3c7bc h1:4gfXZsCVFSFo1VXhjETZbzTgN/h4nOfhtkRy43qHH4I=
github.com/schemalex/schemalex v0.0.0-20181009011149-1c8484e3c7bc/go.mod h1:zWwTMDNFIqKCdfpDybbRG7R+UK6ixHM2eHGKbrraOYc=
github.com/sergi/go-diff v0.0.0-20170409071739-feef008d51ad h1:tSFsPEWlyDYLf376k3+aunLH2qE7TMd/8arj5jZtqg8=
github.com/sergi/go-diff v0.0.0-20170409071739-feef008d51ad/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/net v0.0.0-20170421002609-c8c74377599b h1:0xi+vCJycVjnuU8kmgp0TaCZ1jHkqfhLs1Tg7hLwmyg=
golang.org/x/net v0.0.0-20170421002609-c8c74377599b/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sys v0.0.0-20170421005244-ea9bcade75cb h1:bzF0hsgKGoC02kmi4nu2x0KUqjmiT97R15TN7CaAKK4=
golang.org/x/sys v0.0.0-20170421005244-ea9bcade75cb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.0.0-20180302201248-b7ef84aaf62a h1:06wVxCgDhzQ9MYiwHpRSyzOhZKgF/msceRaCG0PG7ME=
golang.org/x/text v0.0.0-20180302201248-b7ef84aaf62a/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce h1:xcEWjVhvbDy+nHP67nPDDpbYrY+ILlfndk4bRioVHaU=
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

0 comments on commit 6bcac9d

Please sign in to comment.