gofks

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

README

Gofks 微服务脚手架

Gofks 是一个由Go编写的微服务脚手架。集成多个开源框架优秀思想。方便一键式上手编写业务代码,快速开发。

实现功能:

  1. 命令行工具支持(一键生成项目文件 webApi | webSocket | rpcServer | plugins )
  2. 兼容 gin 框架,极简的api调用
  3. 兼容 gRpc,支持中间件拦截器,方便扩展。内建限流、超时、链路追踪、自动恢复
  4. 兼容 plugins 阻塞式的插件类服务 (类似cron)
  5. 兼容 websocket 实现高并发可控的长连接控制,及路由管理调度gRpc
  6. 自定义可靠的、易扩展的 消息传输协议
  7. otel 链路追踪( rpc | websocket | db | redis )
  8. 配置热更新

Getting started

With Go module support, simply add the following import

import "github.com/bhmy-shm/gofks"

run the following Go command to install the gofks package:

$ go get -u github.com/bhmy-shm/gofks

Quick started

基于go-zero 开源框架二开实现

  1. 安装gofkctl 工具
$ go install github.com/bhmy-shm/gofk
  1. 快速生成 rpc 服务
$ gofkctl rpc new hello-rpc
  1. 快速生成 web-api 服务
$ gofkctl api new hello-web --rpc=hello-rpc
  1. 快速生成 web-api + websocket 服务
$ gofkctl api new hello-web --rpc=hello-rpc --websocket=true
  1. 快速生成 plugins 服务
$ gofkctl plugins new hello-plugins --server=first,secod,third -registry=ture  

example Directory

  1. web-api
  2. webSocket
  3. rpc-server
  4. plugins
  5. model-db

项目中 rpc 与 api-websocket 关联创建

  1. 创建项目目录,编写一个proto文件
syntax = "proto3";

package user;
option go_package = "./user";

message Status {
  uint64 code = 1 [json_name = "code,required"];
  string reason = 2;
  string message = 3;
  map<string, string> metadata = 4;
};

message PageParam {
  int32 pageNum = 1; //当前页
  int32 pageSize = 2; //查询数量
}

service UserClient {
  //用户配置
  rpc Login(LoginReq)  returns (LoginResp);
  rpc UpPass(UpPassReq) returns (UpPassResp);
}
  1. 基于proto文件生成 rpc项目
$ cd mall/user/rpc
$ gofkctl rpc protoc user.proto \
  --go_out=./types --go-grpc_out=./types \
  --name=user-rpc \
  --port=9091 
  1. 基于rpc项目 生成 websocket 和 api服务
$ gofkctl api new v1 --websocket --rpc=user-rpc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExceptionResp

func ExceptionResp(ctx *gin.Context, resp errorx.ErrCode)

func InternalResp

func InternalResp(ctx *gin.Context, err *errorx.Error)

func Successful

func Successful(ctx *gin.Context, data interface{})

Types

type CronInter

type CronInter interface {
	Get() *cron.Cron
	Close()
}

func NewCronTask

func NewCronTask() CronInter

type Gofk

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

func Ignite

func Ignite(rootPath string, middles ...gin.HandlerFunc) *Gofk

Ignite 加载web路由

func NewRpcServer

func NewRpcServer(conf *gofkConf.Config) *Gofk

func WebSocket

func WebSocket(conf *gofkConf.Config, root string) *Gofk

WebSocket 简单封装

func (*Gofk) Attach

func (gk *Gofk) Attach(opts ...grpc.ServerOption) *Gofk

func (*Gofk) Cron

func (g *Gofk) Cron(cron string, expr interface{}) *Gofk

Cron 计划任务

func (*Gofk) GetGroup

func (g *Gofk) GetGroup() *gin.RouterGroup

GetGroup 获取当前路由

func (*Gofk) Group

func (g *Gofk) Group(path string) *gin.RouterGroup

Group 设置web子路由

func (*Gofk) Launch

func (g *Gofk) Launch()

Launch 启动 web 服务

func (*Gofk) LoadWatch

func (g *Gofk) LoadWatch(conf *gofkConf.Config) *Gofk

LoadWatch 加载配置文件与监听

func (*Gofk) Mount

func (g *Gofk) Mount(classes ...GofkCase) *Gofk

Mount 挂载 web、plugin 服务插件

func (*Gofk) PProf

func (g *Gofk) PProf(path string)

PProf 程序火箭图

func (*Gofk) Register

func (gk *Gofk) Register(servers ...zrpc.RpcRegisterInter) *Gofk

func (*Gofk) Start

func (gk *Gofk) Start() *Gofk

func (*Gofk) Stop

func (gk *Gofk) Stop()

func (*Gofk) WireApply

func (g *Gofk) WireApply(beans ...interface{}) *Gofk

WireApply 配置依赖,注入注册

type GofkCase

type GofkCase interface {
	Build(*Gofk)
	Name() string
}

type PluginManager

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

func Plugin

func Plugin(conf *gofkConf.Config) *PluginManager

func (*PluginManager) Attach

func (p *PluginManager) Attach(opts ...plugin.OptionFunc) *PluginManager

func (*PluginManager) Mount

func (p *PluginManager) Mount(access ...plugin.PluginItem) *PluginManager

func (*PluginManager) Run

func (p *PluginManager) Run()

type Resp

type Resp struct {
	Code    uint64
	Reason  string
	Message string
	Data    interface{}
}

Jump to

Keyboard shortcuts

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