Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract psapi into github.com/planetscale/planetscale-go #27

Merged
merged 2 commits into from
Jan 12, 2021

Conversation

fatih
Copy link
Member

@fatih fatih commented Jan 11, 2021

This PR extracts the PlanetScale Go API client from this repo into github.com/planetscale/planetscale-go. The repo is already ready for use, so we also migrate with this PR by removing psapi and using this new package.

Extracting the API package is needed for several reasons:

  • Other Go services at PlanetScale also need to interact with the public API; hence these services should use the Go API client without having to rely on the CLI. The first service to use this new API will be https://github.com/planetscale/sql-proxy, which is required to fetch databases and the certificates necessary to establish a secure TLS connection.
  • We eventually want to release an Open-Source Go library for the developer community. People will not only use our CLI; they will also create various kinds of services, and having an official Go client will make it simpler for them to create new tools. Almost all "cloud" specific tools are written in Go.
  • In addition to this, automation tools like Terraform will also need a Go client in the future if we want to add Terraform support for PlanetScale DB.

A couple of notes that will change our workflow:

  • Because the Go package (planetscale-go) is still private, locally, you'll have to configure Go. By default, Go will try to access the default Go module proxy (https:/proxy.golang.org). Because the package is private, it'll throw an error (this will only happen if you re-download the package). To fix the error, you need to configure Go to contact the proxy for our private package. Luckily executing a single command can do it:
go env -w GOPRIVATE="github.com/planetscale/*"
  • There is no versioning yet for the planetscale-go package. Because we're going to change/break things until everything is fleshed out, you'll see that the version in go.mod is something like: v0.0.0-20210109112707-8edffde9c156. I want us to iterate fastly without dealing with versioning/releasing. We're going to release and make it open source once it's ready for prime time.

  • If you want to add a new endpoint or new functionality, you'll first extend the API package and add them to planetscale-go. Once that is finished, to use the new functionality here in the CLI, you can download and vendor the latest release with:

go get github.com/planetscale/planetscale-go
go mod vendor

Copy link
Member

@iheanyi iheanyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

fatih added a commit that referenced this pull request Jan 11, 2021
The following improvements have been made:

* Updated the Go version from 1.13 to 1.15. This is done for two reason.
  First, we should always aim to use the latest version, this is a
  common theme in Go projects and each version provides more performance
  or overall UX improvements we need. Second, starting with Go 1.14, the
  `go` commandline CLI now automatically detects the `vendor/` folder
  and uses that during `go build` and `go test`. This is needed so the
  CI detects any inconsistencies during a pull request and that the
  source code is 100% buildable.

* I removed the `Get dependencies` part because we're vendoring the
  source code and `go get` makes a network call to fetch dependencies.
  We don't need to fetch the dependencies again, because our source of
  truth is the `vendor/` folder. Also, this particular step breaks our
  CI if we start using private dependencies (i.e:
  #27). We could configure our CI
  to easily so `go get` could work easily, but I'm not sure we need it
  at all due the usage of `vendor/`

* I removed the `-v` flag from `go test -v`. The main reason is that
  `-v` outputs to much information. It' s not needed. The best outcome
  is to output only the issues we see. The benefit is, it's easier to
  parse the CI output for humans and we don't have to scroll hundreds of
  lines.

(nit: the pictures are attached to the GitHub Pull Request, please find
the appropriate PR and check that it out there :))

Before:

```
```

After:

```
```
@fatih fatih mentioned this pull request Jan 11, 2021
@fatih
Copy link
Member Author

fatih commented Jan 11, 2021

The CI is failing because it tries to fetch a private dependency and it doesn't have access to it. Because we're vendoring our dependencies into vendor/ folder it's not needed. This PR fixes it: #28 to be merged so the CI. Once that is merged, this PR should be good to go.

This PR extracts the PlanetScale Go API client from this repo into
github.com/planetscale/planetscale-go. The repo is already ready for
use, so we also migrate with this PR by removing `psapi` and using
this new package.

This is needed for several reasons:

* Other Go services at PlanetScale also need to interact with the public
  API, hence these services should be able to use the Go API client
  without having to rely on the CLI. The first service to use this new
  API will be https://github.com/planetscale/sql-proxy, which is
  required to fetch databases and
* We eventually want to release an Open-Source Go library for the
  developer community. People will not only use our CLI; they will also
  create various kinds of services, and having an official Go client
  will make it simpler for them to create new tools. Almost all "cloud"
  specific tools are written in Go.

  In addition to this, automation tools like `Terraform` will also need
  a Go client in the future if we want to add Terraform support for
  PlanetScale DB.

A couple of notes that will change our workflow:

* Because the Go package (planetscale-go) is still private, locally
  you'll have to configure Go. By default, Go will try to access the
  default Go module proxy (https:/proxy.golang.org). Because the package
  is private, it'll throw an error (this will only happen if you
  re-download the package). To fix the error, you need to configure Go,
  so it doesn't contact the proxy for our private package. Luckily
  executing a single command can do it:

```
go env -w GOPRIVATE="github.com/planetscale/*"
```

* There is no versioning yet for the `planetscale-go` package. Because
  we're going to change/break things until everything is fleshed out,
  you'll see that the version in `go.mod` is something like:
  `v0.0.0-20210109112707-8edffde9c156`.

* If you want to add a new endpoint or new functionality, you'll have to
  add it to `planetscale-go`. To use them in the CLI, you can download
  and vendor the latest release with:

```
go get github.com/planetscale/planetscale-go
go mod vendor
```
@fatih fatih force-pushed the fatih/extract-cli branch from 763ea74 to 80cb186 Compare January 11, 2021 19:42
@fatih fatih merged commit 72f0a4b into main Jan 12, 2021
@fatih fatih deleted the fatih/extract-cli branch January 12, 2021 08:00
asbiaidw5 added a commit to asbiaidw5/cli that referenced this pull request Aug 6, 2024
The following improvements have been made:

* Updated the Go version from 1.13 to 1.15. This is done for two reason.
  First, we should always aim to use the latest version, this is a
  common theme in Go projects and each version provides more performance
  or overall UX improvements we need. Second, starting with Go 1.14, the
  `go` commandline CLI now automatically detects the `vendor/` folder
  and uses that during `go build` and `go test`. This is needed so the
  CI detects any inconsistencies during a pull request and that the
  source code is 100% buildable.

* I removed the `Get dependencies` part because we're vendoring the
  source code and `go get` makes a network call to fetch dependencies.
  We don't need to fetch the dependencies again, because our source of
  truth is the `vendor/` folder. Also, this particular step breaks our
  CI if we start using private dependencies (i.e:
  planetscale/cli#27). We could configure our CI
  to easily so `go get` could work easily, but I'm not sure we need it
  at all due the usage of `vendor/`

* I removed the `-v` flag from `go test -v`. The main reason is that
  `-v` outputs to much information. It' s not needed. The best outcome
  is to output only the issues we see. The benefit is, it's easier to
  parse the CI output for humans and we don't have to scroll hundreds of
  lines.

(nit: the pictures are attached to the GitHub Pull Request, please find
the appropriate PR and check that it out there :))

Before:

```
```

After:

```
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants