Sign in

    moonbitstack/moonzero/rest does not have a README file

    Group

    pub struct Group {
    app :
    App

    prefix : String
    }

    A route group (← go-zero's RouteGroup): registers a set of routes on an underlying moonapi.App under a shared path prefix, so related endpoints (e.g. everything under /api/v1) are declared without repeating the prefix.

    Group::delete

    fn Group::delete(self : Group, path : String, handler : (
    Context
    ) ->
    Response
    raise, summary? : String) -> Unit

    Register a DELETE route under the group's prefix.

    Group::get

    fn Group::get(self : Group, path : String, handler : (
    Context
    ) ->
    Response
    raise, summary? : String) -> Unit

    Register a GET route under the group's prefix.

    Group::new

    fn Group::new(app :
    App
    , prefix : String) -> Group

    Open a group that prefixes every route it registers with prefix on app.

    Group::patch

    fn Group::patch(self : Group, path : String, handler : (
    Context
    ) ->
    Response
    raise, summary? : String) -> Unit

    Register a PATCH route under the group's prefix.

    Group::post

    fn Group::post(self : Group, path : String, handler : (
    Context
    ) ->
    Response
    raise, summary? : String) -> Unit

    Register a POST route under the group's prefix.

    Group::prefix

    fn Group::prefix(self : Group) -> String

    The prefix this group joins onto each registered route.

    Group::put

    fn Group::put(self : Group, path : String, handler : (
    Context
    ) ->
    Response
    raise, summary? : String) -> Unit

    Register a PUT route under the group's prefix.

    Group::route

    fn Group::route(self : Group, verb :
    Method
    , path : String, handler : (
    Context
    ) ->
    Response
    raise, summary? : String) -> Unit

    Register a route for an explicit method under the group's prefix.

    Layer

    pub(all) struct Layer {
    name : String
    middleware : (async (
    Scope
    , async () ->
    Event
    , async (
    Event
    ) -> Unit) -> Unit) -> (async (
    Scope
    , async () ->
    Event
    , async (
    Event
    ) -> Unit) -> Unit)
    }

    One layer of the assembled chain: go-zero's name for the handler, and the middleware that stands in for it.

    RestEngine

    The engine that turns a RestConf into a runnable service (← go-zero's rest.engine). It owns the state the built-in layers need — the connection permits, the breaker window, the metric set, the shedder — so every request shares one of each, and it installs exactly the layers Middlewares asks for.

    RestEngine::build

    Assemble app under the configured chain. go-zero's chain.New names the outermost handler first while Server::use_ makes the most recent layer outermost, so the list goes on back to front.

    RestEngine::conf

    The config the engine was built from.

    RestEngine::layers

    fn RestEngine::layers(self : RestEngine) -> Array[Layer]

    The chain the flags ask for, outermost first, in go-zero's buildChainWithNativeMiddlewares order.

    A layer whose configured value disables it is left out even when its flag is on, as in go-zero: no shedder without a CpuThreshold, no timeout without a budget, no body cap without a MaxBytes.

    Two of go-zero's eleven flags install nothing here. Metrics is go-zero's internal stat.Metrics sink, which moonzero has no counterpart for — its one metric set is the Prometheus one the Prometheus flag installs. Gunzip needs a DEFLATE decoder, which neither moonzero nor any dependency carries. Both flags still load, so a go-zero config round-trips through RestConf.

    RestEngine::metrics

    The metric set the prometheus layer records into — the same one mount_metrics publishes.

    RestEngine::names

    fn RestEngine::names(self : RestEngine) -> Array[String]

    The names of the layers layers would install, outermost first.

    RestEngine::new

    Build the engine for conf, pointing the logger at the configured level (← ServiceConf.SetUp's logx.SetUp).

    usage is the CPU meter the shedder reads, per mille. Raises ConfigError for a strict signature config with no keys, which is go-zero's ErrSignatureConfig.

    Server

    A moonzero service: its config plus the assembled application (a moonapi App with any middleware already wrapped around it).

    Server::describe

    fn Server::describe(self : Server) -> String

    A human-readable description of what this service binds to.

    Server::new

    Assemble a service from config and a moonapi application.

    Server::to_asgi

    The assembled AsgiApp, ready for a server (mooncat) to run.

    Server::use_

    Wrap the current application in another middleware layer (outermost last).