generated from sacloud/go-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
applications.go
139 lines (126 loc) · 3.99 KB
/
applications.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Copyright 2021-2024 The sacloud/apprun-api-go authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package apprun
import (
"context"
v1 "github.com/sacloud/apprun-api-go/apis/v1"
)
type ApplicationAPI interface {
// List アプリケーション一覧を取得
List(ctx context.Context, params *v1.ListApplicationsParams) (*v1.HandlerListApplications, error)
// Create アプリケーションを作成
Create(ctx context.Context, params *v1.PostApplicationBody) (*v1.Application, error)
// Read アプリケーション詳細を取得
Read(ctx context.Context, id string) (*v1.Application, error)
// Update アプリケーションを部分的に変更
Update(ctx context.Context, id string, params *v1.PatchApplicationBody) (*v1.HandlerPatchApplication, error)
// Delete アプリケーションを削除
Delete(ctx context.Context, id string) error
// ReadStatus アプリケーションステータスを取得
ReadStatus(ctx context.Context, id string) (*v1.HandlerGetApplicationStatusResponse, error)
}
var _ ApplicationAPI = (*applicationOp)(nil)
type applicationOp struct {
client *Client
}
// NewApplicationOp アプリケーション操作関連API
func NewApplicationOp(client *Client) ApplicationAPI {
return &applicationOp{client: client}
}
func (op *applicationOp) List(ctx context.Context, params *v1.ListApplicationsParams) (*v1.HandlerListApplications, error) {
apiClient, err := op.client.apiClient()
if err != nil {
return nil, err
}
resp, err := apiClient.ListApplicationsWithResponse(ctx, params)
if err != nil {
return nil, err
}
applications, err := resp.Result()
if err != nil {
return nil, err
}
return applications, nil
}
func (op *applicationOp) Create(ctx context.Context, params *v1.PostApplicationBody) (*v1.Application, error) {
apiClient, err := op.client.apiClient()
if err != nil {
return nil, err
}
resp, err := apiClient.PostApplicationWithResponse(ctx, *params)
if err != nil {
return nil, err
}
application, err := resp.Result()
if err != nil {
return nil, err
}
return application, nil
}
func (op *applicationOp) Update(ctx context.Context, id string, params *v1.PatchApplicationBody) (*v1.HandlerPatchApplication, error) {
apiClient, err := op.client.apiClient()
if err != nil {
return nil, err
}
resp, err := apiClient.PatchApplicationWithResponse(ctx, id, *params)
if err != nil {
return nil, err
}
patchApplication, err := resp.Result()
if err != nil {
return nil, err
}
return patchApplication, nil
}
func (op *applicationOp) Read(ctx context.Context, id string) (*v1.Application, error) {
apiClient, err := op.client.apiClient()
if err != nil {
return nil, err
}
resp, err := apiClient.GetApplicationWithResponse(ctx, id)
if err != nil {
return nil, err
}
application, err := resp.Result()
if err != nil {
return nil, err
}
return application, nil
}
func (op *applicationOp) Delete(ctx context.Context, id string) error {
apiClient, err := op.client.apiClient()
if err != nil {
return err
}
resp, err := apiClient.DeleteApplicationWithResponse(ctx, id)
if err != nil {
return err
}
return resp.Result()
}
func (op *applicationOp) ReadStatus(ctx context.Context, id string) (*v1.HandlerGetApplicationStatusResponse, error) {
apiClient, err := op.client.apiClient()
if err != nil {
return nil, err
}
resp, err := apiClient.GetApplicationStatusWithResponse(ctx, id)
if err != nil {
return nil, err
}
applicationStatus, err := resp.Result()
if err != nil {
return nil, err
}
return applicationStatus, nil
}