Documentation
ยถ
Index ยถ
- func Execute[R HTTPRequester, T HTTPResponser](ctx context.Context, engine *Engine, requester R) (T, error)
- func Iterate[T HTTPRequester, R interface{ ... }](ctx context.Context, e *Engine, req T) (next func() (R, bool, error), err error)
- func Ptr[T any](v T) *T
- type Date
- type Engine
- type EngineOption
- type HTTPClient
- type HTTPError
- type HTTPRequester
- type HTTPResponser
- type Money
- type OptionalDateTime
- type Relationship
- type Session
- type Time
Constants ยถ
This section is empty.
Variables ยถ
This section is empty.
Functions ยถ
func Execute ยถ
func Execute[R HTTPRequester, T HTTPResponser](ctx context.Context, engine *Engine, requester R) (T, error)
Execute sends an HTTP request using the provided requester and handles the response using the provided responser.
func Iterate ยถ added in v0.0.7
func Iterate[T HTTPRequester, R interface { HTTPResponser Iterate() *T }](ctx context.Context, e *Engine, req T) (next func() (R, bool, error), err error)
Iterate allows scanning through paginated results from the Teamwork API.
Types ยถ
type Date ยถ
Date is a type alias for time.Time, used to represent date values in the API.
func (Date) MarshalJSON ยถ
MarshalJSON encodes the Date as a string in the format "2006-01-02".
func (Date) MarshalText ยถ
MarshalText encodes the Date as a string in the format "2006-01-02".
func (Date) String ยถ
String returns the string representation of the Date in the format "2006-01-02".
func (*Date) UnmarshalJSON ยถ
UnmarshalJSON decodes a JSON string into a Date type.
func (*Date) UnmarshalText ยถ
UnmarshalText decodes a text string into a Date type. This is required when using Date type as a map key.
type Engine ยถ
type Engine struct {
// contains filtered or unexported fields
}
Engine is the main structure that handles communication with the Teamwork API.
func NewEngine ยถ
func NewEngine(session Session, opts ...EngineOption) *Engine
NewEngine creates a new Engine instance with the provided HTTP client and session.
type EngineOption ยถ
type EngineOption func(*Engine)
EngineOption is a function that modifies the Engine configuration.
func WithHTTPClient ยถ
func WithHTTPClient(client HTTPClient) EngineOption
WithHTTPClient sets the HTTP client for the Engine. By default, it uses http.DefaultClient. When setting the HTTP client, any middlewares that were added using WithMiddleware before this call will be ignored.
func WithLogger ยถ
func WithLogger(logger *slog.Logger) EngineOption
WithLogger sets the logger for the Engine. By default, it uses slog.Default().
func WithMiddleware ยถ added in v0.0.7
func WithMiddleware(middleware func(HTTPClient) HTTPClient) EngineOption
WithMiddleware adds a middleware to the Engine. Middlewares are applied in the order they are added.
type HTTPClient ยถ added in v0.0.7
HTTPClient is an interface that defines the methods required for an HTTP client. This allows for adding middlewares and easier testing.
type HTTPError ยถ added in v0.0.3
HTTPError represents an error response from the API.
func NewHTTPError ยถ added in v0.0.3
NewHTTPError creates a new HTTPError from an http.Response.
type HTTPRequester ยถ
type HTTPRequester interface {
HTTPRequest(ctx context.Context, server string) (*http.Request, error)
}
HTTPRequester knows how to create an HTTP request for a specific entity.
type HTTPResponser ยถ
HTTPResponser knows how to handle an HTTP response for a specific entity.
type OptionalDateTime ยถ
OptionalDateTime is a type alias for time.Time, used to represent date and time values in the API. The difference is that it will accept empty strings as valid values.
func (OptionalDateTime) MarshalJSON ยถ
func (d OptionalDateTime) MarshalJSON() ([]byte, error)
MarshalJSON encodes the OptionalDateTime as a string in the format "2006-01-02T15:04:05Z07:00".
func (*OptionalDateTime) UnmarshalJSON ยถ
func (d *OptionalDateTime) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes a JSON string into an OptionalDateTime type.
type Relationship ยถ added in v0.0.3
type Relationship struct {
ID int64 `json:"id"`
Type string `json:"type"`
Meta map[string]any `json:"meta,omitempty"`
}
Relationship describes the relation between the main entity and a sideload type.
type Session ยถ
Session is an interface that defines the methods required for a session to authenticate requests to the Teamwork Engine.
type Time ยถ
Time is a type alias for time.Time, used to represent time values in the API.
func (Time) MarshalJSON ยถ
MarshalJSON encodes the Time as a string in the format "15:04:05".
func (Time) MarshalText ยถ
MarshalText encodes the Time as a string in the format "15:04:05".
func (Time) String ยถ
String returns the string representation of the Time in the format "15:04:05".
func (*Time) UnmarshalJSON ยถ
UnmarshalJSON decodes a JSON string into a Date type.
func (*Time) UnmarshalText ยถ
UnmarshalText decodes a text string into a Time type. This is required when using Time type as a map key.