Skip to content

Bootstrapper for golang application. See https://rkdev.info/docs/ for details.

License

Notifications You must be signed in to change notification settings

shengyu/rk-boot

 
 

rk-boot

build codecov Go Report Card License FOSSA Status

Table of Contents generated with DocToc

Important note

The version of v1.3.X imported rk-gin, rk-echo, rk-grpc and rk-gf in the go.mod file initially. User only needs to [go get rk-boot] for starting web framework.

From v1.4.X, rk-boot will not include those dependencies in one place.

Instead, we use multi-module repository for supported web frameworks.

Release Description Example
v1.4.x Use multi-module repository, [go get] submodule as needed for web frameworks go get github.com/rookie-ninja/rk-boot/gin
v1.3.x Use root-module repository, will import all web frameworks, not suggested! go get github.com/rookie-ninja/rk-boot

The version of submodule will follow version of rk-xxx dependencies.

For example, rk-grpc is currently at release of v1.2.15, so the latest version of submodule would be github.com/rookie-ninja/rk-boot/grpc@v1.2.15

Official document

rkdev.info

Concept

rk-boot is a library which support bootstrapping server at runtime via YAML file. It is a little like spring boot way.

arch

Goal

We hope user can achieve bellow goals while designing/implementing microservice.

  • 1: Decide which dependencies to use. (For example, MySQL, Redis, AWS, Gin are the required dependencies.)
  • 2: Add dependencies in boot.yaml (where rk-boot will automatically initiate dependency client instances.)
  • 3: Implement your own codes (without caring about logging, metrics and tracing of dependency client.)
  • 4: Monitor service and dependency (via a standard dashboard.)

We are planning to achieve this goal by unify dependency input(by boot.yaml) and output(logging format, metrics format etc).

We will add more bootstrapper for popular third-party dependencies.

Why do I want it?

  • Build application with unified project layout at enterprise level .
  • Build API with the unified format of logging, metrics, tracing, authorization at enterprise level.
  • Make application replace core dependencies quickly.
  • Save learning time of writing initializing procedure of popular frameworks and libraries.
  • User defined Entry for customization.

Features

Supported web frameworks

Welcome to contribute your web framework dependencies into rk-boot family.

Start with docs and refer rk-gin as example.

Frameworks Status Tag Installation Dependency
gin-gonic/gin Stable v1.2.22 go get github.com/rookie-ninja/rk-boot/gin rk-gin
gRPC Stable v1.2.25 go get github.com/rookie-ninja/rk-boot/grpc rk-grpc
labstack/echo Stable v0.0.16 go get github.com/rookie-ninja/rk-boot/echo rk-echo
gogf/gf Stable v0.0.15 go get github.com/rookie-ninja/rk-boot/gf rk-gf
gofiber/fiber Testing v0.0.11 go get github.com/rookie-ninja/rk-boot/fiber rk-fiber
zeromicro/go-zero Testing v0.0.11 go get github.com/rookie-ninja/rk-boot/zero rk-zero
gorilla/mux Testing v0.0.9 go get github.com/rookie-ninja/rk-boot/mux rk-mux

Supported database ORM

Databases still in Testing stage. Please see examples for detail.

Database Status Tag ORM Installation Dependency
MySQL Stable v0.0.6 gorm go get github.com/rookie-ninja/rk-db/mysql rk-db/mysql
SQLite Stable v0.0.4 gorm go get github.com/rookie-ninja/rk-db/sqlite rk-db/sqlite
SQL Server Stable v0.0.4 gorm go get github.com/rookie-ninja/rk-db/sqlserver rk-db/sqlserver
postgreSQL Stable v0.0.4 gorm go get github.com/rookie-ninja/rk-db/postgres rk-db/postgres
ClickHouse Stable v0.0.4 gorm go get github.com/rookie-ninja/rk-db/clickhouse rk-db/clickhouse

Examples

Name Type Example Docs
gin-gonic/gin Web Framework example docs
gRPC Web Framework example docs
labstack/echo Web Framework example docs
gogf/gf Web Framework example docs
gofiber/fiber Web Framework example docs
zeromicro/go-zero Web Framework example docs
gorilla/mux Web Framework example docs
MySQL ORM - gorm example docs
SQLite ORM - gorm example docs
SQL Server ORM - gorm example docs
postgreSQL ORM - gorm example docs
ClickHouse ORM - gorm example docs

Quick Start for Gin

We will start gin-gonic/gin server with rk-boot.

  • Installation

go get github.com/rookie-ninja/rk-boot/gin

  • boot.yaml
---
gin:
  - name: greeter       # Required
    port: 8080          # Required
    enabled: true       # Required
    sw:
      enabled: true     # Optional, enable swagger UI via /sw by default
    commonService:
      enabled: true     # Optional, enable common API like /rk/v1/healthy
    tv:
      enabled:  true    # Optional, enable RK TV via /rk/v1/tv
  • main.go
// Copyright (c) 2021 rookie-ninja
//
// Use of this source code is governed by an Apache-style
// license that can be found in the LICENSE file.
package main

import (
	"context"
	"github.com/gin-gonic/gin"
	"github.com/rookie-ninja/rk-boot"
	"github.com/rookie-ninja/rk-boot/gin"
	"net/http"
)

// Application entrance.
func main() {
	// Create a new boot instance.
	boot := rkboot.NewBoot()

	// Register handler
	ginEntry := rkbootgin.GetGinEntry("greeter")
	ginEntry.Router.GET("/v1/greeter", func(ctx *gin.Context) {
		ctx.JSON(http.StatusOK, "Hello!")
	})
	
	// Bootstrap
	boot.Bootstrap(context.Background())

	// Wait for shutdown sig
	boot.WaitForShutdownSig(context.Background())
}
  • validate
$ go run main.go

$ curl -X GET localhost:8080/rk/v1/healthy
{"healthy":true}

$ curl -X GET localhost:8080/v1/greeter
Hello!

gin-sw

gin-tv

Development Status: Stable

Build instruction

Simply run make all to validate your changes. Or run codes in example/ folder.

  • make all If proto or files in boot/assets were modified, then we need to run it.

Test instruction

Run unit test with make test command.

github workflow will automatically run unit test and golangci-lint for testing and lint validation.

Contributing

We encourage and support an active, healthy community of contributors — including you! Details are in the contribution guide and the code of conduct. The rk maintainers keep an eye on issues and pull requests, but you can also report any negative conduct to lark@rkdev.info.

Released under the Apache 2.0 License.

License

FOSSA Status

About

Bootstrapper for golang application. See https://rkdev.info/docs/ for details.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Go 86.2%
  • Makefile 13.8%