handler

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 12 Imported by: 8

Documentation

Index

Constants

View Source
const SuccessMessage = "OK"

SuccessMessage is the default success message for successful responses.

Variables

View Source
var (
	ErrProjectDoesNotExist      = errors.New("the project does not exist")
	ErrOrganizationDoesNotExist = errors.New("the organization does not exist")
	ErrStackDoesNotExist        = errors.New("the stack does not exist")
)

Functions

func FailureResponse

func FailureResponse(ctx context.Context, err error) render.Renderer

FailureResponse creates a response renderer for a failed request.

func GenerateResponse

func GenerateResponse(ctx context.Context, data any, err error) render.Renderer

Response creates a standard API response renderer.

func GetOrganizationByID

func GetOrganizationByID(ctx context.Context, organizationRepo repository.OrganizationRepository, id uint) (*entity.Organization, error)

func GetProjectByID

func GetProjectByID(ctx context.Context, projectRepo repository.ProjectRepository, id uint) (*entity.Project, error)

func GetSourceByID

func GetSourceByID(ctx context.Context, sourceRepo repository.SourceRepository, id uint) (*entity.Source, error)

func GetStackByID

func GetStackByID(ctx context.Context, stackRepo repository.StackRepository, id uint) (*entity.Stack, error)

func HandleResult

func HandleResult(w http.ResponseWriter, r *http.Request, ctx context.Context, err error, data any)

func SuccessResponse

func SuccessResponse(ctx context.Context, data any) render.Renderer

SuccessResponse creates a response renderer for a successful request.

Types

type Duration

type Duration time.Duration

Duration is a custom type that represents a duration of time.

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() (b []byte, err error)

MarshalJSON customizes JSON representation of the Duration type.

type Payload

type Payload interface {
	Decode(*http.Request) error // Decode returns the payload object with the decoded
}

Payload is an interface for incoming requests payloads Each handler should implement this interface to parse payloads

type Response

type Response struct {
	Success   bool       `json:"success" yaml:"success"`                         // Indicates success status.
	Message   string     `json:"message" yaml:"message"`                         // Descriptive message.
	Data      any        `json:"data,omitempty" yaml:"data,omitempty"`           // Data payload.
	TraceID   string     `json:"traceID,omitempty" yaml:"traceID,omitempty"`     // Trace identifier.
	StartTime *time.Time `json:"startTime,omitempty" yaml:"startTime,omitempty"` // Request start time.
	EndTime   *time.Time `json:"endTime,omitempty" yaml:"endTime,omitempty"`     // Request end time.
	CostTime  Duration   `json:"costTime,omitempty" yaml:"costTime,omitempty"`   // Time taken for the request.
}

response defines the structure for API response payloads.

func (*Response) Render

func (rep *Response) Render(w http.ResponseWriter, r *http.Request) error

Render is a no-op method that satisfies the render.Renderer interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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