Documentation
¶
Index ¶
- func ApplySparseFields[F ~string](query url.Values, entityKey string, fields []F)
- func Execute[R HTTPRequester, T HTTPResponser](ctx context.Context, engine *Engine, requester R) (T, error)
- func ExecuteRaw[R HTTPRequester](ctx context.Context, engine *Engine, requester R) (*http.Response, error)
- func Iterate[T HTTPRequester, R interface{ ... }](ctx context.Context, e *Engine, req T) (next func() (R, bool, error), err error)
- type Date
- type Engine
- type EngineOption
- type HTTPClient
- type HTTPClientFunc
- type HTTPError
- type HTTPRequester
- type HTTPResponser
- type HexColor
- type Money
- type OptionalDateTime
- type OrderMode
- type Relationship
- type Session
- type Time
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplySparseFields ¶ added in v1.17.0
ApplySparseFields adds a `fields[<entityKey>]=...` parameter to query when fields is non-empty. entityKey is the JSON collection name used by the v3 response (e.g. "tasks" for the main task list, "customfields" for a sideload of custom fields). F is constrained to typed string aliases so callers can only pass values that correspond to real JSON attributes on the entity — concrete types are generated alongside each list response.
https://apidocs.teamwork.com/guides/teamwork/sparse-fieldsets
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 ExecuteRaw ¶ added in v1.17.0
func ExecuteRaw[R HTTPRequester](ctx context.Context, engine *Engine, requester R) (*http.Response, error)
ExecuteRaw sends an HTTP request using the provided requester and returns the raw HTTP response. The caller will be responsible for closing the response body. This is useful when using sparse fields, where only a subset of the fields are returned in the response, and the caller needs to handle the response manually.
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 HTTPClientFunc ¶ added in v0.0.8
HTTPClientFunc is a function type that implements the HTTPClient interface.
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 HexColor ¶ added in v1.16.0
type HexColor string
HexColor defines a hexadecimal color.
func NewHexColor ¶ added in v1.16.0
NewHexColor creates a pointer to new hexadecimal color.
func (HexColor) MarshalJSON ¶ added in v1.16.0
MarshalJSON encodes the type to JSON format.
func (*HexColor) UnmarshalJSON ¶ added in v1.16.0
UnmarshalJSON validate and parse v into a hexadecimal type.
type Money ¶
type Money int64
Money represents a monetary value in the API.
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 OrderMode ¶ added in v1.5.0
type OrderMode string
OrderMode specifies the order direction (asc, desc).
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) 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.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
iterator
command
|
|
|
middleware
command
|
|
|
oauth2
command
|
|
|
internal
|
|
|
sparsefieldsgen
command
Command sparsefieldsgen generates typed string enums and per-list containers for v3 sparse fieldsets.
|
Command sparsefieldsgen generates typed string enums and per-list containers for v3 sparse fieldsets. |