1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-01 23:36:58 +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:
Dan Ramich
2018-04-10 13:29:10 -07:00
committed by Darren Shepherd
parent 93bfc4ea3a
commit 9846d7349c
3 changed files with 25 additions and 19 deletions

View File

@@ -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
}

View File

@@ -28,6 +28,25 @@ var (
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 {
URL string
AccessKey string

View File

@@ -12,6 +12,12 @@ import (
"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) {
req.Header.Add("Authorization", a.Opts.getAuthHeader())
}