generatedcmd/api/main.go
// Code generated by builder; DO NOT EDIT.
// Command api runs app api: the doors builder generates in
// github.com/acme/shop/gen/builder/api.
package main
import (
app "github.com/acme/shop/gen/builder/api"
"github.com/xgodev/boost"
fxfact "github.com/xgodev/boost/factory/contrib/go.uber.org/fx/v1"
)
func main() {
boost.Start()
fxfact.NewApp(app.Modules()...).Run()
}
generatedgen/builder/api/modules.go
// Code generated by builder; DO NOT EDIT.
package api
import (
"go.uber.org/fx"
mw_local_54c3d838 "github.com/acme/shop/gen/builder/middleware/internal_/pkg/domain/service/stock/reserver/local"
multiserverfx "github.com/xgodev/boost/fx/modules/extra/multiserver"
)
// Modules returns the doors of app api and the multiserver that runs its servers:
//
// fxfact.NewApp(api.Modules()...).Run()
func Modules() []fx.Option {
return []fx.Option{
RestModule(),
mw_local_54c3d838.DecorateNew(),
multiserverfx.Module(),
}
}
generatedgen/builder/api/rest_module.go
// Code generated by builder; DO NOT EDIT.
package api
import (
"sync"
"go.uber.org/fx"
gen_rest_54b9e997 "github.com/acme/shop/gen/internal/app/api/rest"
gen_reserver_5a8b66f7 "github.com/acme/shop/gen/internal/app/api/rest/handler/stock/reserver"
src_reserver_5a8b66f7 "github.com/acme/shop/internal/app/api/rest/handler/stock/reserver"
boostecho "github.com/xgodev/boost/factory/contrib/labstack/echo/v4"
echofx "github.com/xgodev/boost/fx/modules/factory/contrib/labstack/echo/v4"
)
var restOnce sync.Once
// RestModule serves the REST routes of server rest on echo.
// It returns an empty option after the first call.
func RestModule() fx.Option {
options := fx.Options()
restOnce.Do(func() {
options = fx.Module("api.rest",
echofx.Module(),
gen_reserver_5a8b66f7.NewModule(),
gen_rest_54b9e997.PluginsModule(),
fx.Invoke(func(srv *boostecho.Server, h0 *src_reserver_5a8b66f7.Handler) {
srv.Add("POST", "/stock/:sku/reserve", h0.Handle)
}),
)
})
return options
}
generatedgen/builder/middleware/internal_/pkg/domain/service/stock/reserver/local/new_middleware.go
// Code generated by builder; DO NOT EDIT.
package local
import (
"go.uber.org/fx"
context "context"
src_reserver_399f2048 "github.com/acme/shop/internal/pkg/domain/service/stock/reserver"
middleware "github.com/xgodev/boost/extra/middleware"
fmiddleware "github.com/xgodev/boost/factory/local/extra/middleware"
prometheusmw "github.com/xgodev/boost/factory/local/extra/middleware/plugins/contrib/prometheus/client_golang/v1"
logmw "github.com/xgodev/boost/factory/local/extra/middleware/plugins/local/wrapper/log"
contextfx "github.com/xgodev/boost/fx/modules/core/context"
)
// DecorateNew decorates the reserver.Service that local.New provides:
// every consumer in the app receives a newDecorator, which runs the middlewares
// log, prometheus around each method; config can disable each one.
func DecorateNew() fx.Option {
return fx.Options(
contextfx.Module(),
fx.Decorate(decorateNew),
)
}
// decorateNew builds the wrappers of every method of reserver.Service once.
func decorateNew(ctx context.Context, next src_reserver_399f2048.Service) (src_reserver_399f2048.Service, error) {
d := &newDecorator{next: next}
var err error
d.reserveWrapper, err = fmiddleware.NewErrorWrapperWithOptions(ctx, &fmiddleware.Options{Name: "reserver.service.reserve"},
logmw.NewError,
prometheusmw.NewError,
)
if err != nil {
return nil, err
}
return d, nil
}
// newDecorator implements reserver.Service: each method runs next's in its wrapper.
type newDecorator struct {
next src_reserver_399f2048.Service
reserveWrapper *middleware.ErrorWrapper
}
// Reserve runs next.Reserve in the middlewares of reserver.service.reserve.
func (d *newDecorator) Reserve(ctx context.Context, a1 string) error {
return d.reserveWrapper.Exec(ctx, "reserver.service.reserve",
func(ctx context.Context) error {
return d.next.Reserve(ctx, a1)
},
func(_ context.Context, err error) error {
return err
},
)
}
generatedgen/implementation/internal_/pkg/domain/repository/stock/repository_implementation.go
// Code generated by inject; DO NOT EDIT.
package stock
import (
"sync"
"github.com/xgodev/boost/model/errors"
"github.com/xgodev/boost/wrapper/config"
"go.uber.org/fx"
gen_memory_6a1a5ba1 "github.com/acme/shop/gen/internal/pkg/datastore/stock/memory"
gen_mongodb_1bacb721 "github.com/acme/shop/gen/internal/pkg/datastore/stock/mongodb"
)
// repositoryImplementationKey chooses the implementation of github.com/acme/shop/internal/pkg/domain/repository/stock.Repository.
const repositoryImplementationKey = "internal.pkg.domain.repository.stock.implementation"
func init() {
config.Add(repositoryImplementationKey, "memory", "implementation of github.com/acme/shop/internal/pkg/domain/repository/stock.Repository: memory, mongodb")
}
// RepositoryImplementation returns the name of the implementation of
// github.com/acme/shop/internal/pkg/domain/repository/stock.Repository that RepositoryImplementationModule wires.
func RepositoryImplementation() string {
return config.String(repositoryImplementationKey)
}
var repositoryImplementationOnce sync.Once
// RepositoryImplementationModule wires the implementation of github.com/acme/shop/internal/pkg/domain/repository/stock.Repository
// named by internal.pkg.domain.repository.stock.implementation (memory, mongodb; default memory) and only that one.
// An unknown name fails the boot. It returns an empty option after the first
// call, so every consumer can include it.
func RepositoryImplementationModule() fx.Option {
options := fx.Options()
repositoryImplementationOnce.Do(func() {
switch name := RepositoryImplementation(); name {
case "memory":
options = gen_memory_6a1a5ba1.NewModule()
case "mongodb":
options = gen_mongodb_1bacb721.NewModule()
default:
options = fx.Error(errors.NotValidf("%s: unknown implementation %q; valid: %s", repositoryImplementationKey, name, "memory, mongodb"))
}
})
return options
}
generatedgen/internal/app/api/rest/handler/stock/reserver/new_module.go
// Code generated by inject; DO NOT EDIT.
package reserver
import (
"sync"
"go.uber.org/fx"
gen_local_9afcd4bd "github.com/acme/shop/gen/internal/pkg/domain/service/stock/reserver/local"
src_reserver_5a8b66f7 "github.com/acme/shop/internal/app/api/rest/handler/stock/reserver"
)
var NewOnce sync.Once
// NewModule registers github.com/acme/shop/internal/app/api/rest/handler/stock/reserver.New and the modules it depends on.
// It returns an empty option after the first call, so a constructor shared by
// several modules is registered only once.
func NewModule() fx.Option {
options := fx.Options()
NewOnce.Do(func() {
options = fx.Module("github.com/acme/shop/internal/app/api/rest/handler/stock/reserver.New",
gen_local_9afcd4bd.NewModule(),
fx.Provide(src_reserver_5a8b66f7.New),
)
})
return options
}
generatedgen/internal/app/api/rest/plugins_module.go
// Code generated by inject; DO NOT EDIT.
package rest
import (
"sync"
"go.uber.org/fx"
src_rest_54b9e997 "github.com/acme/shop/internal/app/api/rest"
)
var PluginsOnce sync.Once
// PluginsModule registers github.com/acme/shop/internal/app/api/rest.Plugins and the modules it depends on.
// It returns an empty option after the first call, so a constructor shared by
// several modules is registered only once.
func PluginsModule() fx.Option {
options := fx.Options()
PluginsOnce.Do(func() {
options = fx.Module("github.com/acme/shop/internal/app/api/rest.Plugins",
fx.Provide(src_rest_54b9e997.Plugins),
)
})
return options
}
generatedgen/internal/pkg/domain/service/stock/reserver/local/new_module.go
// Code generated by inject; DO NOT EDIT.
package local
import (
"sync"
"go.uber.org/fx"
impl_stock_f8e11fb6 "github.com/acme/shop/gen/implementation/internal_/pkg/domain/repository/stock"
src_local_9afcd4bd "github.com/acme/shop/internal/pkg/domain/service/stock/reserver/local"
)
var NewOnce sync.Once
// NewModule registers github.com/acme/shop/internal/pkg/domain/service/stock/reserver/local.New and the modules it depends on.
// It returns an empty option after the first call, so a constructor shared by
// several modules is registered only once.
func NewModule() fx.Option {
options := fx.Options()
NewOnce.Do(func() {
options = fx.Module("github.com/acme/shop/internal/pkg/domain/service/stock/reserver/local.New",
impl_stock_f8e11fb6.RepositoryImplementationModule(),
fx.Provide(src_local_9afcd4bd.New),
)
})
return options
}
generatedgen/internal/pkg/datastore/stock/memory/new_module.go
// Code generated by inject; DO NOT EDIT.
package memory
import (
"sync"
"go.uber.org/fx"
src_memory_6a1a5ba1 "github.com/acme/shop/internal/pkg/datastore/stock/memory"
)
var NewOnce sync.Once
// NewModule registers github.com/acme/shop/internal/pkg/datastore/stock/memory.New and the modules it depends on.
// It returns an empty option after the first call, so a constructor shared by
// several modules is registered only once.
func NewModule() fx.Option {
options := fx.Options()
NewOnce.Do(func() {
options = fx.Module("github.com/acme/shop/internal/pkg/datastore/stock/memory.New",
fx.Provide(src_memory_6a1a5ba1.New),
)
})
return options
}
generatedgen/internal/pkg/datastore/stock/mongodb/new_module.go
// Code generated by inject; DO NOT EDIT.
package mongodb
import (
"sync"
"go.uber.org/fx"
src_mongodb_1bacb721 "github.com/acme/shop/internal/pkg/datastore/stock/mongodb"
)
var NewOnce sync.Once
// NewModule registers github.com/acme/shop/internal/pkg/datastore/stock/mongodb.New and the modules it depends on.
// It returns an empty option after the first call, so a constructor shared by
// several modules is registered only once.
func NewModule() fx.Option {
options := fx.Options()
NewOnce.Do(func() {
options = fx.Module("github.com/acme/shop/internal/pkg/datastore/stock/mongodb.New",
OptionsModule(),
fx.Provide(src_mongodb_1bacb721.New),
)
})
return options
}
generatedgen/internal/pkg/datastore/stock/mongodb/options_module.go
// Code generated by inject; DO NOT EDIT.
package mongodb
import (
"sync"
"github.com/xgodev/boost/wrapper/config"
"go.uber.org/fx"
src_mongodb_1bacb721 "github.com/acme/shop/internal/pkg/datastore/stock/mongodb"
)
// optionsRoot is the config key holding github.com/acme/shop/internal/pkg/datastore/stock/mongodb.Options.
const optionsRoot = "internal.pkg.datastore.stock.mongodb"
func init() {
// env INTERNAL_PKG_DATASTORE_STOCK_MONGODB_COLLECTION
config.Add(optionsRoot+".collection", "stock", "collection of the units in stock")
}
var optionsOnce sync.Once
// OptionsModule provides the Options of github.com/acme/shop/internal/pkg/datastore/stock/mongodb,
// filled from the config keys under internal.pkg.datastore.stock.mongodb.
// It returns an empty option after the first call, so every consumer can
// include it.
func OptionsModule() fx.Option {
options := fx.Options()
optionsOnce.Do(func() {
options = fx.Module("github.com/acme/shop/internal/pkg/datastore/stock/mongodb.Options",
fx.Provide(func() (*src_mongodb_1bacb721.Options, error) {
return config.NewOptionsWithPath[src_mongodb_1bacb721.Options](optionsRoot)
}),
)
})
return options
}
generatedgen/module.go
// Code generated by inject; DO NOT EDIT.
package gen
import (
"go.uber.org/fx"
impl_stock_f8e11fb6 "github.com/acme/shop/gen/implementation/internal_/pkg/domain/repository/stock"
gen_rest_54b9e997 "github.com/acme/shop/gen/internal/app/api/rest"
gen_reserver_5a8b66f7 "github.com/acme/shop/gen/internal/app/api/rest/handler/stock/reserver"
gen_mongodb_1bacb721 "github.com/acme/shop/gen/internal/pkg/datastore/stock/mongodb"
gen_local_9afcd4bd "github.com/acme/shop/gen/internal/pkg/domain/service/stock/reserver/local"
)
// Module registers every module generated by inject.
func Module() fx.Option {
return fx.Options(
gen_rest_54b9e997.PluginsModule(),
gen_reserver_5a8b66f7.NewModule(),
impl_stock_f8e11fb6.RepositoryImplementationModule(),
gen_mongodb_1bacb721.OptionsModule(),
gen_local_9afcd4bd.NewModule(),
)
}