rk-boot
Official site
rkdev.info
Join discussing channel
Channel |
Code |
Wechat group (CN) |
|
Slack channel (EN) |
#rk-boot |
Important note about V2
RK family is bumping up to V2 which will not be full compatible with V1 including documentation. Please refer to V1 as needed.
From V2, rk-boot will not include any of dependencies which implement rkentry.Entry. As a result, user need to pull rk-boot and rk-xxx or user implemented Entry manually.
We think it will be a better experience for dependency management.
For example, if we hope to start Gin web framework, we need to pull both of rk-boot and rk-gin. example
Official document
V2 documentation will be updated soon. Please refer to github docs now.
Concept
rk-boot is a library which support bootstrapping server at runtime via YAML file. It is a little like spring boot way.
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.
Plugins V2
We will migrate dependencies from v1 to v2 as quick as possible.
Quick Start for Gin
We will start gin-gonic/gin server with rk-boot.
- Installation
rk-boot is required one for all RK family. We pulled rk-gin as dependency since we are testing GIN.
go get github.com/rookie-ninja/rk-boot/v2
go get github.com/rookie-ninja/rk-gin/v2
---
gin:
- name: greeter # Required
port: 8080 # Required
enabled: true # Required
sw:
enabled: true # Optional, default: false
docs:
enabled: true # Optional, default: false
// 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"
"fmt"
"github.com/gin-gonic/gin"
"github.com/rookie-ninja/rk-boot/v2"
"github.com/rookie-ninja/rk-gin/v2/boot"
"net/http"
)
// @title Swagger Example API
// @version 1.0
// @description This is a sample rk-demo server.
// @termsOfService http://swagger.io/terms/
// @securityDefinitions.basic BasicAuth
// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email support@swagger.io
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
func main() {
// Create a new boot instance.
boot := rkboot.NewBoot()
// Register handler
entry := rkgin.GetGinEntry("greeter")
entry.Router.GET("/v1/greeter", Greeter)
// Bootstrap
boot.Bootstrap(context.TODO())
boot.WaitForShutdownSig(context.TODO())
}
// Greeter handler
// @Summary Greeter
// @Id 1
// @Tags Hello
// @version 1.0
// @Param name query string true "name"
// @produce application/json
// @Success 200 {object} GreeterResponse
// @Router /v1/greeter [get]
func Greeter(ctx *gin.Context) {
ctx.JSON(http.StatusOK, &GreeterResponse{
Message: fmt.Sprintf("Hello %s!", ctx.Query("name")),
})
}
type GreeterResponse struct {
Message string
}
$ go run main.go
$ curl -X GET localhost:8080/v1/greeter?name=rk-dev
{"Message":"Hello rk-dev!"}
$ curl -X GET localhost:8080/rk/v1/ready
{
"ready": true
}
$ curl -X GET localhost:8080/rk/v1/alive
{
"alive": true
}
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