gontainer

command module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: MIT Imports: 8 Imported by: 0

README

TEST REPOSITORY; DO NOT USE IT

Build Status Coverage Status

Gontainer

A Depenendency Injection container for GO inspired by Symfony.

Docs

  1. Documentation
    1. Version
    2. Meta
    3. Parameters
    4. Services
    5. Decorators
  2. Use cases
    1. Composition root
    2. Contextual scope
  3. Examples
  4. Interface

Installation

homebrew

brew install gomponents/homebrew-tap/gontainer

go install

go install github.com/gomponents/gontainer@latest

Manual compilation

git clone git@github.com:gontainer/gontainer.git
cd gontainer
GONTAINER_BINARY=/usr/local/bin/gontainer make build

TL;DR

Describe dependencies in YAML

File gontainer/gontainer.yaml:

meta:
  pkg: "gontainer"
  constructor: "New"

parameters:
  appPort: '%envInt("APP_PORT", 9090)%' # get the port from the ENV variable if it exists, otherwise, use the default one

services:
  endpointHelloWorld: # sample HTTP endpoint
    constructor: "http.NewHelloWorld"

  serveMux:
    constructor: '"net/http".NewServeMux'
    calls:
      - [ "Handle", [ "/hello-world", "@endpointHelloWorld" ] ]

  server:
    getter: "GetServer"
    must_getter: true # define method MustGetServer
    value: '&"net/http".Server{}'
    type: '*"net/http".Server'
    fields:
      Addr: ":%appPort%"
      Handler: "@serveMux"

Compile it

gontainer build -i gontainer/gontainer.yaml -o gontainer/container.go

# it can read multiple configuration files, e.g.
# gontainer build -i gontainer/gontainer.yaml -i gontainer/dev/*.yaml -o gontainer/container.go

Voilà!

File main.go:

package main

import (
	"github.com/user/repo/gontainer"
)

func main() {
	c := gontainer.New()
	s := c.MustGetServer()

	err := s.ListenAndServe()
	if err != nil {
		panic(err)
	}
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
example module
internal
cmd
pkg/errors
Package errors provides a toolset to join and split errors.
Package errors provides a toolset to join and split errors.
pkg/token
Package token provides a tool to convert a string to Tokens that represent GO code.
Package token provides a tool to convert a string to Tokens that represent GO code.

Jump to

Keyboard shortcuts

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