Documentation ¶
Overview ¶
HTTP related utility tools
Package net is a generated GoMock package.
Index ¶
- Variables
- func InitNegroni(appName string, handler http.Handler) (n *negroni.Negroni)
- func JSONApiError(w http.ResponseWriter, statusCode int, errorDesc string, err error)
- func NewWebSocketConn() *testWebSocketConn
- type ApiHttpError
- type AppContextHandler
- type HttpClient
- type MockHttpClient
- func (m *MockHttpClient) EXPECT() *MockHttpClientMockRecorder
- func (m *MockHttpClient) GetAuthClient() *http.Client
- func (m *MockHttpClient) GetUrl(url string, unmarshalObj proto.Message) error
- func (m *MockHttpClient) GetUrlRawData(url string) ([]byte, error)
- func (m *MockHttpClient) GetUrlResponse(url string) (*http.Response, error)
- func (m *MockHttpClient) PostUrl(url, body string, unmarshalObj proto.Message) error
- func (m *MockHttpClient) PostUrlForm(url string, form url.Values) (*http.Response, error)
- type MockHttpClientMockRecorder
- func (mr *MockHttpClientMockRecorder) GetAuthClient() *gomock.Call
- func (mr *MockHttpClientMockRecorder) GetUrl(url, unmarshalObj interface{}) *gomock.Call
- func (mr *MockHttpClientMockRecorder) GetUrlRawData(url interface{}) *gomock.Call
- func (mr *MockHttpClientMockRecorder) GetUrlResponse(url interface{}) *gomock.Call
- func (mr *MockHttpClientMockRecorder) PostUrl(url, body, unmarshalObj interface{}) *gomock.Call
- func (mr *MockHttpClientMockRecorder) PostUrlForm(url, form interface{}) *gomock.Call
- type MockOAuthClientCreds
- type MockOAuthClientCredsMockRecorder
- type OAuthClient
- func (oc *OAuthClient) GetAuthClient() *http.Client
- func (oc *OAuthClient) GetUrl(url string, unmarshalObj proto.Message) error
- func (oc *OAuthClient) GetUrlRawData(url string) ([]byte, error)
- func (oc *OAuthClient) GetUrlResponse(url string) (*http.Response, error)
- func (oc *OAuthClient) PostUrl(url string, body string, unmarshalObj proto.Message) error
- func (oc *OAuthClient) PostUrlForm(url string, form url.Values) (*http.Response, error)
- func (oc *OAuthClient) Setup(config OAuthClientCreds) (string, error)
- func (oc *OAuthClient) SetupNoAuthentication()
- func (oc *OAuthClient) SetupStaticToken(config OAuthClientCreds) (string, error)
- type OAuthClientCreds
- type OcenetWs
- type WebsocketEy
Constants ¶
This section is empty.
Variables ¶
var (
FileNotFound = errors.New("could not find raw data at url")
)
Functions ¶
func InitNegroni ¶
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 ¶
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 ¶
func (m *MockHttpClient) EXPECT() *MockHttpClientMockRecorder
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 ¶
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 ¶
func (m *MockOAuthClientCreds) EXPECT() *MockOAuthClientCredsMockRecorder
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) PostUrlForm ¶
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 OcenetWs ¶
type OcenetWs struct {
// contains filtered or unexported fields
}
fulfills the Streamable interface in ocelot