api

package
v0.0.0-...-c9de236 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 17 Imported by: 0

README

API Package

A type-safe, declarative HTTP API framework for Go built on generics. Define your API as a struct, and the framework handles routing, serialization, OpenAPI generation, and client creation automatically.

Import Convention

This package follows the conv prefix naming convention for imports:

import (
    convAPI "github.com/sofmon/convention/lib/api"
    convAuth "github.com/sofmon/convention/lib/auth"
    convCtx "github.com/sofmon/convention/lib/ctx"
)

Quick Start

1. Define Your API
package def

import (
    convAPI "github.com/sofmon/convention/lib/api"
    convAuth "github.com/sofmon/convention/lib/auth"
)

type API struct {
    GetHealth convAPI.Out[string] `api:"GET /health/"`

    GetUser    convAPI.OutP1[User, UserID]           `api:"GET /users/{user_id}"`
    CreateUser convAPI.InOut[CreateUserReq, User]    `api:"POST /users"`
    DeleteUser convAPI.TriggerP1[UserID]             `api:"DELETE /users/{user_id}"`
    UpdateUser convAPI.InP2[UpdateUserReq, convAuth.Tenant, UserID] `api:"PUT /tenants/{tenant}/users/{user_id}"`

    GetOpenAPI convAPI.OpenAPI `api:"GET /openapi.yaml"`
}

var Client = convAPI.NewClient[API]("api.example.com", 443)

func OpenAPI() convAPI.OpenAPI {
    return convAPI.NewOpenAPI().
        WithDescription("User management API").
        WithServers("https://api.example.com")
}
2. Implement Handlers
package svc

import (
    convAPI "github.com/sofmon/convention/lib/api"
    convCtx "github.com/sofmon/convention/lib/ctx"

    "myapp/def"
)

func ListenAndServe(ctx convCtx.Context) error {
    svr, err := convAPI.NewServer(ctx, "", 443, authPolicy, &def.API{
        GetHealth:  convAPI.NewOut(handleGetHealth),
        GetUser:    convAPI.NewOutP1(handleGetUser),
        CreateUser: convAPI.NewInOut(handleCreateUser),
        DeleteUser: convAPI.NewTriggerP1(handleDeleteUser),
        UpdateUser: convAPI.NewInP2(handleUpdateUser),
        GetOpenAPI: def.OpenAPI(),
    })
    if err != nil {
        return err
    }
    return svr.ListenAndServe()
}

func handleGetHealth(ctx convCtx.Context) (string, error) {
    return "OK", nil
}

func handleGetUser(ctx convCtx.Context, id UserID) (User, error) {
    // Implementation
}

func handleCreateUser(ctx convCtx.Context, req CreateUserReq) (User, error) {
    // Implementation
}

func handleDeleteUser(ctx convCtx.Context, id UserID) error {
    // Implementation
}

func handleUpdateUser(ctx convCtx.Context, tenant convAuth.Tenant, id UserID, req UpdateUserReq) error {
    // Implementation
}
3. Use the Client
client := def.Client

user, err := client.GetUser.Call(ctx, "user-123")
if err != nil {
    if convAPI.ErrorHasCode(err, convAPI.ErrorCodeNotFound) {
        // Handle not found
    }
    return err
}

Handler Types

Type Description Handler Signature Client Call
Trigger No input or output func(ctx) error Call(ctx) error
In[T] Input only func(ctx, in T) error Call(ctx, in T) error
Out[T] Output only func(ctx) (T, error) Call(ctx) (T, error)
InOut[I,O] Input and output func(ctx, in I) (O, error) Call(ctx, in I) (O, error)
Raw Direct HTTP access func(ctx, w, r) Call(ctx, body) error
Path Parameters

Each handler type has variants supporting 1-5 path parameters (P1 through P5):

// Single parameter
GetUser convAPI.OutP1[User, UserID] `api:"GET /users/{user_id}"`

// Two parameters
GetUserPost convAPI.OutP2[Post, UserID, PostID] `api:"GET /users/{user_id}/posts/{post_id}"`

// Three parameters
GetComment convAPI.OutP3[Comment, Tenant, UserID, CommentID] `api:"GET /tenants/{t}/users/{u}/comments/{c}"`

Parameter types must be based on string (using Go's type constraint ~string):

type UserID string
type PostID string

Handler signature with parameters:

func handleGetUserPost(ctx convCtx.Context, userId UserID, postId PostID) (Post, error) {
    // Parameters are extracted from URL path in order
}

API Tag Format

`api:"METHOD /path/to/endpoint?query=type|description"`
  • METHOD (optional): HTTP method (GET, POST, PUT, DELETE, PATCH, HEAD). Defaults to GET.
  • Path: Static segments and {param} placeholders.
  • Query params (optional): ?name=type|description for OpenAPI documentation.

Examples:

`api:"GET /users"`                           // Simple GET
`api:"POST /users"`                          // POST with body
`api:"/users/{id}"`                          // GET is default
`api:"GET /search?q=string|Search query"`    // With query param docs
`api:"GET /items?limit=integer|Max results&offset=integer|Skip count"`

OpenAPI Generation

The package auto-generates OpenAPI 3.0 YAML documentation:

func OpenAPI() convAPI.OpenAPI {
    return convAPI.NewOpenAPI().
        WithDescription("API description").
        WithServers(
            "https://api.example.com",
            "https://api.dev.example.com",
        ).
        WithTypeSubstitutions(
            // Map types with custom marshaling to their JSON structure
            convAPI.NewTypeSubstitution[
                Money,           // Original type
                struct {         // How it appears in JSON
                    Amount   float64 `json:"amount"`
                    Currency string  `json:"currency"`
                },
            ](),
        ).
        WithEnums(
            // Document enum values for string-based types
            convAPI.NewEnum(StatusDraft, StatusActive, StatusArchived),
            convAPI.NewEnum(RoleAdmin, RoleUser, RoleGuest),
        )
}

Pre/Post Checks

Add authorization or validation logic that runs before or after handlers:

handler := convAPI.NewOutP1(handleGetUser).
    WithPreCheck(func(ctx convCtx.Context) error {
        // Runs before handler - e.g., permission check
        if !hasPermission(ctx) {
            return convAPI.NewError(ctx, 403, convAPI.ErrorCodeForbidden, "access denied", nil)
        }
        return nil
    }).
    WithPostCheck(func(ctx convCtx.Context) error {
        // Runs after handler - e.g., audit logging
        return nil
    })

Error Handling

Creating Errors
return convAPI.NewError(ctx, http.StatusNotFound, convAPI.ErrorCodeNotFound, "user not found", nil)
Error Codes
Code Description
ErrorCodeInternalError Server-side error (500)
ErrorCodeNotFound Resource not found (404)
ErrorCodeBadRequest Invalid request (400)
ErrorCodeForbidden Authentication failed (403)
ErrorCodeUnauthorized Authorization failed (401)
Checking Errors (Client-side)
user, err := client.GetUser.Call(ctx, id)
if err != nil {
    if convAPI.ErrorHasCode(err, convAPI.ErrorCodeNotFound) {
        // Handle 404
    }
    return err
}

Server Creation

Full Server with TLS
svr, err := convAPI.NewServer(ctx, "0.0.0.0", 443, authPolicy, &API{...})
if err != nil {
    return err
}
return svr.ListenAndServe() // Uses TLS certificates from config
HTTP Handler Only

For integration with existing servers or custom TLS setup:

handler := convAPI.NewHandler(ctx, "api.example.com", 443, authCheck, &API{...})
http.Handle("/", handler)

Helper Functions

// Receive JSON body in Raw handlers
req, err := convAPI.ReceiveJSON[CreateUserReq](r)

// Serve JSON response in Raw handlers
convAPI.ServeJSON(w, response)

// Serve error response
convAPI.ServeError(ctx, w, http.StatusBadRequest, convAPI.ErrorCodeBadRequest, "invalid input", err)

Type Mapping

Go types are automatically converted to OpenAPI schemas:

Go Type OpenAPI Type
string, ~string string
int, int64, etc. integer
float32, float64 number
bool boolean
time.Time string (format: date-time)
[]T array
map[K]V object (additionalProperties)
struct object
*T Same as T, but optional

Field naming follows these rules:

  • Uses json tag if present
  • Otherwise converts to snake_case (UserIDuser_id)
  • omitempty makes fields optional in the schema

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorHasCode

func ErrorHasCode(err error, code ErrorCode) bool

func NewClient

func NewClient[svcT any](host string, port int) (svc *svcT)

func NewEnum

func NewEnum[T ~string](values ...T) (e enum)

func NewError

func NewError(ctx convCtx.Context, status int, code ErrorCode, message string, inner error) error

func NewHandler

func NewHandler(ctx convCtx.Context, host string, port int, check convAuth.Check, svc any, logCalls bool) http.Handler

func NewServer

func NewServer(ctx convCtx.Context, host string, port int, policy convAuth.Policy, svc any) (srv *server, err error)

func NewTypeSubstitution

func NewTypeSubstitution[fromT any, toT any]() (ts typeSubstitution)

func ReceiveJSON

func ReceiveJSON[T any](r *http.Request) (res T, err error)

func ServeError

func ServeError(ctx convCtx.Context, w http.ResponseWriter, status int, code ErrorCode, message string, inner error)

func ServeJSON

func ServeJSON(w http.ResponseWriter, body any) error

Types

type Check

type Check func(ctx convCtx.Context) error

type Error

type Error struct {
	URL     string    `json:"url,omitempty"`
	Method  string    `json:"method,omitempty"`
	Status  int       `json:"status,omitempty"`
	Code    ErrorCode `json:"code,omitempty"`
	Scope   string    `json:"scope,omitempty"`
	Message string    `json:"message,omitempty"`
	Inner   *Error    `json:"inner,omitempty"`
}

func (Error) Error

func (e Error) Error() string

type ErrorCode

type ErrorCode string
const (
	ErrorCodeInternalError        ErrorCode = "internal_error"
	ErrorCodeNotFound             ErrorCode = "not_found"
	ErrorCodeBadRequest           ErrorCode = "bad_request"
	ErrorCodeForbidden            ErrorCode = "forbidden"
	ErrorCodeUnauthorized         ErrorCode = "unauthorized"
	ErrorCodeUnexpectedStatusCode ErrorCode = "unexpected_status_code"
)

type In

type In[inT any] struct {
	// contains filtered or unexported fields
}

func NewIn

func NewIn[inT any](fn func(ctx convCtx.Context, in inT) error) In[inT]

func (*In[inT]) Call

func (x *In[inT]) Call(ctx convCtx.Context, in inT) (err error)

func (In[inT]) WithPostCheck

func (x In[inT]) WithPostCheck(check Check) In[inT]

func (In[inT]) WithPreCheck

func (x In[inT]) WithPreCheck(check Check) In[inT]

type InOut

type InOut[inT, outT any] struct {
	// contains filtered or unexported fields
}

func NewInOut

func NewInOut[inT, outT any](fn func(ctx convCtx.Context, in inT) (outT, error)) InOut[inT, outT]

func (*InOut[inT, outT]) Call

func (x *InOut[inT, outT]) Call(ctx convCtx.Context, in inT) (out outT, err error)

func (InOut[inT, outT]) WithPostCheck

func (x InOut[inT, outT]) WithPostCheck(check Check) InOut[inT, outT]

func (InOut[inT, outT]) WithPreCheck

func (x InOut[inT, outT]) WithPreCheck(check Check) InOut[inT, outT]

type InOutP1

type InOutP1[inT, outT any, p1T ~string] struct {
	// contains filtered or unexported fields
}

func NewInOutP1

func NewInOutP1[inT, outT any, p1T ~string](fn func(ctx convCtx.Context, p1 p1T, in inT) (outT, error)) InOutP1[inT, outT, p1T]

func (*InOutP1[inT, outT, p1T]) Call

func (x *InOutP1[inT, outT, p1T]) Call(ctx convCtx.Context, p1 p1T, in inT) (out outT, err error)

func (InOutP1[inT, outT, p1T]) WithPostCheck

func (x InOutP1[inT, outT, p1T]) WithPostCheck(check Check) InOutP1[inT, outT, p1T]

func (InOutP1[inT, outT, p1T]) WithPreCheck

func (x InOutP1[inT, outT, p1T]) WithPreCheck(check Check) InOutP1[inT, outT, p1T]

type InOutP2

type InOutP2[inT, outT any, p1T, p2T ~string] struct {
	// contains filtered or unexported fields
}

func NewInOutP2

func NewInOutP2[inT, outT any, p1T, p2T ~string](fn func(ctx convCtx.Context, p1 p1T, p2 p2T, in inT) (outT, error)) InOutP2[inT, outT, p1T, p2T]

func (*InOutP2[inT, outT, p1T, p2T]) Call

func (x *InOutP2[inT, outT, p1T, p2T]) Call(ctx convCtx.Context, p1 p1T, p2 p2T, in inT) (out outT, err error)

func (InOutP2[inT, outT, p1T, p2T]) WithPostCheck

func (x InOutP2[inT, outT, p1T, p2T]) WithPostCheck(check Check) InOutP2[inT, outT, p1T, p2T]

func (InOutP2[inT, outT, p1T, p2T]) WithPreCheck

func (x InOutP2[inT, outT, p1T, p2T]) WithPreCheck(check Check) InOutP2[inT, outT, p1T, p2T]

type InOutP3

type InOutP3[inT, outT any, p1T, p2T, p3T ~string] struct {
	// contains filtered or unexported fields
}

func NewInOutP3

func NewInOutP3[inT, outT any, p1T, p2T, p3T ~string](fn func(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, in inT) (outT, error)) InOutP3[inT, outT, p1T, p2T, p3T]

func (*InOutP3[inT, outT, p1T, p2T, p3T]) Call

func (x *InOutP3[inT, outT, p1T, p2T, p3T]) Call(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, in inT) (out outT, err error)

func (InOutP3[inT, outT, p1T, p2T, p3T]) WithPostCheck

func (x InOutP3[inT, outT, p1T, p2T, p3T]) WithPostCheck(check Check) InOutP3[inT, outT, p1T, p2T, p3T]

func (InOutP3[inT, outT, p1T, p2T, p3T]) WithPreCheck

func (x InOutP3[inT, outT, p1T, p2T, p3T]) WithPreCheck(check Check) InOutP3[inT, outT, p1T, p2T, p3T]

type InOutP4

type InOutP4[inT, outT any, p1T, p2T, p3T, p4T ~string] struct {
	// contains filtered or unexported fields
}

func NewInOutP4

func NewInOutP4[inT, outT any, p1T, p2T, p3T, p4T ~string](fn func(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, p4 p4T, in inT) (outT, error)) InOutP4[inT, outT, p1T, p2T, p3T, p4T]

func (*InOutP4[inT, outT, p1T, p2T, p3T, p4T]) Call

func (x *InOutP4[inT, outT, p1T, p2T, p3T, p4T]) Call(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, p4 p4T, in inT) (out outT, err error)

func (InOutP4[inT, outT, p1T, p2T, p3T, p4T]) WithPostCheck

func (x InOutP4[inT, outT, p1T, p2T, p3T, p4T]) WithPostCheck(check Check) InOutP4[inT, outT, p1T, p2T, p3T, p4T]

func (InOutP4[inT, outT, p1T, p2T, p3T, p4T]) WithPreCheck

func (x InOutP4[inT, outT, p1T, p2T, p3T, p4T]) WithPreCheck(check Check) InOutP4[inT, outT, p1T, p2T, p3T, p4T]

type InOutP5

type InOutP5[inT, outT any, p1T, p2T, p3T, p4T, p5T ~string] struct {
	// contains filtered or unexported fields
}

func NewInOutP5

func NewInOutP5[inT, outT any, p1T, p2T, p3T, p4T, p5T ~string](fn func(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, p4 p4T, p5 p5T, in inT) (outT, error)) InOutP5[inT, outT, p1T, p2T, p3T, p4T, p5T]

func (*InOutP5[inT, outT, p1T, p2T, p3T, p4T, p5T]) Call

func (x *InOutP5[inT, outT, p1T, p2T, p3T, p4T, p5T]) Call(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, p4 p4T, p5 p5T, in inT) (out outT, err error)

func (InOutP5[inT, outT, p1T, p2T, p3T, p4T, p5T]) WithPostCheck

func (x InOutP5[inT, outT, p1T, p2T, p3T, p4T, p5T]) WithPostCheck(check Check) InOutP5[inT, outT, p1T, p2T, p3T, p4T, p5T]

func (InOutP5[inT, outT, p1T, p2T, p3T, p4T, p5T]) WithPreCheck

func (x InOutP5[inT, outT, p1T, p2T, p3T, p4T, p5T]) WithPreCheck(check Check) InOutP5[inT, outT, p1T, p2T, p3T, p4T, p5T]

type InP1

type InP1[inT any, p1T ~string] struct {
	// contains filtered or unexported fields
}

func NewInP1

func NewInP1[inT any, p1T ~string](fn func(ctx convCtx.Context, p1 p1T, in inT) error) InP1[inT, p1T]

func (*InP1[inT, p1T]) Call

func (x *InP1[inT, p1T]) Call(ctx convCtx.Context, p1 p1T, in inT) (err error)

func (InP1[inT, p1T]) WithPostCheck

func (x InP1[inT, p1T]) WithPostCheck(check Check) InP1[inT, p1T]

func (InP1[inT, p1T]) WithPreCheck

func (x InP1[inT, p1T]) WithPreCheck(check Check) InP1[inT, p1T]

type InP2

type InP2[inT any, p1T, p2T ~string] struct {
	// contains filtered or unexported fields
}

func NewInP2

func NewInP2[inT any, p1T, p2T ~string](fn func(ctx convCtx.Context, p1 p1T, p2 p2T, in inT) error) InP2[inT, p1T, p2T]

func (*InP2[inT, p1T, p2T]) Call

func (x *InP2[inT, p1T, p2T]) Call(ctx convCtx.Context, p1 p1T, p2 p2T, in inT) (err error)

func (InP2[inT, p1T, p2T]) WithPostCheck

func (x InP2[inT, p1T, p2T]) WithPostCheck(check Check) InP2[inT, p1T, p2T]

func (InP2[inT, p1T, p2T]) WithPreCheck

func (x InP2[inT, p1T, p2T]) WithPreCheck(check Check) InP2[inT, p1T, p2T]

type InP3

type InP3[inT any, p1T, p2T, p3T ~string] struct {
	// contains filtered or unexported fields
}

func NewInP3

func NewInP3[inT any, p1T, p2T, p3T ~string](fn func(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, in inT) error) InP3[inT, p1T, p2T, p3T]

func (*InP3[inT, p1T, p2T, p3T]) Call

func (x *InP3[inT, p1T, p2T, p3T]) Call(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, in inT) (err error)

func (InP3[inT, p1T, p2T, p3T]) WithPostCheck

func (x InP3[inT, p1T, p2T, p3T]) WithPostCheck(check Check) InP3[inT, p1T, p2T, p3T]

func (InP3[inT, p1T, p2T, p3T]) WithPreCheck

func (x InP3[inT, p1T, p2T, p3T]) WithPreCheck(check Check) InP3[inT, p1T, p2T, p3T]

type InP4

type InP4[inT any, p1T, p2T, p3T, p4T ~string] struct {
	// contains filtered or unexported fields
}

func NewInP4

func NewInP4[inT any, p1T, p2T, p3T, p4T ~string](fn func(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, p4 p4T, in inT) error) InP4[inT, p1T, p2T, p3T, p4T]

func (*InP4[inT, p1T, p2T, p3T, p4T]) Call

func (x *InP4[inT, p1T, p2T, p3T, p4T]) Call(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, p4 p4T, in inT) (err error)

func (InP4[inT, p1T, p2T, p3T, p4T]) WithPostCheck

func (x InP4[inT, p1T, p2T, p3T, p4T]) WithPostCheck(check Check) InP4[inT, p1T, p2T, p3T, p4T]

func (InP4[inT, p1T, p2T, p3T, p4T]) WithPreCheck

func (x InP4[inT, p1T, p2T, p3T, p4T]) WithPreCheck(check Check) InP4[inT, p1T, p2T, p3T, p4T]

type InP5

type InP5[inT any, p1T, p2T, p3T, p4T, p5T ~string] struct {
	// contains filtered or unexported fields
}

func NewInP5

func NewInP5[inT any, p1T, p2T, p3T, p4T, p5T ~string](fn func(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, p4 p4T, p5 p5T, in inT) error) InP5[inT, p1T, p2T, p3T, p4T, p5T]

func (*InP5[inT, p1T, p2T, p3T, p4T, p5T]) Call

func (x *InP5[inT, p1T, p2T, p3T, p4T, p5T]) Call(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, p4 p4T, p5 p5T, in inT) (err error)

func (InP5[inT, p1T, p2T, p3T, p4T, p5T]) WithPostCheck

func (x InP5[inT, p1T, p2T, p3T, p4T, p5T]) WithPostCheck(check Check) InP5[inT, p1T, p2T, p3T, p4T, p5T]

func (InP5[inT, p1T, p2T, p3T, p4T, p5T]) WithPreCheck

func (x InP5[inT, p1T, p2T, p3T, p4T, p5T]) WithPreCheck(check Check) InP5[inT, p1T, p2T, p3T, p4T, p5T]

type OpenAPI

type OpenAPI struct {
	// contains filtered or unexported fields
}

func NewOpenAPI

func NewOpenAPI() OpenAPI

func (OpenAPI) WithDescription

func (o OpenAPI) WithDescription(desc string) OpenAPI

func (OpenAPI) WithEnums

func (o OpenAPI) WithEnums(enums ...enum) OpenAPI

func (OpenAPI) WithServers

func (o OpenAPI) WithServers(svs ...string) OpenAPI

func (OpenAPI) WithTypeSubstitutions

func (o OpenAPI) WithTypeSubstitutions(subs ...typeSubstitution) OpenAPI

type Out

type Out[outT any] struct {
	// contains filtered or unexported fields
}

func NewOut

func NewOut[outT any](fn func(ctx convCtx.Context) (outT, error)) Out[outT]

func (*Out[outT]) Call

func (x *Out[outT]) Call(ctx convCtx.Context) (out outT, err error)

func (Out[outT]) WithPostCheck

func (x Out[outT]) WithPostCheck(check Check) Out[outT]

func (Out[outT]) WithPreCheck

func (x Out[outT]) WithPreCheck(check Check) Out[outT]

type OutP1

type OutP1[outT any, p1T ~string] struct {
	// contains filtered or unexported fields
}

func NewOutP1

func NewOutP1[outT any, p1T ~string](fn func(ctx convCtx.Context, p1 p1T) (outT, error)) OutP1[outT, p1T]

func (*OutP1[outT, p1T]) Call

func (x *OutP1[outT, p1T]) Call(ctx convCtx.Context, p1 p1T) (out outT, err error)

func (OutP1[outT, p1T]) WithPostCheck

func (x OutP1[outT, p1T]) WithPostCheck(check Check) OutP1[outT, p1T]

func (OutP1[outT, p1T]) WithPreCheck

func (x OutP1[outT, p1T]) WithPreCheck(check Check) OutP1[outT, p1T]

type OutP2

type OutP2[outT any, p1T, p2T ~string] struct {
	// contains filtered or unexported fields
}

func NewOutP2

func NewOutP2[outT any, p1T, p2T ~string](fn func(ctx convCtx.Context, p1 p1T, p2 p2T) (outT, error)) OutP2[outT, p1T, p2T]

func (*OutP2[outT, p1T, p2T]) Call

func (x *OutP2[outT, p1T, p2T]) Call(ctx convCtx.Context, p1 p1T, p2 p2T) (out outT, err error)

func (OutP2[outT, p1T, p2T]) WithPostCheck

func (x OutP2[outT, p1T, p2T]) WithPostCheck(check Check) OutP2[outT, p1T, p2T]

func (OutP2[outT, p1T, p2T]) WithPreCheck

func (x OutP2[outT, p1T, p2T]) WithPreCheck(check Check) OutP2[outT, p1T, p2T]

type OutP3

type OutP3[outT any, p1T, p2T, p3T ~string] struct {
	// contains filtered or unexported fields
}

func NewOutP3

func NewOutP3[outT any, p1T, p2T, p3T ~string](fn func(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T) (outT, error)) OutP3[outT, p1T, p2T, p3T]

func (*OutP3[outT, p1T, p2T, p3T]) Call

func (x *OutP3[outT, p1T, p2T, p3T]) Call(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T) (out outT, err error)

func (OutP3[outT, p1T, p2T, p3T]) WithPostCheck

func (x OutP3[outT, p1T, p2T, p3T]) WithPostCheck(check Check) OutP3[outT, p1T, p2T, p3T]

func (OutP3[outT, p1T, p2T, p3T]) WithPreCheck

func (x OutP3[outT, p1T, p2T, p3T]) WithPreCheck(check Check) OutP3[outT, p1T, p2T, p3T]

type OutP4

type OutP4[outT any, p1T, p2T, p3T, p4T ~string] struct {
	// contains filtered or unexported fields
}

func NewOutP4

func NewOutP4[outT any, p1T, p2T, p3T, p4T ~string](fn func(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, p4 p4T) (outT, error)) OutP4[outT, p1T, p2T, p3T, p4T]

func (*OutP4[outT, p1T, p2T, p3T, p4T]) Call

func (x *OutP4[outT, p1T, p2T, p3T, p4T]) Call(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, p4 p4T) (out outT, err error)

func (OutP4[outT, p1T, p2T, p3T, p4T]) WithPostCheck

func (x OutP4[outT, p1T, p2T, p3T, p4T]) WithPostCheck(check Check) OutP4[outT, p1T, p2T, p3T, p4T]

func (OutP4[outT, p1T, p2T, p3T, p4T]) WithPreCheck

func (x OutP4[outT, p1T, p2T, p3T, p4T]) WithPreCheck(check Check) OutP4[outT, p1T, p2T, p3T, p4T]

type OutP5

type OutP5[outT any, p1T, p2T, p3T, p4T, p5T ~string] struct {
	// contains filtered or unexported fields
}

func NewOutP5

func NewOutP5[outT any, p1T, p2T, p3T, p4T, p5T ~string](fn func(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, p4 p4T, p5 p5T) (outT, error)) OutP5[outT, p1T, p2T, p3T, p4T, p5T]

func (*OutP5[outT, p1T, p2T, p3T, p4T, p5T]) Call

func (x *OutP5[outT, p1T, p2T, p3T, p4T, p5T]) Call(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, p4 p4T, p5 p5T) (out outT, err error)

func (OutP5[outT, p1T, p2T, p3T, p4T, p5T]) WithPostCheck

func (x OutP5[outT, p1T, p2T, p3T, p4T, p5T]) WithPostCheck(check Check) OutP5[outT, p1T, p2T, p3T, p4T, p5T]

func (OutP5[outT, p1T, p2T, p3T, p4T, p5T]) WithPreCheck

func (x OutP5[outT, p1T, p2T, p3T, p4T, p5T]) WithPreCheck(check Check) OutP5[outT, p1T, p2T, p3T, p4T, p5T]

type Raw

type Raw struct {
	// contains filtered or unexported fields
}

func NewRaw

func NewRaw(fn func(ctx convCtx.Context, w http.ResponseWriter, r *http.Request)) Raw

func (*Raw) Call

func (x *Raw) Call(ctx convCtx.Context, body io.Reader) (err error)

func (Raw) WithPreCheck

func (x Raw) WithPreCheck(check Check) Raw

type RawP1

type RawP1[p1T ~string] struct {
	// contains filtered or unexported fields
}

func NewRawP1

func NewRawP1[p1T ~string](fn func(ctx convCtx.Context, p1 p1T, w http.ResponseWriter, r *http.Request)) RawP1[p1T]

func (*RawP1[p1T]) Call

func (x *RawP1[p1T]) Call(ctx convCtx.Context, p1 p1T, body io.Reader) (err error)

func (RawP1[p1T]) WithPreCheck

func (x RawP1[p1T]) WithPreCheck(check Check) RawP1[p1T]

type RawP2

type RawP2[p1T, p2T ~string] struct {
	// contains filtered or unexported fields
}

func NewRawP2

func NewRawP2[p1T, p2T ~string](fn func(ctx convCtx.Context, p1 p1T, p2 p2T, w http.ResponseWriter, r *http.Request)) RawP2[p1T, p2T]

func (*RawP2[p1T, p2T]) Call

func (x *RawP2[p1T, p2T]) Call(ctx convCtx.Context, p1 p1T, p2 p2T, body io.Reader) (err error)

func (RawP2[p1T, p2T]) WithPreCheck

func (x RawP2[p1T, p2T]) WithPreCheck(check Check) RawP2[p1T, p2T]

type RawP3

type RawP3[p1T, p2T, p3T ~string] struct {
	// contains filtered or unexported fields
}

func NewRawP3

func NewRawP3[p1T, p2T, p3T ~string](fn func(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, w http.ResponseWriter, r *http.Request)) RawP3[p1T, p2T, p3T]

func (*RawP3[p1T, p2T, p3T]) Call

func (x *RawP3[p1T, p2T, p3T]) Call(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, body io.Reader) (err error)

func (RawP3[p1T, p2T, p3T]) WithPreCheck

func (x RawP3[p1T, p2T, p3T]) WithPreCheck(check Check) RawP3[p1T, p2T, p3T]

type RawP4

type RawP4[p1T, p2T, p3T, p4T ~string] struct {
	// contains filtered or unexported fields
}

func NewRawP4

func NewRawP4[p1T, p2T, p3T, p4T ~string](fn func(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, p4 p4T, w http.ResponseWriter, r *http.Request)) RawP4[p1T, p2T, p3T, p4T]

func (*RawP4[p1T, p2T, p3T, p4T]) Call

func (x *RawP4[p1T, p2T, p3T, p4T]) Call(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, p4 p4T, body io.Reader) (err error)

func (RawP4[p1T, p2T, p3T, p4T]) WithPreCheck

func (x RawP4[p1T, p2T, p3T, p4T]) WithPreCheck(check Check) RawP4[p1T, p2T, p3T, p4T]

type RawP5

type RawP5[p1T, p2T, p3T, p4T, p5T ~string] struct {
	// contains filtered or unexported fields
}

func NewRawP5

func NewRawP5[p1T, p2T, p3T, p4T, p5T ~string](fn func(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, p4 p4T, p5 p5T, w http.ResponseWriter, r *http.Request)) RawP5[p1T, p2T, p3T, p4T, p5T]

func (*RawP5[p1T, p2T, p3T, p4T, p5T]) Call

func (x *RawP5[p1T, p2T, p3T, p4T, p5T]) Call(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, p4 p4T, p5 p5T, body io.Reader) (err error)

func (RawP5[p1T, p2T, p3T, p4T, p5T]) WithPreCheck

func (x RawP5[p1T, p2T, p3T, p4T, p5T]) WithPreCheck(check Check) RawP5[p1T, p2T, p3T, p4T, p5T]

type Trigger

type Trigger struct {
	// contains filtered or unexported fields
}

func NewTrigger

func NewTrigger(fn func(ctx convCtx.Context) error) Trigger

func (*Trigger) Call

func (x *Trigger) Call(ctx convCtx.Context) (err error)

func (Trigger) WithPostCheck

func (x Trigger) WithPostCheck(check Check) Trigger

func (Trigger) WithPreCheck

func (x Trigger) WithPreCheck(check Check) Trigger

type TriggerP1

type TriggerP1[p1T ~string] struct {
	// contains filtered or unexported fields
}

func NewTriggerP1

func NewTriggerP1[p1T ~string](fn func(ctx convCtx.Context, p1 p1T) error) TriggerP1[p1T]

func (*TriggerP1[p1T]) Call

func (x *TriggerP1[p1T]) Call(ctx convCtx.Context, p1 p1T) (err error)

func (TriggerP1[p1T]) WithPostCheck

func (x TriggerP1[p1T]) WithPostCheck(check Check) TriggerP1[p1T]

func (TriggerP1[p1T]) WithPreCheck

func (x TriggerP1[p1T]) WithPreCheck(check Check) TriggerP1[p1T]

type TriggerP2

type TriggerP2[p1T, p2T ~string] struct {
	// contains filtered or unexported fields
}

func NewTriggerP2

func NewTriggerP2[p1T, p2T ~string](fn func(ctx convCtx.Context, p1 p1T, p2 p2T) error) TriggerP2[p1T, p2T]

func (*TriggerP2[p1T, p2T]) Call

func (x *TriggerP2[p1T, p2T]) Call(ctx convCtx.Context, p1 p1T, p2 p2T) (err error)

func (TriggerP2[p1T, p2T]) WithPostCheck

func (x TriggerP2[p1T, p2T]) WithPostCheck(check Check) TriggerP2[p1T, p2T]

func (TriggerP2[p1T, p2T]) WithPreCheck

func (x TriggerP2[p1T, p2T]) WithPreCheck(check Check) TriggerP2[p1T, p2T]

type TriggerP3

type TriggerP3[p1T, p2T, p3T ~string] struct {
	// contains filtered or unexported fields
}

func NewTriggerP3

func NewTriggerP3[p1T, p2T, p3T ~string](fn func(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T) error) TriggerP3[p1T, p2T, p3T]

func (*TriggerP3[p1T, p2T, p3T]) Call

func (x *TriggerP3[p1T, p2T, p3T]) Call(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T) (err error)

func (TriggerP3[p1T, p2T, p3T]) WithPostCheck

func (x TriggerP3[p1T, p2T, p3T]) WithPostCheck(check Check) TriggerP3[p1T, p2T, p3T]

func (TriggerP3[p1T, p2T, p3T]) WithPreCheck

func (x TriggerP3[p1T, p2T, p3T]) WithPreCheck(check Check) TriggerP3[p1T, p2T, p3T]

type TriggerP4

type TriggerP4[p1T, p2T, p3T, p4T ~string] struct {
	// contains filtered or unexported fields
}

func NewTriggerP4

func NewTriggerP4[p1T, p2T, p3T, p4T ~string](fn func(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, p4 p4T) error) TriggerP4[p1T, p2T, p3T, p4T]

func (*TriggerP4[p1T, p2T, p3T, p4T]) Call

func (x *TriggerP4[p1T, p2T, p3T, p4T]) Call(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, p4 p4T) (err error)

func (TriggerP4[p1T, p2T, p3T, p4T]) WithPostCheck

func (x TriggerP4[p1T, p2T, p3T, p4T]) WithPostCheck(check Check) TriggerP4[p1T, p2T, p3T, p4T]

func (TriggerP4[p1T, p2T, p3T, p4T]) WithPreCheck

func (x TriggerP4[p1T, p2T, p3T, p4T]) WithPreCheck(check Check) TriggerP4[p1T, p2T, p3T, p4T]

type TriggerP5

type TriggerP5[p1T, p2T, p3T, p4T, p5T ~string] struct {
	// contains filtered or unexported fields
}

func NewTriggerP5

func NewTriggerP5[p1T, p2T, p3T, p4T, p5T ~string](fn func(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, p4 p4T, p5 p5T) error) TriggerP5[p1T, p2T, p3T, p4T, p5T]

func (*TriggerP5[p1T, p2T, p3T, p4T, p5T]) Call

func (x *TriggerP5[p1T, p2T, p3T, p4T, p5T]) Call(ctx convCtx.Context, p1 p1T, p2 p2T, p3 p3T, p4 p4T, p5 p5T) (err error)

func (TriggerP5[p1T, p2T, p3T, p4T, p5T]) WithPostCheck

func (x TriggerP5[p1T, p2T, p3T, p4T, p5T]) WithPostCheck(check Check) TriggerP5[p1T, p2T, p3T, p4T, p5T]

func (TriggerP5[p1T, p2T, p3T, p4T, p5T]) WithPreCheck

func (x TriggerP5[p1T, p2T, p3T, p4T, p5T]) WithPreCheck(check Check) TriggerP5[p1T, p2T, p3T, p4T, p5T]

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL