gimbap

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2024 License: MIT Imports: 6 Imported by: 10

README

GIMBAP Logo

GIMBAP - Go Injection Management for Better Application Programming

Go

Go Injection Management for Better Application Programming

Why GIMBAP?

Gimbap is a Korean-style sea-weed roll with various ingredients insid. It is a simple and easy to make dish that is popular in Korea. The name GIMBAP is chosen as the acronym because it's one of my favourite dishes!.

Gimbap is a food where vegetables, fish and meat are rolled in a seaweed sheet with cooked rice. The seaweed sheet connects all the ingredients together and makes it easy to eat.

Like this GIMBAP aims to provide a simple solution to build web application in Go, connecting all components together in a simple and easy way.

Disclaimer

GIMBAP is still in its early stage of development. It is not recommended to use this in production environment yet, and I am still working on to handle some of the key features that are missing or need improvement.

Key Features

GIMBAP currently supports the following key features:

  • Automatic Dependency Injection management
  • API Endpoint management by code
  • Flexible Server engine switching
  • Containerized instance managing
Automatic Dependency Injection Management

This is an example of adding a new dependency struct B to the constructor of A

AS-IS

package example

import "github.com/jhseong7/gimbap"

type A struct {}

func CreateA() *A {
  return &A{}
}

var ProviderA = gimbap.DefineProvider(
  gimbap.ProviderOption{Name: "A", Instantiator: CreateA},
)

var Module = gimbap.DefineModule(
  gimbap.ModuleOption{
    Name: "ExampleModule",
    Providers: []*gimbap.Provider{ProviderA}
  }
)

TO-BE

package example

import "github.com/jhseong7/gimbap"

type A struct {B *B}


func CreateA(B *B) *A {
  return &A{B: B}
}

var ProviderA = gimbap.DefineProvider(
  gimbap.ProviderOption{Name: "A", Instantiator: CreateA},
)

// ==== Add defs for B START =====
type B struct {}

func CreateB() *B {
  return &B{}
}

var ProviderB = gimbap.DefineProvider(
  gimbap.ProviderOption{Name: "B", Instantiator: CreateB},
)
// ==== Add defs for B END =====

var Module = gimbap.DefineModule(
  gimbap.ModuleOption{
    Name: "ExampleModule",
    Providers: []*gimbap.Provider{ProviderA, ProviderB} // Add the provider for B here
  }
)

Don't worry about changing the intialization process by hand for the new struct. GIMBAP will handle it for you.

API Endpoint management by code

WIP

Flexible Server engine switching

GIMBAP has an modularized server core that can be switched easily by preference

import "github.com/jhseong7/gimbap"
import "github.com/jhseong7/gimbap/internal/engine/fiber_engine"
import "github.com/jhseong7/gimbap/internal/engine/echo_engine"

func main() {
  // Using GIN as http server
  a := gimbap.CreateApp(gimbap.AppOption{
    AppName:   "SampleApp",
		AppModule: SampleModule,
  })

  // Using fiber
  a = gimbap.CreateApp(gimbap.AppOption{
    AppName:   "SampleApp",
		AppModule: SampleModule,
    ServerEngine: fiber_engine.NewFiberHttpEngine()
  })

  // Using Echo
  a = gimbap.CreateApp(gimbap.AppOption{
    AppName:   "SampleApp",
		AppModule: SampleModule,
    ServerEngine: echo_engine.NewEchoHttpEngine()
  })
}

You can choose whatever web server you prefer as the core server easily.

Documentation

Check for the documentation here.

Documentation

Sample Repo Config Provider

Goals

This framework provides the following features in the future

  • Interceptor, Guard support
  • Template engine support
  • More to be added...

Third-Party Libraries

This project uses the following third-party libraries:

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Overview

Alias public types and functions for the package gimbap.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetProvider

func GetProvider[T interface{}](a GimbapApp, prov T) (ret T)

Function to get a provider from the app.

Provide the app and the provider type to get the provider instance. If the provider is not found, it will panic.

Types

type AppOption

type AppOption = app.AppOption

App related

type Controller added in v0.0.4

type Controller = controller.Controller

type aliases for public apis

func DefineController

func DefineController(option ControllerOption) *Controller

Define a controller.

Defines a special provider that is used to handle RESTful requests. The controller will be registered to the app and can be injected to the other controllers.

type ControllerOption

type ControllerOption = controller.ControllerOption

type aliases for public apis

type GimbapApp

type GimbapApp = app.GimbapApp

type aliases for public apis

func CreateApp

func CreateApp(option AppOption) *GimbapApp

Create a Gimbap instance.

This is the entry point to create a Gimbap application.

type IController

type IController = controller.IController

Controller related

type IMicroService

type IMicroService = microservice.IMicroService

Microservice related

type IServerEngine

type IServerEngine = engine.IServerEngine

Engine related

type MicroServiceProvider added in v0.0.5

type MicroServiceProvider = microservice.MicroServiceProvider

type aliases for public apis

func DefineMicroService added in v0.0.5

func DefineMicroService(option MicroServiceProviderOption) *MicroServiceProvider

Define a microservice

Define a special provider for microservices

type MicroServiceProviderOption added in v0.0.5

type MicroServiceProviderOption = microservice.MicroServiceProviderOption

type aliases for public apis

type Module

type Module = module.Module

type aliases for public apis

func DefineModule

func DefineModule(option ModuleOption) *Module

Define a module.

This defines a module with the given option. The module is used to determine the dependencies of the providers.

type ModuleOption

type ModuleOption = module.ModuleOption

Module related

type Provider added in v0.0.4

type Provider = provider.Provider

Provider related

func DefineProvider

func DefineProvider(option ProviderOption) *Provider

Define a provider.

This defines a provider with the given option. The provider will be registered to the app and can be injected to the controllers.

type ProviderOption

type ProviderOption = provider.ProviderOption

type aliases for public apis

type RouteSpec

type RouteSpec = controller.RouteSpec

type aliases for public apis

type RuntimeOptions

type RuntimeOptions = app.RuntimeOptions

type aliases for public apis

type ServerEngineOption

type ServerEngineOption = engine.ServerEngineOption

type aliases for public apis

type TLSOption added in v0.0.6

type TLSOption = engine.TLSOption

type aliases for public apis

Directories

Path Synopsis
Experimental Gimbap Dependency Manager
Experimental Gimbap Dependency Manager
File: http-engine.go
File: http-engine.go
gin
File: module.go
File: module.go
file: provider.go
file: provider.go

Jump to

Keyboard shortcuts

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