gontainer

command module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: MIT Imports: 6 Imported by: 0

README

TEST REPOSITORY; DO NOT USE IT

Build Status Coverage Status

Gontainer

Depenendency Injection container for GO inspired by Symfony.

Docs

  1. Use cases
    1. Composition Root
    2. Tags
    3. Contextual scope
  2. Documentation
    1. Meta
    2. Providers
    3. Parameters
    4. Services
    5. Decorators
  3. Examples
  4. Interface
  5. Installation

TL;DR

Describe dependencies in YAML

File gontainer/gontainer.yml:

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.yml -o gontainer/container.go

# it can read multiple configuration files, e.g.
# gontainer build -i gontainer/gontainer.yml -i gontainer/dev/*.yml -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/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