box

package module
v2.0.0-...-c87de9c Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Application

type Application interface {
	ID() string
	Name() string
	Version() string
	Namespace() string
	Metadata() map[string]string
	Run() error
}

func New

func New(options ...Option) Application

New a box bootstrap

type Box

type Box interface {
	Name() string
}

type Option

type Option func(ops *Options)

Option setter

func WithAutoMaxProcs

func WithAutoMaxProcs(autoMaxProcs bool) Option

WithAutoMaxProcs auto set `P`

func WithBoxes

func WithBoxes(boxes ...Box) Option

WithBoxes set boxes

func WithId

func WithId(id string) Option

WithId with service id.

func WithLog

func WithLog(l log.Logger) Option

WithLog with service id.

func WithMeta

func WithMeta(meta map[string]string) Option

WithMeta with service metadata.

func WithName

func WithName(name string) Option

WithName with service name.

func WithNameSpace

func WithNameSpace(namespace string) Option

WithNameSpace with service namespace.

func WithShutdownTimeout

func WithShutdownTimeout(timeout int) Option

WithShutdownTimeout app shutdown timeout

func WithStartupTimeout

func WithStartupTimeout(timeout int) Option

WithStartupTimeout app startup timeout

func WithVersion

func WithVersion(version string) Option

WithVersion with service version.

type Options

type Options struct {
	// contains filtered or unexported fields
}

Options new box options

Directories

Path Synopsis
Package build contains application build information ```sh go build -ldflags="-X 'github.com/boxgo/box/v2/build.ID={ID}' -X 'github.com/boxgo/box/v2/build.Name={Name}' -X 'github.com/boxgo/box/v2/build.Version={Version}' -X 'github.com/boxgo/box/v2/build.Namespace={Namespace}'" ```
Package build contains application build information ```sh go build -ldflags="-X 'github.com/boxgo/box/v2/build.ID={ID}' -X 'github.com/boxgo/box/v2/build.Name={Name}' -X 'github.com/boxgo/box/v2/build.Version={Version}' -X 'github.com/boxgo/box/v2/build.Namespace={Namespace}'" ```
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.
Package codec handles data encoding
Package codec handles data encoding
xml
Package config is an interface for dynamic configuration.
Package config is an interface for dynamic configuration.
reader
Package reader parses change sets and provides config values
Package reader parses change sets and provides config values
source
Package source is the interface for sources
Package source is the interface for sources
source/file
Package file is a file source.
Package file is a file source.
contrib
grpc
internal
Package schedule is to help you manage schedule tasks.
Package schedule is to help you manage schedule tasks.
ginserver/mid/ginlog
Package ginlog is gin server logger middleware.
Package ginlog is gin server logger middleware.
ginserver/mid/ginsession
Package ginsession is gin server session middleware.
Package ginsession is gin server session middleware.
util

Jump to

Keyboard shortcuts

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