Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1114 from yunfeiyanggzq/bridge_3
Browse files Browse the repository at this point in the history
feature:modify client api
  • Loading branch information
starnop committed Dec 3, 2019
2 parents d1577a8 + 5e3fab2 commit e49d466
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 14 deletions.
21 changes: 20 additions & 1 deletion client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,28 @@ import (
// CommonAPIClient defines common methods of api client.
type CommonAPIClient interface {
PreheatAPIClient
PeerAPIClient
TaskAPIClient
}

// PreheatAPIClient defines methods of Container client.
type PreheatAPIClient interface {
PreheatCreate(ctx context.Context, config *types.PreheatCreateRequest) (*types.PreheatCreateResponse, error)
PreheatCreate(ctx context.Context, request *types.PreheatCreateRequest) (preheatCreateResponse *types.PreheatCreateResponse, err error)
PreheatInfo(ctx context.Context, id string) (preheatInfoResponse *types.PreheatInfo, err error)
}

// PeerAPIClient defines methods of peer related client.
type PeerAPIClient interface {
PeerCreate(ctx context.Context, request *types.PeerCreateRequest) (peerCreateResponse *types.PeerCreateResponse, err error)
PeerDelete(ctx context.Context, id string) error
PeerInfo(ctx context.Context, id string) (peerInfoResponse *types.PeerInfo, err error)
PeerList(ctx context.Context, id string) (peersInfoResponse []*types.PeerInfo, err error)
}

// TaskAPIClient defines methods of task related client.
type TaskAPIClient interface {
TaskCreate(ctx context.Context, request *types.TaskCreateRequest) (taskCreateResponse *types.TaskCreateResponse, err error)
TaskDelete(ctx context.Context, id string) error
TaskInfo(ctx context.Context, id string) (taskInfoResponse *types.TaskInfo, err error)
TaskUpdate(ctx context.Context, id string, config *types.TaskUpdateRequest) error
}
4 changes: 2 additions & 2 deletions client/peer_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
)

// PeerCreate creates a peer node in supernode.
func (client *APIClient) PeerCreate(ctx context.Context, config *types.PeerCreateRequest) (*types.PeerCreateResponse, error) {
resp, err := client.post(ctx, "/peers", nil, config, nil)
func (client *APIClient) PeerCreate(ctx context.Context, request *types.PeerCreateRequest) (peerCreateResponse *types.PeerCreateResponse, err error) {
resp, err := client.post(ctx, "/api/v1/peers", nil, request, nil)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion client/peer_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

// PeerDelete deletes the specified peer in supernode.
func (client *APIClient) PeerDelete(ctx context.Context, id string) error {
resp, err := client.delete(ctx, "/peers/"+id, nil, nil)
resp, err := client.delete(ctx, "/api/v1/peers/"+id, nil, nil)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions client/peer_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ import (
)

// PeerInfo gets detailed information of a peer in supernode.
func (client *APIClient) PeerInfo(ctx context.Context, id string) (*types.PeerInfo, error) {
resp, err := client.get(ctx, "/peers/"+id, nil, nil)
func (client *APIClient) PeerInfo(ctx context.Context, id string) (peerInfoResponse *types.PeerInfo, err error) {
resp, err := client.get(ctx, "/api/v1/peers/"+id, nil, nil)
if err != nil {
return nil, err
}

peer := &types.PeerInfo{}

err = decodeBody(peer, resp.Body)
ensureCloseReader(resp)

Expand Down
4 changes: 2 additions & 2 deletions client/peer_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
)

// PeerList lists detailed information of all peers in supernode.
func (client *APIClient) PeerList(ctx context.Context, id string) ([]*types.PeerInfo, error) {
resp, err := client.get(ctx, "/peers", nil, nil)
func (client *APIClient) PeerList(ctx context.Context, id string) (peersInfoResponse []*types.PeerInfo, err error) {
resp, err := client.get(ctx, "/api/v1/peers", nil, nil)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion client/preheat_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

// PreheatCreate creates a preheat task.
func (client *APIClient) PreheatCreate(ctx context.Context, config *types.PreheatCreateRequest) (*types.PreheatCreateResponse, error) {
func (client *APIClient) PreheatCreate(ctx context.Context, config *types.PreheatCreateRequest) (preheatCreateResponse *types.PreheatCreateResponse, err error) {
resp, err := client.post(ctx, "/preheats", nil, config, nil)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion client/preheat_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

// PreheatInfo gets detailed information of a preheat task.
func (client *APIClient) PreheatInfo(ctx context.Context, id string) (*types.PreheatInfo, error) {
func (client *APIClient) PreheatInfo(ctx context.Context, id string) (preheatInfoResponse *types.PreheatInfo, err error) {
resp, err := client.get(ctx, "/preheats/"+id, nil, nil)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions client/task_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
)

// TaskCreate creates a task in supernode.
func (client *APIClient) TaskCreate(ctx context.Context, config *types.TaskCreateRequest) (*types.TaskCreateResponse, error) {
resp, err := client.post(ctx, "/tasks", nil, config, nil)
func (client *APIClient) TaskCreate(ctx context.Context, request *types.TaskCreateRequest) (taskCreateResponse *types.TaskCreateResponse, err error) {
resp, err := client.post(ctx, "/api/v1/tasks", nil, request, nil)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion client/task_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

// TaskInfo gets detailed information of a task in supernode.
func (client *APIClient) TaskInfo(ctx context.Context, id string) (*types.TaskInfo, error) {
func (client *APIClient) TaskInfo(ctx context.Context, id string) (taskInfoResponse *types.TaskInfo, err error) {
resp, err := client.get(ctx, "/tasks/"+id, nil, nil)
if err != nil {
return nil, err
Expand Down

0 comments on commit e49d466

Please sign in to comment.