gimbap

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2025 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

AppOption

This is the option provided when creating a Gimbap App

Original type:

type AppOption struct {
	AppName      string
	AppModule    *module.Module
	ServerEngine engine.IServerEngine
	DepManager   dependency.IDependencyManager
}

type Controller added in v0.0.4

type Controller = controller.Controller

Original type:

type Controller struct {
	name     string
	instance IController
	module   *Module
}

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

Original type:

type ControllerOption struct {
	Name     string
	Instance IController
	Module   *Module
}

type GimbapApp

type GimbapApp = app.GimbapApp

Original type:

type GimbapApp struct {
	appName      string
	appModule    *module.Module
	serverEngine engine.IServerEngine
	depManager   dependency.IDependencyManager
}

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 Original type:

type IController interface {
	RegisterRoutes(router *gin.Engine)
}

type IMicroService

type IMicroService = microservice.IMicroService

Microservice related Original type:

type IMicroService interface {
	Start() error
	Stop() error
}

type IServerEngine

type IServerEngine = engine.IServerEngine

Engine related Original type:

type IServerEngine interface {
	Start(port int, tls *TLSOption) error
	Stop() error
}

type MicroServiceProvider added in v0.0.5

type MicroServiceProvider = microservice.MicroServiceProvider

Original type:

type MicroServiceProvider struct {
	name     string
	instance IMicroService
	module   *Module
}

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

Original type:

type MicroServiceProviderOption struct {
	Name     string
	Instance IMicroService
	Module   *Module
}

type Module

type Module = module.Module

Original type:

type Module struct {
	name      string
	providers []*Provider
	dependsOn []*Module
}

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 Original type:

type ModuleOption struct {
	Name       string
	Providers  []*Provider
	DependsOn  []*Module
}

type Provider added in v0.0.4

type Provider = provider.Provider

Provider related Original type:

type Provider struct {
	name     string
	instance interface{}
	module   *Module
}

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

Original type:

type ProviderOption struct {
	Name     string
	Instance interface{}
	Module   *Module
}

type RouteSpec

type RouteSpec = controller.RouteSpec

Original type:

type RouteSpec struct {
	Method  string
	Path    string
	Handler gin.HandlerFunc
}

type RuntimeOptions

type RuntimeOptions = app.RuntimeOptions

Original type:

type RuntimeOptions struct {
	Port int
	TLS  *TLSOption
}

type ServerEngineOption

type ServerEngineOption = engine.ServerEngineOption

Original type:

type ServerEngineOption struct {
	EngineType string
}

type TLSOption added in v0.0.6

type TLSOption = engine.TLSOption

Original type:

type TLSOption struct {
	CertFile string
	KeyFile  string
}

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