Git Product home page Git Product logo

rk-boot's Introduction

rk-boot

build codecov Go Report Card Sourcegraph GoDoc Release License FOSSA Status

Official site

rkdev.info

Join discussing channel

Channel Code
Wechat group (CN) image
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.

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.

Plugins V2

We will migrate dependencies from v1 to v2 as quick as possible.

Category Name V2 go get Example
Web
Framework
gin-gonic/gin github.com/rookie-ninja/rk-gin/v2 example
gRPC github.com/rookie-ninja/rk-grpc/v2 example
labstack/echo github.com/rookie-ninja/rk-echo example
gogf/gf github.com/rookie-ninja/rk-gf example
gofiber/fiber github.com/rookie-ninja/rk-fiber example
zeromicro/go-zero github.com/rookie-ninja/rk-zero example
gorilla/mux github.com/rookie-ninja/rk-mux example
Database
ORM
MySQL github.com/rookie-ninja/rk-db/mysql example
SQLite github.com/rookie-ninja/rk-db/sqlite example
SQL Server github.com/rookie-ninja/rk-db/sqlserver example
postgreSQL github.com/rookie-ninja/rk-db/postgres example
ClickHouse github.com/rookie-ninja/rk-db/clickhouse example
MongoDB github.com/rookie-ninja/rk-db/mongodb example
Redis github.com/rookie-ninja/rk-db/redis example
Caching Redis github.com/rookie-ninja/rk-cache/redis example
Cloud AWS github.com/rookie-ninja/rk-cloud/aws TODO
AWS/KMS github.com/rookie-ninja/rk-cloud/aws/kms TODO
AWS/KMS/Signer github.com/rookie-ninja/rk-cloud/aws/signer TODO
AWS/KMS/Crypto github.com/rookie-ninja/rk-cloud/aws/crypto TODO
Tencent github.com/rookie-ninja/rk-cloud/tencent TODO
Tencent/KMS github.com/rookie-ninja/rk-cloud/tencent/kms TODO
Tencent/KMS/Signer github.com/rookie-ninja/rk-cloud/tencent/signer TODO
Tencent/KMS/Crypto github.com/rookie-ninja/rk-cloud/tencent/crypto TODO

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
  • boot.yaml
---
gin:
  - name: greeter                                          # Required
    port: 8080                                             # Required
    enabled: true                                          # Required
    sw:
      enabled: true                                        # Optional, default: false
    docs:
      enabled: true                                        # Optional, default: false
  • 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"
	"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 [email protected]

// @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
}
  • validate
$ 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
}

image

image

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 [email protected].

Released under the Apache 2.0 License.

Star

Stargazers over time

License

FOSSA Status

rk-boot's People

Contributors

dongxuny avatar fossabot avatar kevwan avatar naruepanart avatar shengyu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.