ninja

package module
v0.0.0-...-67e0549 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2022 License: MIT Imports: 19 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Ninja

Build Status

a simple ioc for https://github.com/facebookgo/inject

⚙ Installation

go get -u github.com/eininst/ninja

⚡ Quickstart

package main

import (
	"github.com/eininst/ninja"
	"github.com/gofiber/fiber/v2"
)

type Router struct {
    Cfg    *ninja.Config `inject:""`
}

func (r *Router) Init(router fiber.Router) {
    router.Get("/", func(ctx *fiber.Ctx) error {
        return ctx.SendString("helloword")
    })
}

func main() {
    nj := ninja.NewApp("./examples/helloword.yml")
    ninja.Provide(new(Router))
	
    nj.Listen()
}

Config yaml

ninja:
  port: 8001
  middleware:
    - recover:
    - limiter:
        rate: 10
        burst: 200
        timeout: 5
    - status:
    - logger:
    - metrics:

---
profile: dev

redis:
  addr: kubernetes.docker.internal:6379
  db: 0
  poolSize: 100
  minIdleCount: 20

mysql:
  dsn: nft:Aa505814@tcp(localhost:3306)/credit?charset=utf8mb4&parseTime=True&loc=Local
  maxIdleCount: 32
  maxOpenCount: 128
  maxLifetime: 7200

rs:
  prefix: MQ_
  sender:
    maxLen: 100

---
profile: prod

redis:
  addr: kubernetes.docker.internal:6379
  db: 0
  poolSize: 100
  minIdleCount: 20

mysql:
  dsn: test:test123@tcp(localhost:3306)/credit?charset=utf8mb4&parseTime=True&loc=Local
  maxIdleCount: 32
  maxOpenCount: 128
  maxLifetime: 7200

Depends

https://github.com/gofiber/fiber #Fiber framework

https://github.com/facebookgo/inject #依赖注入

https://github.com/eininst/fiber-prefork-grace #Fiber Prefork(多进程)模式下的优雅退出

https://github.com/eininst/fiber-middleware-burst #Fiber的令牌桶限流器

https://github.com/eininst/fiber-middleware-recover #Fiber的错误处理中间件

https://github.com/eininst/fiber-middleware-redoc #Fiber redoc

See examples

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Objects

func Objects() []*inject.Object

func Populate

func Populate(objects ...any)

func Provide

func Provide(objects ...any)

Types

type AppConfig

type AppConfig struct {
	Port         string `json:"port"`
	Prefork      bool   `json:"prefork"`
	ReadTimeout  int64  `json:"readTimeout"`
	WriteTimeout int64  `json:"writeTimeout"`
}

type Config

type Config struct {
	Data      map[string]any
	Ret       gjson.Result
	AppConfig *AppConfig
}

func NewConfig

func NewConfig(path string, profile ...string) *Config

func (*Config) Get

func (c *Config) Get(path ...string) gjson.Result

func (*Config) GetAppConfig

func (c *Config) GetAppConfig() *AppConfig

func (*Config) IsDev

func (c *Config) IsDev() bool

func (*Config) IsProd

func (c *Config) IsProd() bool

func (*Config) IsTest

func (c *Config) IsTest() bool

func (*Config) IsUat

func (c *Config) IsUat() bool

type Ninja

type Ninja struct {
	FiberApp *fiber.App
	Config   *Config
}

func NewApp

func NewApp(path string, profile ...string) *Ninja

func NewAppByConfig

func NewAppByConfig(cfg *Config) *Ninja

func (*Ninja) App

func (n *Ninja) App() *fiber.App

func (*Ninja) Listen

func (n *Ninja) Listen(config ...grace.Config)

type Router

type Router interface {
	Init(router fiber.Router)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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