mirror of
https://github.com/rancher/norman.git
synced 2025-09-02 07:44:51 +00:00
Add interface for APIBaseClient
Problem: There are three clients based off the APIBaseClient so three code paths are needed to make the same type of call in each client Solution: Add an interface so any client that satisfies it can be used to make these calls
This commit is contained in:
committed by
Darren Shepherd
parent
93bfc4ea3a
commit
9846d7349c
@@ -1,19 +0,0 @@
|
|||||||
package clientbase
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/rancher/norman/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type APIBaseClient struct {
|
|
||||||
Ops *APIOperations
|
|
||||||
Opts *ClientOpts
|
|
||||||
Types map[string]types.Schema
|
|
||||||
}
|
|
||||||
|
|
||||||
type APIOperations struct {
|
|
||||||
Opts *ClientOpts
|
|
||||||
Types map[string]types.Schema
|
|
||||||
Client *http.Client
|
|
||||||
}
|
|
@@ -28,6 +28,25 @@ var (
|
|||||||
dialer = &websocket.Dialer{}
|
dialer = &websocket.Dialer{}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type APIBaseClientInterface interface {
|
||||||
|
Websocket(url string, headers map[string][]string) (*websocket.Conn, *http.Response, error)
|
||||||
|
List(schemaType string, opts *types.ListOpts, respObject interface{}) error
|
||||||
|
Post(url string, createObj interface{}, respObject interface{}) error
|
||||||
|
GetLink(resource types.Resource, link string, respObject interface{}) error
|
||||||
|
Create(schemaType string, createObj interface{}, respObject interface{}) error
|
||||||
|
Update(schemaType string, existing *types.Resource, updates interface{}, respObject interface{}) error
|
||||||
|
ByID(schemaType string, id string, respObject interface{}) error
|
||||||
|
Delete(existing *types.Resource) error
|
||||||
|
Reload(existing *types.Resource, output interface{}) error
|
||||||
|
Action(schemaType string, action string, existing *types.Resource, inputObject, respObject interface{}) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type APIBaseClient struct {
|
||||||
|
Ops *APIOperations
|
||||||
|
Opts *ClientOpts
|
||||||
|
Types map[string]types.Schema
|
||||||
|
}
|
||||||
|
|
||||||
type ClientOpts struct {
|
type ClientOpts struct {
|
||||||
URL string
|
URL string
|
||||||
AccessKey string
|
AccessKey string
|
||||||
|
@@ -12,6 +12,12 @@ import (
|
|||||||
"github.com/rancher/norman/types"
|
"github.com/rancher/norman/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type APIOperations struct {
|
||||||
|
Opts *ClientOpts
|
||||||
|
Types map[string]types.Schema
|
||||||
|
Client *http.Client
|
||||||
|
}
|
||||||
|
|
||||||
func (a *APIOperations) setupRequest(req *http.Request) {
|
func (a *APIOperations) setupRequest(req *http.Request) {
|
||||||
req.Header.Add("Authorization", a.Opts.getAuthHeader())
|
req.Header.Add("Authorization", a.Opts.getAuthHeader())
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user