Documentation
¶
Index ¶
- func HandleAPIError(err error, label string) (*mcp.CallToolResult, error)
- func ParamGroup(params map[string]any, funcs ...ParamFunc) error
- func SliceToAny[T any](slice []T) []any
- func WebLinker(ctx context.Context, data []byte, buildPath func(map[string]any) string, ...) []byte
- func WebLinkerWithIDPathBuilder(prefix string) func(map[string]any) string
- type ParamFunc
- func OptionalCustomNumericListParam[T interface{ ... }](target T, key string) ParamFunc
- func OptionalDateParam(target *twapi.Date, key string, middlewares ...ParamMiddleware[string]) ParamFunc
- func OptionalDatePointerParam(target **twapi.Date, key string, middlewares ...ParamMiddleware[string]) ParamFunc
- func OptionalLegacyDateParam(target *projects.LegacyDate, key string, ...) ParamFunc
- func OptionalLegacyDatePointerParam(target **projects.LegacyDate, key string, ...) ParamFunc
- func OptionalListParam[T any](target *[]T, key string) ParamFunc
- func OptionalNumericListParam[T ...](target *[]T, key string) ParamFunc
- func OptionalNumericParam[T ...](target *T, key string, middlewares ...ParamMiddleware[T]) ParamFunc
- func OptionalNumericPointerParam[T ...](target **T, key string, middlewares ...ParamMiddleware[T]) ParamFunc
- func OptionalParam[T any](target *T, key string, middlewares ...ParamMiddleware[T]) ParamFunc
- func OptionalPointerParam[T any](target **T, key string, middlewares ...ParamMiddleware[T]) ParamFunc
- func OptionalTimeOnlyParam(target *twapi.Time, key string, middlewares ...ParamMiddleware[string]) ParamFunc
- func OptionalTimeOnlyPointerParam(target **twapi.Time, key string, middlewares ...ParamMiddleware[string]) ParamFunc
- func OptionalTimeParam(target *time.Time, key string, middlewares ...ParamMiddleware[string]) ParamFunc
- func OptionalTimePointerParam(target **time.Time, key string, middlewares ...ParamMiddleware[string]) ParamFunc
- func RequiredDateParam(target *twapi.Date, key string, middlewares ...ParamMiddleware[string]) ParamFunc
- func RequiredLegacyDateParam(target *projects.LegacyDate, key string, ...) ParamFunc
- func RequiredNumericParam[T ...](target *T, key string, middlewares ...ParamMiddleware[T]) ParamFunc
- func RequiredParam[T any](target *T, key string, middlewares ...ParamMiddleware[T]) ParamFunc
- func RequiredTimeOnlyParam(target *twapi.Time, key string, middlewares ...ParamMiddleware[string]) ParamFunc
- func RequiredTimeParam(target *time.Time, key string, middlewares ...ParamMiddleware[string]) ParamFunc
- type ParamMiddleware
- type WebLinkerOption
- type WebLinkerOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleAPIError ¶
func HandleAPIError(err error, label string) (*mcp.CallToolResult, error)
HandleAPIError processes an error returned from the Teamwork API and converts it into an appropriate MCP tool result or error.
func ParamGroup ¶
ParamGroup applies a series of functions to a map of parameters.
func SliceToAny ¶ added in v1.5.3
SliceToAny converts a slice of any type to []any for use with filter.In()
func WebLinker ¶
func WebLinker( ctx context.Context, data []byte, buildPath func(map[string]any) string, opts ...WebLinkerOption, ) []byte
WebLinker processes JSON data to inject web links into entities based on their structure. It decodes the input data as JSON, traverses the top-level fields, and adds a "webLink" field in the meta section to qualifying objects using the provided buildPath function and customer URL from context.
The function handles two types of structures for each top-level field:
- Single objects: {"field": {"id": 123, ...}} → adds webLink to the object
- Arrays of objects: {"field": [{"id": 123, ...}, ...]} → adds webLink to each object in the array
Behavior:
- Returns original data unchanged if JSON parsing fails, customer URL is missing, or buildPath is nil
- Skips fields listed in the ignoreFields option (defaults to "meta" and "included")
- Only processes objects within arrays; non-object array items are left unchanged
- The webLink is constructed as: "{customerURL}/{path}" where path comes from buildPath()
- If buildPath returns an empty string for an object, no webLink is added to that object
Parameters:
- ctx: Context containing customer URL via config.CustomerURLFromContext
- data: Raw JSON data as bytes
- buildPath: Function that generates a path string from an object (e.g., "#users/123")
- opts: Optional configuration (e.g., WebLinkerWithIgnoreFields to skip additional fields)
Returns the modified JSON data as bytes, or the original data if processing fails.
func WebLinkerWithIDPathBuilder ¶
WebLinkerWithIDPathBuilder creates a path builder function for entities with an "id" field. It returns a function that builds a path in the format "prefix/id" for objects containing a non-zero "id" field. Returns an empty string if the "id" field is missing or has a zero value.
Types ¶
type ParamFunc ¶
ParamFunc defines a function type that takes a map of parameters and returns an error. This is used to define functions that can retrieve parameters from a map, converting them to a specific type and applying middleware functions if necessary.
func OptionalCustomNumericListParam ¶
OptionalCustomNumericListParam retrieves an optional list of numeric parameters from a map, converting each item to the specified numeric type using a custom type that implements the Add method. It returns an error if the key is not found or if the type conversion fails.
func OptionalDateParam ¶
func OptionalDateParam( target *twapi.Date, key string, middlewares ...ParamMiddleware[string], ) ParamFunc
OptionalDateParam retrieves an optional date parameter from a map, converting it to a twapi.Date type. It returns an error if the type conversion fails. The date format is expected to be "YYYY-MM-DD". If the target is nil, it returns an error. If the key is not found, it does not set the target.
func OptionalDatePointerParam ¶
func OptionalDatePointerParam( target **twapi.Date, key string, middlewares ...ParamMiddleware[string], ) ParamFunc
OptionalDatePointerParam retrieves an optional date parameter from a map and sets it to a pointer target. It converts the value to a twapi.Date type and applies middleware functions to the value before setting it. The date format is expected to be "YYYY-MM-DD". If the target is nil, it returns an error.
func OptionalLegacyDateParam ¶
func OptionalLegacyDateParam( target *projects.LegacyDate, key string, middlewares ...ParamMiddleware[string], ) ParamFunc
OptionalLegacyDateParam retrieves an optional legacy date parameter from a map, converting it to a projects.LegacyDate type. It returns an error if the type conversion fails. The date format is expected to be "YYYYMMDD". If the target is nil, it returns an error. If the key is not found, it does not set the target.
func OptionalLegacyDatePointerParam ¶
func OptionalLegacyDatePointerParam( target **projects.LegacyDate, key string, middlewares ...ParamMiddleware[string], ) ParamFunc
OptionalLegacyDatePointerParam retrieves an optional date parameter from a map and sets it to a pointer target. It converts the value to a projects.LegacyDate type and applies middleware functions to the value before setting it. The date format is expected to be "YYYYMMDD". If the target is nil, it returns an error.
func OptionalListParam ¶
OptionalListParam retrieves an optional list parameter from a map, converting each item to the specified type. It returns an error if the key is not found or if the type conversion fails. If the target is nil, it returns an error.
func OptionalNumericListParam ¶
func OptionalNumericListParam[T int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | float32 | float64 | projects.LegacyNumber]( target *[]T, key string, ) ParamFunc
OptionalNumericListParam retrieves an optional list of numeric parameters from a map, converting each item to the specified numeric type. It returns an error if the key is not found or if the type conversion fails. If the target is nil, it returns an error.
func OptionalNumericParam ¶
func OptionalNumericParam[T int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | float32 | float64 | projects.LegacyNumber]( target *T, key string, middlewares ...ParamMiddleware[T], ) ParamFunc
OptionalNumericParam retrieves an optional numeric parameter from a map, converting it to the target numeric type. It returns an error if the type conversion fails. If the target is nil, it returns an error.
func OptionalNumericPointerParam ¶
func OptionalNumericPointerParam[T int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | float32 | float64 | projects.LegacyNumber]( target **T, key string, middlewares ...ParamMiddleware[T], ) ParamFunc
OptionalNumericPointerParam retrieves an optional numeric parameter from a map and sets it to a pointer target. It converts the value to the specified numeric type and applies middleware functions to the value before setting it. If the target is nil, it returns an error.
func OptionalParam ¶
func OptionalParam[T any](target *T, key string, middlewares ...ParamMiddleware[T]) ParamFunc
OptionalParam retrieves an optional parameter from a map, converting it to the specified type. It returns an error if the type conversion fails. If the target is nil, it returns an error. It also allows for middleware functions to be applied to the value before setting it to the target. Each middleware function should return a boolean indicating whether to continue processing and an error if any issue occurs.
func OptionalPointerParam ¶
func OptionalPointerParam[T any](target **T, key string, middlewares ...ParamMiddleware[T]) ParamFunc
OptionalPointerParam retrieves an optional parameter from a map and sets it to a pointer target. It converts the value to the specified type and applies middleware functions to the value before setting it. If the target is nil, it returns an error. The middleware functions should return a boolean indicating whether to continue processing and an error if any issue occurs. If the parameter is not found, it does not set the target pointer.
func OptionalTimeOnlyParam ¶
func OptionalTimeOnlyParam( target *twapi.Time, key string, middlewares ...ParamMiddleware[string], ) ParamFunc
OptionalTimeOnlyParam retrieves an optional time parameter from a map, converting it to a twapi.Time type. It returns an error if the type conversion fails. If the target is nil, it returns an error.
func OptionalTimeOnlyPointerParam ¶
func OptionalTimeOnlyPointerParam( target **twapi.Time, key string, middlewares ...ParamMiddleware[string], ) ParamFunc
OptionalTimeOnlyPointerParam retrieves an optional time parameter from a map and sets it to a pointer target. It converts the value to a twapi.Time type and applies middleware functions to the value before setting it. If the target is nil, it returns an error.
func OptionalTimeParam ¶
func OptionalTimeParam( target *time.Time, key string, middlewares ...ParamMiddleware[string], ) ParamFunc
OptionalTimeParam retrieves an optional time parameter from a map, converting it to a time.Time type. It returns an error if the type conversion fails. If the target is nil, it returns an error.
func OptionalTimePointerParam ¶
func OptionalTimePointerParam( target **time.Time, key string, middlewares ...ParamMiddleware[string], ) ParamFunc
OptionalTimePointerParam retrieves an optional time parameter from a map and sets it to a pointer target. It converts the value to a time.Time type and applies middleware functions to the value before setting it. If the target is nil, it returns an error.
func RequiredDateParam ¶
func RequiredDateParam( target *twapi.Date, key string, middlewares ...ParamMiddleware[string], ) ParamFunc
RequiredDateParam retrieves a required date parameter from a map, converting it to a twapi.Date type. It returns an error if the key is not found or if the type conversion fails. The date format is expected to be "YYYY-MM-DD". If the target is nil, it returns an error.
func RequiredLegacyDateParam ¶
func RequiredLegacyDateParam( target *projects.LegacyDate, key string, middlewares ...ParamMiddleware[string], ) ParamFunc
RequiredLegacyDateParam retrieves a required legacy date parameter from a map, converting it to a projects.LegacyDate type. It returns an error if the key is not found or if the type conversion fails. The date format is expected to be "YYYYMMDD". If the target is nil, it returns an error.
func RequiredNumericParam ¶
func RequiredNumericParam[T int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | float32 | float64 | projects.LegacyNumber]( target *T, key string, middlewares ...ParamMiddleware[T], ) ParamFunc
RequiredNumericParam retrieves a required numeric parameter from a map, converting it to the target numeric type. It returns an error if the key is not found or if the type conversion fails. If the target is nil, it returns an error.
func RequiredParam ¶
func RequiredParam[T any](target *T, key string, middlewares ...ParamMiddleware[T]) ParamFunc
RequiredParam retrieves a required parameter from a map, converting it to the specified type. It returns an error if the key is not found or if the type conversion fails. If the target is nil, it returns an error. It also allows for middleware functions to be applied to the value before setting it to the target. Each middleware function should return a boolean indicating whether to continue processing and an error if any issue occurs.
func RequiredTimeOnlyParam ¶
func RequiredTimeOnlyParam( target *twapi.Time, key string, middlewares ...ParamMiddleware[string], ) ParamFunc
RequiredTimeOnlyParam retrieves a required time parameter from a map, converting it to a twapi.Time type. It returns an error if the key is not found or if the type conversion fails. If the target is nil, it returns an error.
func RequiredTimeParam ¶
func RequiredTimeParam( target *time.Time, key string, middlewares ...ParamMiddleware[string], ) ParamFunc
RequiredTimeParam retrieves a required time parameter from a map, converting it to a time.Time type. It returns an error if the key is not found or if the type conversion fails. If the target is nil, it returns an error.
type ParamMiddleware ¶
ParamMiddleware defines a function type that takes a pointer to a specific type and returns a boolean indicating whether to continue processing and an error if any issue occurs. This is used to apply middleware functions to parameters before they are set to the target.
func RestrictValues ¶
func RestrictValues[T comparable](allowedValues ...T) ParamMiddleware[T]
RestrictValues restricts the values of a parameter to a predefined set of allowed values. It can be used as a middleware function in the Param or OptionalParam functions.
type WebLinkerOption ¶
type WebLinkerOption func(*WebLinkerOptions)
WebLinkerOption is a function that configures the WebLinkerOptions.
func WebLinkerWithIgnoreFields ¶
func WebLinkerWithIgnoreFields(fields ...string) WebLinkerOption
WebLinkerWithIgnoreFields creates an option to specify additional fields that should be ignored when processing JSON data for web link injection. These fields will be skipped in addition to the default knownRootFields ("meta" and "included").
type WebLinkerOptions ¶
type WebLinkerOptions struct {
// contains filtered or unexported fields
}
WebLinkerOptions holds configuration options for the WebLinker function.