Skip to content

Commit 77b93ab

Browse files
authored
ACG: Decompose client interface (#27)
1 parent 5c8b2ec commit 77b93ab

File tree

6 files changed

+141
-9
lines changed

6 files changed

+141
-9
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,10 @@ The `client.go` file contains an `interface` defining the programming interface
205205

206206
```golang
207207
type VisAdminClient interface {
208-
CreateOrUpdateClient(request *CreateOrUpdateClientRequest) (CreateOrUpdateClientResponse, error)
208+
CreateOrUpdateClientMethod
209+
}
210+
type CreateOrUpdateClientMethod interface {
211+
CreateOrUpdateClient(request *CreateOrUpdateClientRequest) (CreateOrUpdateClientResponse, error)
209212
}
210213
```
211214

example/client.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,29 @@ import (
1111
)
1212

1313
type TodoServiceClient interface {
14+
DeleteTodosMethod
15+
ListTodosMethod
16+
PostTodoMethod
17+
DeleteTodoMethod
18+
GetTodoMethod
19+
PatchTodoMethod
20+
}
21+
type DeleteTodosMethod interface {
1422
DeleteTodos(request *DeleteTodosRequest) (DeleteTodosResponse, error)
23+
}
24+
type ListTodosMethod interface {
1525
ListTodos(request *ListTodosRequest) (ListTodosResponse, error)
26+
}
27+
type PostTodoMethod interface {
1628
PostTodo(request *PostTodoRequest) (PostTodoResponse, error)
29+
}
30+
type DeleteTodoMethod interface {
1731
DeleteTodo(request *DeleteTodoRequest) (DeleteTodoResponse, error)
32+
}
33+
type GetTodoMethod interface {
1834
GetTodo(request *GetTodoRequest) (GetTodoResponse, error)
35+
}
36+
type PatchTodoMethod interface {
1937
PatchTodo(request *PatchTodoRequest) (PatchTodoResponse, error)
2038
}
2139

example/framework.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,10 @@ func (v *Validator) ValidateRequest(request interface{}) (*ValidationErrorsObjec
582582
}
583583

584584
var (
585-
GitCommit string = "0f410ab08724ac9dae51e4558de0c01638cfc8ff"
586-
GitBranch string = "HEAD"
585+
GitCommit string = "a6eac71c7893e75f0c294f2a5dc85bae5bfa4723"
586+
GitBranch string = "feature/interface_cleanup"
587587
GitTag string = "v1.0.0"
588-
BuildTime string = "Sa 6. Nov 15:03:27 CET 2021"
588+
BuildTime string = "Sa 27. Nov 10:55:34 CET 2021"
589589
)
590590

591591
type VersionInfo struct {

generator/client_generator.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,24 @@ func (gen *goClientGenerator) Generate(path, pckg string, generatePrometheus boo
4040

4141
file := file.NewFile(pckg)
4242

43+
var clientInterfaceMethods []jen.Code
4344
var clientMethods []jen.Code
4445
operations := make([]*Operation, 0)
4546
if err := gen.WalkOperations(func(operation *Operation) error {
4647
methodDef := jen.Id(strings.Title(operation.ID)).Params(jen.Id("request").Op("*").Id(strings.Title(operation.ID+"Request"))).Params(jen.Id(strings.Title(operation.ID+"Response")), jen.Error())
47-
clientMethods = append(clientMethods, methodDef)
48+
methodInterfaceIdentifier := strings.Title(strings.Title(operation.ID)+"Method")
49+
clientMethods = append(clientMethods, jen.Id(methodInterfaceIdentifier).Interface(methodDef))
50+
clientInterfaceMethods = append(clientInterfaceMethods, jen.Id(methodInterfaceIdentifier))
4851
operations = append(operations, operation)
4952
return nil
5053
}); err != nil {
5154
return errors.Wrap(err, "error generating operations")
5255
}
5356

54-
file.Type().Id(strings.Title(gen.clientName())).Interface(clientMethods...)
57+
file.Type().Id(strings.Title(gen.clientName())).Interface(clientInterfaceMethods...)
58+
for _, clientMethod := range clientMethods {
59+
file.Type().Add(clientMethod)
60+
}
5561

5662
gen.generateConstructor(gen.clientName(), pckg, operations, generatePrometheus, file)
5763

tests/api/client.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,145 @@ import (
1313
)
1414

1515
type VisAdminClient interface {
16+
GetClientsMethod
17+
DeleteClientMethod
18+
GetClientMethod
19+
CreateOrUpdateClientMethod
20+
GetViewsSetsMethod
21+
DeleteViewsSetMethod
22+
GetViewsSetMethod
23+
ActivateViewsSetMethod
24+
CreateOrUpdateViewsSetMethod
25+
ShowVehicleInViewMethod
26+
GetPermissionsMethod
27+
DestroySessionMethod
28+
GetUserInfoMethod
29+
CreateSessionMethod
30+
GetUsersMethod
31+
DeleteUserMethod
32+
GetUserMethod
33+
CreateOrUpdateUserMethod
34+
GetBookingMethod
35+
GetBookingsMethod
36+
ListModelsMethod
37+
GetClassesMethod
38+
CodeMethod
39+
DeleteCustomerSessionMethod
40+
CreateCustomerSessionMethod
41+
DownloadNestedFileMethod
42+
DownloadImageMethod
43+
ListElementsMethod
44+
FileUploadMethod
45+
DownloadFileMethod
46+
FindByTagsMethod
47+
GenericFileDownloadMethod
48+
GetRentalMethod
49+
GetShoesMethod
50+
PostUploadMethod
51+
}
52+
type GetClientsMethod interface {
1653
GetClients(request *GetClientsRequest) (GetClientsResponse, error)
54+
}
55+
type DeleteClientMethod interface {
1756
DeleteClient(request *DeleteClientRequest) (DeleteClientResponse, error)
57+
}
58+
type GetClientMethod interface {
1859
GetClient(request *GetClientRequest) (GetClientResponse, error)
60+
}
61+
type CreateOrUpdateClientMethod interface {
1962
CreateOrUpdateClient(request *CreateOrUpdateClientRequest) (CreateOrUpdateClientResponse, error)
63+
}
64+
type GetViewsSetsMethod interface {
2065
GetViewsSets(request *GetViewsSetsRequest) (GetViewsSetsResponse, error)
66+
}
67+
type DeleteViewsSetMethod interface {
2168
DeleteViewsSet(request *DeleteViewsSetRequest) (DeleteViewsSetResponse, error)
69+
}
70+
type GetViewsSetMethod interface {
2271
GetViewsSet(request *GetViewsSetRequest) (GetViewsSetResponse, error)
72+
}
73+
type ActivateViewsSetMethod interface {
2374
ActivateViewsSet(request *ActivateViewsSetRequest) (ActivateViewsSetResponse, error)
75+
}
76+
type CreateOrUpdateViewsSetMethod interface {
2477
CreateOrUpdateViewsSet(request *CreateOrUpdateViewsSetRequest) (CreateOrUpdateViewsSetResponse, error)
78+
}
79+
type ShowVehicleInViewMethod interface {
2580
ShowVehicleInView(request *ShowVehicleInViewRequest) (ShowVehicleInViewResponse, error)
81+
}
82+
type GetPermissionsMethod interface {
2683
GetPermissions(request *GetPermissionsRequest) (GetPermissionsResponse, error)
84+
}
85+
type DestroySessionMethod interface {
2786
DestroySession(request *DestroySessionRequest) (DestroySessionResponse, error)
87+
}
88+
type GetUserInfoMethod interface {
2889
GetUserInfo(request *GetUserInfoRequest) (GetUserInfoResponse, error)
90+
}
91+
type CreateSessionMethod interface {
2992
CreateSession(request *CreateSessionRequest) (CreateSessionResponse, error)
93+
}
94+
type GetUsersMethod interface {
3095
GetUsers(request *GetUsersRequest) (GetUsersResponse, error)
96+
}
97+
type DeleteUserMethod interface {
3198
DeleteUser(request *DeleteUserRequest) (DeleteUserResponse, error)
99+
}
100+
type GetUserMethod interface {
32101
GetUser(request *GetUserRequest) (GetUserResponse, error)
102+
}
103+
type CreateOrUpdateUserMethod interface {
33104
CreateOrUpdateUser(request *CreateOrUpdateUserRequest) (CreateOrUpdateUserResponse, error)
105+
}
106+
type GetBookingMethod interface {
34107
GetBooking(request *GetBookingRequest) (GetBookingResponse, error)
108+
}
109+
type GetBookingsMethod interface {
35110
GetBookings(request *GetBookingsRequest) (GetBookingsResponse, error)
111+
}
112+
type ListModelsMethod interface {
36113
ListModels(request *ListModelsRequest) (ListModelsResponse, error)
114+
}
115+
type GetClassesMethod interface {
37116
GetClasses(request *GetClassesRequest) (GetClassesResponse, error)
117+
}
118+
type CodeMethod interface {
38119
Code(request *CodeRequest) (CodeResponse, error)
120+
}
121+
type DeleteCustomerSessionMethod interface {
39122
DeleteCustomerSession(request *DeleteCustomerSessionRequest) (DeleteCustomerSessionResponse, error)
123+
}
124+
type CreateCustomerSessionMethod interface {
40125
CreateCustomerSession(request *CreateCustomerSessionRequest) (CreateCustomerSessionResponse, error)
126+
}
127+
type DownloadNestedFileMethod interface {
41128
DownloadNestedFile(request *DownloadNestedFileRequest) (DownloadNestedFileResponse, error)
129+
}
130+
type DownloadImageMethod interface {
42131
DownloadImage(request *DownloadImageRequest) (DownloadImageResponse, error)
132+
}
133+
type ListElementsMethod interface {
43134
ListElements(request *ListElementsRequest) (ListElementsResponse, error)
135+
}
136+
type FileUploadMethod interface {
44137
FileUpload(request *FileUploadRequest) (FileUploadResponse, error)
138+
}
139+
type DownloadFileMethod interface {
45140
DownloadFile(request *DownloadFileRequest) (DownloadFileResponse, error)
141+
}
142+
type FindByTagsMethod interface {
46143
FindByTags(request *FindByTagsRequest) (FindByTagsResponse, error)
144+
}
145+
type GenericFileDownloadMethod interface {
47146
GenericFileDownload(request *GenericFileDownloadRequest) (GenericFileDownloadResponse, error)
147+
}
148+
type GetRentalMethod interface {
48149
GetRental(request *GetRentalRequest) (GetRentalResponse, error)
150+
}
151+
type GetShoesMethod interface {
49152
GetShoes(request *GetShoesRequest) (GetShoesResponse, error)
153+
}
154+
type PostUploadMethod interface {
50155
PostUpload(request *PostUploadRequest) (PostUploadResponse, error)
51156
}
52157

tests/api/framework.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,10 @@ func (v *Validator) ValidateRequest(request interface{}) (*ValidationErrorsObjec
582582
}
583583

584584
var (
585-
GitCommit string = "0f410ab08724ac9dae51e4558de0c01638cfc8ff"
586-
GitBranch string = "HEAD"
585+
GitCommit string = "5c8b2ec75cd8f17faea02dfc4bba67fe24683cb7"
586+
GitBranch string = "feature/interface_cleanup"
587587
GitTag string = "v1.0.0"
588-
BuildTime string = "Sa 6. Nov 15:03:27 CET 2021"
588+
BuildTime string = "Sa 27. Nov 10:43:52 CET 2021"
589589
)
590590

591591
type VersionInfo struct {

0 commit comments

Comments
 (0)