Skip to content

Commit d202b2f

Browse files
authored
refactor: use protocol api (#77)
* refactor: use protocol api * fix: go mod * chore: update * chore: update * chore: go version * fix: test * chore: golang lint
1 parent 63c9d73 commit d202b2f

31 files changed

+412
-602
lines changed

.github/workflows/tests.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,20 @@ jobs:
1313
- uses: actions/checkout@v3
1414
- uses: actions/setup-go@v3
1515
with:
16-
go-version: 1.19
16+
go-version: 1.23.2
1717
- run: go generate ./...
1818
- name: golangci-lint
19-
uses: golangci/golangci-lint-action@v3
19+
uses: golangci/golangci-lint-action@v6
2020
with:
21-
version: v1.49.0
22-
args: -v
23-
skip-cache: true
21+
version: v1.60.2
22+
args: --verbose --timeout 20m --max-same-issues=30 --allow-parallel-runners
2423
go-tidy:
2524
runs-on: ubuntu-latest
2625
steps:
2726
- uses: actions/checkout@v3
2827
- uses: actions/setup-go@v3
2928
with:
30-
go-version: 1.19
29+
go-version: 1.23.2
3130
- name: Verify tidy
3231
run: |
3332
go mod tidy
@@ -41,7 +40,7 @@ jobs:
4140
fetch-depth: 0
4241
- uses: actions/setup-go@v3
4342
with:
44-
go-version: 1.19
43+
go-version: 1.23.2
4544
- uses: hashicorp/setup-terraform@v2
4645
with:
4746
terraform_version: "1.3.*"

.golangci.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ linters-settings:
7373
disabled: true
7474
- name: early-return
7575
disabled: true
76+
- name: use-any
77+
disabled: true
78+
- name: unchecked-type-assertion
79+
disabled: true
7680
gocritic:
7781
disabled-checks:
7882
- ifElseChain

api/auth.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

api/client.go

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
11
package api
22

3-
import "context"
3+
import (
4+
"context"
5+
6+
v1pb "buf.build/gen/go/bytebase/bytebase/protocolbuffers/go/v1"
7+
)
48

59
// Client is the API message for Bytebase OpenAPI client.
610
type Client interface {
711
// Auth
812
// Login will login the user and get the response.
9-
Login() (*AuthResponse, error)
13+
Login() (*v1pb.LoginResponse, error)
1014

1115
// Environment
1216
// CreateEnvironment creates the environment.
13-
CreateEnvironment(ctx context.Context, environmentID string, create *EnvironmentMessage) (*EnvironmentMessage, error)
17+
CreateEnvironment(ctx context.Context, environmentID string, create *v1pb.Environment) (*v1pb.Environment, error)
1418
// GetEnvironment gets the environment by id.
15-
GetEnvironment(ctx context.Context, environmentName string) (*EnvironmentMessage, error)
19+
GetEnvironment(ctx context.Context, environmentName string) (*v1pb.Environment, error)
1620
// ListEnvironment finds all environments.
17-
ListEnvironment(ctx context.Context, showDeleted bool) (*ListEnvironmentMessage, error)
21+
ListEnvironment(ctx context.Context, showDeleted bool) (*v1pb.ListEnvironmentsResponse, error)
1822
// UpdateEnvironment updates the environment.
19-
UpdateEnvironment(ctx context.Context, patch *EnvironmentPatchMessage) (*EnvironmentMessage, error)
23+
UpdateEnvironment(ctx context.Context, patch *v1pb.Environment, updateMask []string) (*v1pb.Environment, error)
2024
// DeleteEnvironment deletes the environment.
2125
DeleteEnvironment(ctx context.Context, environmentName string) error
2226
// UndeleteEnvironment undeletes the environment.
23-
UndeleteEnvironment(ctx context.Context, environmentName string) (*EnvironmentMessage, error)
27+
UndeleteEnvironment(ctx context.Context, environmentName string) (*v1pb.Environment, error)
2428

2529
// Instance
2630
// ListInstance will return instances.
27-
ListInstance(ctx context.Context, find *InstanceFindMessage) (*ListInstanceMessage, error)
31+
ListInstance(ctx context.Context, showDeleted bool) (*v1pb.ListInstancesResponse, error)
2832
// GetInstance gets the instance by id.
29-
GetInstance(ctx context.Context, instanceName string) (*InstanceMessage, error)
33+
GetInstance(ctx context.Context, instanceName string) (*v1pb.Instance, error)
3034
// CreateInstance creates the instance.
31-
CreateInstance(ctx context.Context, instanceID string, instance *InstanceMessage) (*InstanceMessage, error)
35+
CreateInstance(ctx context.Context, instanceID string, instance *v1pb.Instance) (*v1pb.Instance, error)
3236
// UpdateInstance updates the instance.
33-
UpdateInstance(ctx context.Context, patch *InstancePatchMessage) (*InstanceMessage, error)
37+
UpdateInstance(ctx context.Context, patch *v1pb.Instance, updateMasks []string) (*v1pb.Instance, error)
3438
// DeleteInstance deletes the instance.
3539
DeleteInstance(ctx context.Context, instanceName string) error
3640
// UndeleteInstance undeletes the instance.
37-
UndeleteInstance(ctx context.Context, instanceName string) (*InstanceMessage, error)
41+
UndeleteInstance(ctx context.Context, instanceName string) (*v1pb.Instance, error)
3842
// SyncInstanceSchema will trigger the schema sync for an instance.
3943
SyncInstanceSchema(ctx context.Context, instanceName string) error
4044

@@ -50,23 +54,23 @@ type Client interface {
5054

5155
// Database
5256
// GetDatabase gets the database by instance resource id and the database name.
53-
GetDatabase(ctx context.Context, databaseName string) (*DatabaseMessage, error)
57+
GetDatabase(ctx context.Context, databaseName string) (*v1pb.Database, error)
5458
// ListDatabase list the databases.
55-
ListDatabase(ctx context.Context, find *DatabaseFindMessage) (*ListDatabaseMessage, error)
59+
ListDatabase(ctx context.Context, instanceID, filter string) (*v1pb.ListDatabasesResponse, error)
5660
// UpdateDatabase patches the database.
57-
UpdateDatabase(ctx context.Context, patch *DatabasePatchMessage) (*DatabaseMessage, error)
61+
UpdateDatabase(ctx context.Context, patch *v1pb.Database, updateMasks []string) (*v1pb.Database, error)
5862

5963
// Project
6064
// GetProject gets the project by resource id.
61-
GetProject(ctx context.Context, projectName string) (*ProjectMessage, error)
65+
GetProject(ctx context.Context, projectName string) (*v1pb.Project, error)
6266
// ListProject list the projects,
63-
ListProject(ctx context.Context, showDeleted bool) (*ListProjectMessage, error)
67+
ListProject(ctx context.Context, showDeleted bool) (*v1pb.ListProjectsResponse, error)
6468
// CreateProject creates the project.
65-
CreateProject(ctx context.Context, projectID string, project *ProjectMessage) (*ProjectMessage, error)
69+
CreateProject(ctx context.Context, projectID string, project *v1pb.Project) (*v1pb.Project, error)
6670
// UpdateProject updates the project.
67-
UpdateProject(ctx context.Context, patch *ProjectPatchMessage) (*ProjectMessage, error)
71+
UpdateProject(ctx context.Context, patch *v1pb.Project, updateMask []string) (*v1pb.Project, error)
6872
// DeleteProject deletes the project.
6973
DeleteProject(ctx context.Context, projectName string) error
7074
// UndeleteProject undeletes the project.
71-
UndeleteProject(ctx context.Context, projectName string) (*ProjectMessage, error)
75+
UndeleteProject(ctx context.Context, projectName string) (*v1pb.Project, error)
7276
}

api/common.go

Lines changed: 0 additions & 45 deletions
This file was deleted.

api/data_source.go

Lines changed: 0 additions & 25 deletions
This file was deleted.

api/database.go

Lines changed: 0 additions & 35 deletions
This file was deleted.

api/environment.go

Lines changed: 0 additions & 36 deletions
This file was deleted.

api/instance.go

Lines changed: 0 additions & 34 deletions
This file was deleted.

api/project.go

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)