def slacksend(*, config: str) -> GoError: """send message to slack channel""" from egoist.generate.clikit import clikit from egoist.go import di with runtime.generate(clikit) as m: context = m.import_("context") ctx = m.let("ctx", context.Background()) b = di.Builder() b.add_provider(config_pkg.LoadConfig) b.add_provider(api_pkg.NewClient) b.add_provider(api_pkg.NewAPI) injector = b.build(variables={"config_file": config}) api = injector.inject(m) args = runtime.get_cli_rest_args() with m.for_(f"_, text := range {args}"): with m.if_( "err := {}; err != nil", api.Send(ctx, m.symbol("text"), _to_str("random")), ): m.return_("err") m.return_("nil")
def wire_example(*, grumby: bool = False) -> None: """ google/wire event examples """ from egoist.generators.clikit import runtime, clikit from egoist.go import di internal = app.maybe_dotted("internal") # ./internal.py with runtime.generate(clikit) as m: b = di.Builder() # Greeter depends on Message # and, Event depends on Greeter b.add_provider(internal.NewMessage) b.add_provider(internal.NewGreeter) b.add_provider(internal.NewEvent) injector = b.build(variables=locals()) event = injector.inject(m) m.stmt(event.Start())
def NewZ0(y: Y0) -> Z0: pass def NewY1(x: X) -> Y1: pass def NewZ1(y: Y1) -> Z1: pass m = Module() b = di.Builder() b.add_provider(NewX) b.add_provider(NewY0) b.add_provider(NewZ0) b.add_provider(NewY1) b.add_provider(NewZ1) injector = b.build() z0 = injector.inject(m, provider=NewZ0) z1 = injector.inject(m, provider=NewZ1) z1 = injector.inject(m, provider=NewZ1) m.stmt("({}, {})", z0, z1)