module

package
v0.10.8 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package module provides a unified module registration system that automatically registers models, services, and HTTP routes for CRUD operations.

A module consists of three components:

  • Model: Database entity implementing types.Model
  • Service: Business logic implementing types.Service
  • Module: Configuration implementing types.Module

Usage:

  1. Define model (embedding model.Base), request/response types, and service (embedding service.Base)
  2. Implement module with types.Module interface
  3. Call module.Use() with desired CRUD phases

Example:

module.Use[*User, *UserReq, *UserRsp, *UserService](
    &UserModule{},
    consts.PHASE_CREATE,
    consts.PHASE_LIST,
    consts.PHASE_GET,
)

Route paths are normalized (leading slashes and "api/" prefix are removed). Authentication is controlled by Module.Pub() method.

See module/helloworld for complete examples.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init added in v0.10.1

func Init() error

Init notifies the module system that the framework is initialized. After calling Init, modules can start registering models, services, and routes.

func NewWrapper added in v0.10.5

func NewWrapper[M types.Model, REQ types.Request, RSP types.Response](route string, param string, pub bool) types.Module[M, REQ, RSP]

func Use

func Use[M types.Model, REQ types.Request, RSP types.Response, S types.Service[M, REQ, RSP]](mod types.Module[M, REQ, RSP], phases ...consts.Phase)

Use registers a module with the framework, automatically setting up model, service, and HTTP route registration for the specified CRUD phases.

Type Parameters:

  • M: Model type implementing types.Model
  • REQ: Request type for API operations
  • RSP: Response type for API operations
  • S: Service type implementing types.Service[M, REQ, RSP]

Parameters:

  • mod: Module instance implementing types.Module[M, REQ, RSP]
  • phases: CRUD phases to register. Available phases: PHASE_CREATE, PHASE_DELETE, PHASE_UPDATE, PHASE_PATCH, PHASE_LIST, PHASE_GET, PHASE_CREATE_MANY, PHASE_DELETE_MANY, PHASE_UPDATE_MANY, PHASE_PATCH_MANY

Routes are registered based on mod.Route() and mod.Param(). Authentication is determined by mod.Pub().

Must be called during application initialization, typically in a Register() function.

Types

type Wrapper added in v0.10.5

type Wrapper[M types.Model, REQ types.Request, RSP types.Response] struct {
	// contains filtered or unexported fields
}

func (*Wrapper[M, REQ, RSP]) Param added in v0.10.5

func (w *Wrapper[M, REQ, RSP]) Param() string

func (*Wrapper[M, REQ, RSP]) Pub added in v0.10.5

func (w *Wrapper[M, REQ, RSP]) Pub() bool

func (*Wrapper[M, REQ, RSP]) Route added in v0.10.5

func (w *Wrapper[M, REQ, RSP]) Route() string

func (*Wrapper[M, REQ, RSP]) Service added in v0.10.5

func (w *Wrapper[M, REQ, RSP]) Service() types.Service[M, REQ, RSP]

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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