Documentation
¶
Index ¶
- func CreateLogDirectory(logPath string)
- func Error(msg string, args ...interface{})
- func Fatal(msg string, args ...interface{})
- func Info(msg string, args ...interface{})
- func MarshalByMethod(v interface{}, method string) ([]byte, error)
- func ParseHTTPStatusCodeInResponse(response *http.Response) (*http.Response, error)
- func ParseResponse(model interface{}, response *http.Response) error
- func ParseTemplatedPath(template string, path string) (map[string]string, error)
- func ParseURLParams(model interface{}) url.Values
- func Warning(msg string, args ...interface{})
- type Credential
- type HTTPError
- type Logger
- type MethodMarshaler
- type OpenAPIParameterStyle
- type SdkTransport
- type Ticker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateLogDirectory ¶ added in v1.4.0
func CreateLogDirectory(logPath string)
Checks if log directory exists. It creates the log directory, if it doesn't exist.
func Fatal ¶ added in v1.4.0
func Fatal(msg string, args ...interface{})
Prints a fatal error message and exits.
func MarshalByMethod ¶
MarshalByMethod marshals any json tagged struct fields matching the method being specified.
If the `methods:` tag is specified for the field, then the field is marshaled if the input method is present in the comma-separated list within the tag (case insensitive).
If no `methods:` tag is present then it is presumed that the field is valid for all methods, so the field is marshaled.
Example:
```go
type Model struct {
// Marshal this field for PATCH or POST methods
A string `json:"a" methods:"PATCH,POST"`
// Never marshal this field (no methods)
B string `json:"b" methods:""`
// Always marshal this field (all methods)
C string `json:"c"`
// Marshal this field for POST methods but only if value is not empty
D string `json:"d,omitempty" methods:"POST"`
}
model := Model{
A: "valueA",
B: "valueB",
D: "",
}
// A is marshaled because it matches the POST method
// B is not marshaled because the `methods:""` tag prevents marshaling for all methods
// C is marshaled because omitting the `methods:` tag always marshals the field
// D is not marshaled because even though the POST method matches the tag, the value is empty
// and omitempty is specified
bytes, err := MarshalByMethod(model, "POST") // string(bytes) == `{"a":"valueA","c":""}`
```
func ParseHTTPStatusCodeInResponse ¶
ParseHTTPStatusCodeInResponse returns http response and HTTPError struct based on response status code
func ParseResponse ¶
ParseResponse parses json-formatted http response and decodes it into pre-defined models
func ParseTemplatedPath ¶
ParseTemplatedPath parses a url-like path using an input template and outputs a map of matched values. template should place the named params to be extracted in single braces, e.g. ParseTemplatedPath("{my_param1}/literal/path/{my_param2}/parts", "foo/literal/path/bar/parts") returns {"my_param1": "foo", "my_param2": "bar"}
func ParseURLParams ¶
ParseURLParams parses a struct into url params based on its "key" tag It parses basic values and slices, and will parse structs recursively see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#style-examples for details about style and explode formatting
Types ¶
type Credential ¶
type Credential struct {
// contains filtered or unexported fields
}
Credential is a simple string whose value is redacted when converted to a string via the Stringer interface in order to prevent accidental logging or other unintentional disclosure - value is retrieved using ClearText() method
func NewCredential ¶
func NewCredential(s string) *Credential
NewCredential creates a Credential from a simple string
func (*Credential) ClearText ¶
func (c *Credential) ClearText() string
ClearText returns the actual cleartext string value
type HTTPError ¶
type HTTPError struct {
HTTPStatusCode int
HTTPStatus string
Message string `json:"message,omitempty"`
Code string `json:"code,omitempty"`
MoreInfo string `json:"moreInfo,omitempty"`
Details interface{} `json:"details,omitempty"`
}
HTTPError is raised when status code is not 2xx
type Logger ¶
type Logger interface {
Print(v ...interface{})
}
Logger compatible with standard "log" library
type MethodMarshaler ¶
MethodMarshaler is the interface implemented by types that can marshal themselves into valid JSON according to the input http method
type OpenAPIParameterStyle ¶
type OpenAPIParameterStyle string
const ( // StyleForm corresponds to style: form which is the default for query parameters StyleForm OpenAPIParameterStyle = "form" )
type SdkTransport ¶
type SdkTransport struct {
// contains filtered or unexported fields
}
SdkTransport is to define a transport RoundTripper with user-defined logger
func NewCustomSdkTransport ¶
func NewCustomSdkTransport(logger Logger, transport *http.Transport) *SdkTransport
NewCustomSdkTransport Creates a RoundTripper with user defined logger and http.Transport
func NewSdkTransport ¶
func NewSdkTransport(logger Logger) *SdkTransport
NewSdkTransport Creates a RoundTripper with user defined logger
type Ticker ¶
type Ticker struct {
// contains filtered or unexported fields
}
Ticker is a wrapper of time.Ticker with additional functionality
func NewTicker ¶
NewTicker spits out a pointer to Ticker model. It sets ticker to stop state by default