net

package
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2018 License: GPL-3.0 Imports: 18 Imported by: 10

Documentation

Overview

HTTP related utility tools

Package net is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var (
	FileNotFound = errors.New("could not find raw data at url")
)

Functions

func InitNegroni

func InitNegroni(appName string, handler http.Handler) (n *negroni.Negroni)

InitNegroni is a helper function for starting up http servers. it will create a new Negroni instance, use attach a logrus instance with a json formatter, and register the log instance with the appName it will also attach a handler, so really all you have to call is Run() on the returned instance

func JSONApiError

func JSONApiError(w http.ResponseWriter, statusCode int, errorDesc string, err error)

JSONApiError sets the status code. The error description and error string are written RESTError struct and encoded to JSON, written to response writer. Also logs the error using ocelog

func NewWebSocketConn

func NewWebSocketConn() *testWebSocketConn

Types

type ApiHttpError

type ApiHttpError struct {
	ErrorDescription string
	Error            string
	Status           int
}

HttpError is the format that errors should be returned from all REST api's - see usage in admin.go

type AppContextHandler

type AppContextHandler struct {
	Ctx interface{}
	H   func(interface{}, http.ResponseWriter, *http.Request)
}

for initializing connections / configurations once, then passing it around for lifetime of application Ctx can be anything, just have to set H to be HandleFunc that also takes in the context as first value. in handle func, cast Ctx interface{} to your struct that you initialized in startup so you can access fields for ex: ``` appctx := &MyContext{config: "config yay wooo the best"} muxi.Handle("/ws/builds/{hash}", &ocenet.AppContextHandler{appctx, stream}).Methods("GET") ...

func stream(ctx interface{}, w http.ResponseWriter, r *http.Request){
    a := ctx.(*MyContext)
    // do stuff

... ```

func (*AppContextHandler) ServeHTTP

func (ah *AppContextHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HttpClient

type HttpClient interface {
	//GetUrl will perform a GET on the specified URL and return the appropriate protobuf response
	GetUrl(url string, unmarshalObj proto.Message) error

	//GetUrlRawData will return raw data at specified URL in a byte array
	GetUrlRawData(url string) ([]byte, error)

	//GetUrlResponse uses the OAuth Client to make an HTTP get call, and returns a normal response object. Caller is expected to close response body as per usual
	GetUrlResponse(url string) (*http.Response, error)

	//PostUrl will perform a post on the specified URL. It takes in a json formatted body
	//and returns an (optional) protobuf response
	PostUrl(url string, body string, unmarshalObj proto.Message) error

	// PostURLForm will post form data and return an http response
	PostUrlForm(url string, form url.Values) (*http.Response, error)

	// GetAuthClient will return the oauth authenticated client for more flexibility
	GetAuthClient() *http.Client
}

HttpClient is an http client interface that you can implement.

type MockHttpClient

type MockHttpClient struct {
	// contains filtered or unexported fields
}

MockHttpClient is a mock of HttpClient interface

func NewMockHttpClient

func NewMockHttpClient(ctrl *gomock.Controller) *MockHttpClient

NewMockHttpClient creates a new mock instance

func (*MockHttpClient) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockHttpClient) GetAuthClient

func (m *MockHttpClient) GetAuthClient() *http.Client

GetAuthClient mocks base method

func (*MockHttpClient) GetUrl

func (m *MockHttpClient) GetUrl(url string, unmarshalObj proto.Message) error

GetUrl mocks base method

func (*MockHttpClient) GetUrlRawData

func (m *MockHttpClient) GetUrlRawData(url string) ([]byte, error)

GetUrlRawData mocks base method

func (*MockHttpClient) GetUrlResponse

func (m *MockHttpClient) GetUrlResponse(url string) (*http.Response, error)

GetUrlResponse mocks base method

func (*MockHttpClient) PostUrl

func (m *MockHttpClient) PostUrl(url, body string, unmarshalObj proto.Message) error

PostUrl mocks base method

func (*MockHttpClient) PostUrlForm

func (m *MockHttpClient) PostUrlForm(url string, form url.Values) (*http.Response, error)

PostUrlForm mocks base method

type MockHttpClientMockRecorder

type MockHttpClientMockRecorder struct {
	// contains filtered or unexported fields
}

MockHttpClientMockRecorder is the mock recorder for MockHttpClient

func (*MockHttpClientMockRecorder) GetAuthClient

func (mr *MockHttpClientMockRecorder) GetAuthClient() *gomock.Call

GetAuthClient indicates an expected call of GetAuthClient

func (*MockHttpClientMockRecorder) GetUrl

func (mr *MockHttpClientMockRecorder) GetUrl(url, unmarshalObj interface{}) *gomock.Call

GetUrl indicates an expected call of GetUrl

func (*MockHttpClientMockRecorder) GetUrlRawData

func (mr *MockHttpClientMockRecorder) GetUrlRawData(url interface{}) *gomock.Call

GetUrlRawData indicates an expected call of GetUrlRawData

func (*MockHttpClientMockRecorder) GetUrlResponse

func (mr *MockHttpClientMockRecorder) GetUrlResponse(url interface{}) *gomock.Call

GetUrlResponse indicates an expected call of GetUrlResponse

func (*MockHttpClientMockRecorder) PostUrl

func (mr *MockHttpClientMockRecorder) PostUrl(url, body, unmarshalObj interface{}) *gomock.Call

PostUrl indicates an expected call of PostUrl

func (*MockHttpClientMockRecorder) PostUrlForm

func (mr *MockHttpClientMockRecorder) PostUrlForm(url, form interface{}) *gomock.Call

PostUrlForm indicates an expected call of PostUrlForm

type MockOAuthClientCreds

type MockOAuthClientCreds struct {
	// contains filtered or unexported fields
}

MockOAuthClientCreds is a mock of OAuthClientCreds interface

func NewMockOAuthClientCreds

func NewMockOAuthClientCreds(ctrl *gomock.Controller) *MockOAuthClientCreds

NewMockOAuthClientCreds creates a new mock instance

func (*MockOAuthClientCreds) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockOAuthClientCreds) GetClientId

func (m *MockOAuthClientCreds) GetClientId() string

GetClientId mocks base method

func (*MockOAuthClientCreds) GetClientSecret

func (m *MockOAuthClientCreds) GetClientSecret() string

GetClientSecret mocks base method

func (*MockOAuthClientCreds) GetTokenURL

func (m *MockOAuthClientCreds) GetTokenURL() string

GetTokenURL mocks base method

type MockOAuthClientCredsMockRecorder

type MockOAuthClientCredsMockRecorder struct {
	// contains filtered or unexported fields
}

MockOAuthClientCredsMockRecorder is the mock recorder for MockOAuthClientCreds

func (*MockOAuthClientCredsMockRecorder) GetClientId

func (mr *MockOAuthClientCredsMockRecorder) GetClientId() *gomock.Call

GetClientId indicates an expected call of GetClientId

func (*MockOAuthClientCredsMockRecorder) GetClientSecret

func (mr *MockOAuthClientCredsMockRecorder) GetClientSecret() *gomock.Call

GetClientSecret indicates an expected call of GetClientSecret

func (*MockOAuthClientCredsMockRecorder) GetTokenURL

func (mr *MockOAuthClientCredsMockRecorder) GetTokenURL() *gomock.Call

GetTokenURL indicates an expected call of GetTokenURL

type OAuthClient

type OAuthClient struct {
	AuthClient  *http.Client
	Unmarshaler jsonpb.Unmarshaler
}

OAuthClient is a client containing a pre-authenticated http client as returned by golang's oauth2 clientcredentials package as well as a protobuf json unmarshaler

func (*OAuthClient) GetAuthClient

func (oc *OAuthClient) GetAuthClient() *http.Client

func (*OAuthClient) GetUrl

func (oc *OAuthClient) GetUrl(url string, unmarshalObj proto.Message) error

func (*OAuthClient) GetUrlRawData

func (oc *OAuthClient) GetUrlRawData(url string) ([]byte, error)

func (*OAuthClient) GetUrlResponse

func (oc *OAuthClient) GetUrlResponse(url string) (*http.Response, error)

GetUrlResponse just uses the OAuth client to get the url.

func (*OAuthClient) PostUrl

func (oc *OAuthClient) PostUrl(url string, body string, unmarshalObj proto.Message) error

func (*OAuthClient) PostUrlForm

func (oc *OAuthClient) PostUrlForm(url string, form url.Values) (*http.Response, error)

func (*OAuthClient) Setup

func (oc *OAuthClient) Setup(config OAuthClientCreds) (string, error)

Setup takes in OAuth2 credentials and returns a temporary token along with an error. uses two-legged OAuth model.

func (*OAuthClient) SetupNoAuthentication

func (oc *OAuthClient) SetupNoAuthentication()

SetupNoAuthentication will set up OAuthClient to make calls with a regular *http.Client, all calls will be unauthenticated

func (*OAuthClient) SetupStaticToken

func (oc *OAuthClient) SetupStaticToken(config OAuthClientCreds) (string, error)

SetupStaticToken will set up the OAuthClient to use a static token, will assume it will never expire.

Used for github api authentication, or any service that does not support two-legged OAuth

type OAuthClientCreds

type OAuthClientCreds interface {
	GetClientId() string
	GetClientSecret() string
	GetTokenURL() string
}

type OcenetWs

type OcenetWs struct {
	// contains filtered or unexported fields
}

fulfills the Streamable interface in ocelot

func Upgrade

func Upgrade(upgrader websocket.Upgrader, w http.ResponseWriter, r *http.Request) (*OcenetWs, error)

Upgrade returns an OcenetWs object with a websocket connection upgraded by the ResponseWriter and the request

func (*OcenetWs) Finish

func (ws *OcenetWs) Finish(done chan int)

func (*OcenetWs) SendError

func (ws *OcenetWs) SendError(errorDesc []byte)

func (*OcenetWs) SendIt

func (ws *OcenetWs) SendIt(data []byte) error

type WebsocketEy

type WebsocketEy interface {
	SetWriteDeadline(t time.Time) error
	WriteMessage(messageType int, data []byte) error
	Close() error
}

testable interface for using websockets

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL