box

package module
v1.0.0-beta.14 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2021 License: Apache-2.0 Imports: 10 Imported by: 1

README

						____
						|  _ \
						| |_) | _____  __
						|  _ < / _ \ \/ /
						| |_) | (_) >  <
						|____/ \___/_/\_\

English | 简体中文

PkgGoDev Go Report Card CI Status Coverage Status Release


Box

Box 致力于解决企业级项目开发过程中的各类痛点,帮助你轻松构建稳定、健壮、安全,高性能的应用。

Features

  • 生命周期管理,模块可挂载至box启动器托管启动/停止/前置/后置任务

  • 配置功能丰富,支持多配置源、动态更新配置、配置信息注册/查询

  • 可选服务协议,支持gRPC、http

  • 指标采集,支持自定义指标,易接入Dashboard、报警系统

  • 链路跟踪,调用链路还原、查询、诊断

  • 规范、强大的日志记录,可动态调整日志级别

  • 在线pprof,方便分析线上问题

  • 定时任务系统

  • 规范错误,收敛错误码与错误消息定义

  • 级联超时与取消控制,内建方法使用context扩散

  • 简单、友好的接口

  • 服务注册与发现(开发中)

  • 限流、熔断,降级(开发中)

  • 请求表单自动校验(开发中)

  • 接口文档自动生成(开发中)

Installation

go get -u github.com/boxgo/box

Required

go version: go1.12+

grpc-go version: 1.26

Recommend

建议使用国内源:

  1. goproxy.cn
  2. goproxy.io

Qucik Start

  1. 编写配置文件
// box.yaml
box:
  name: testBox
  version: 1.0.0

gin:
  default:
    mode: release
    addr: ":9000"

logger:
  default:
    level: info
    outputPaths:
      - stdout
    errorOutputPaths:
      - stderr
  1. 编写程序代码
// main.go
package main

import (
	"github.com/boxgo/box"
	"github.com/boxgo/box/pkg/server/ginserver"
	"github.com/gin-gonic/gin"
)

func main() {
	app := box.New(
		box.WithBoxes(
			ginserver.Default,
		),
	)

	ginserver.GET("/ping", func(ctx *gin.Context) {
		ctx.Data(200, gin.MIMEPlain, []byte("pong"))
	})

	app.Run()
}
  1. 启动程序
$ go run main.go # 启动程序

通过go run main.go命令启动我们的程序,可以看到如上所示界面,这个表格是我们程序所使用到的配置描述。紧跟其后的是程序启动时的配置信息。再往下,我们就看到了box启动器开始启动,box启动器启动GinServer服务,由于我们没有挂载其他组件,这时候启动器启动完成。

通过 ctrl + c 我们看到启动器开始停止工作,然后GinServer被关闭,整个进程退出。

  1. 验证程序
$ curl http://127.0.0.1:9000/ping
$ pong

可以看到,请求ping接口已经返回"pong"了。

Documentation

官方网站:boxgo.github.io/website

Plan

  • 更多的文档
  • 更多的单元测试
  • 更高的代码覆盖率
  • 服务注册与发现
  • 熔断、限流、降级
  • 接口文档生成
  • 请求表单自动校验
  • 一站式管控平台

Thanks

感谢 Jetbrains 为本项目提供License。

Jetbrains

Documentation

Overview

Package box is a bootstrap to help you build mirco services easily.

Example

Example this is a ping-pong http server.

package main

import (
	"github.com/boxgo/box"
	"github.com/boxgo/box/pkg/logger"
	"github.com/boxgo/box/pkg/server/ginserver"
	"github.com/gin-gonic/gin"
)

func main() {
	ginserver.Default.GET("/ping", func(ctx *gin.Context) {
		ctx.JSON(200, "pong")
	})

	app := box.New(
		box.WithBoxes(
			ginserver.Default,
		),
	)

	if err := app.Run(); err != nil {
		logger.Errorw("server run error: ", "err", err)
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Application

type Application interface {
	Run() error
}

func New

func New(options ...Option) Application

New new a box bootstrap

type Box

type Box interface {
	Name() string
}

type Option

type Option func(ops *Options)

Option setter

func WithAutoMaxProcs added in v1.0.0

func WithAutoMaxProcs(autoMaxProcs bool) Option

WithAutoMaxProcs

func WithBoxes

func WithBoxes(boxes ...Box) Option

WithBoxes set boxes

func WithShutdownTimeout

func WithShutdownTimeout(timeout int) Option

WithShutdownTimeout

func WithStartupTimeout

func WithStartupTimeout(timeout int) Option

type Options

type Options struct {
	StartupTimeout  int
	ShutdownTimeout int
	AutoMaxProcs    *bool
	Boxes           []Box
}

Options new box options

Directories

Path Synopsis
pkg
client/rabbitmq
Package rabbitmq is an AMQP 0.9.1 client with RabbitMQ extensions in Go.
Package rabbitmq is an AMQP 0.9.1 client with RabbitMQ extensions in Go.
config
Package config is an interface for dynamic configuration.
Package config is an interface for dynamic configuration.
config/encoder
Package encoder handles source encoding formats
Package encoder handles source encoding formats
config/loader
Package loader manages loading from multiple sources
Package loader manages loading from multiple sources
config/reader
Package reader parses change sets and provides config values
Package reader parses change sets and provides config values
config/source
Package source is the interface for sources
Package source is the interface for sources
config/source/file
Package file is a file source.
Package file is a file source.
schedule
Package schedule is to help you manage schedule tasks.
Package schedule is to help you manage schedule tasks.

Jump to

Keyboard shortcuts

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