Malt

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 18, 2025 License: MIT Imports: 1 Imported by: 0

README

Malt

Malt 是一个轻量级、模块化的 Go 微服务框架,旨在简化分布式系统的开发和部署。框架提供了丰富的功能组件,包括 HTTP 服务器、RPC 客户端/服务器、指标监控、链路追踪等,帮助开发者快速构建高性能、可观测的微服务应用。

特性

  • HTTP 服务 :基于 Gin 的 RESTful API 服务,支持中间件、参数验证、JWT 认证等
  • RPC 通信 :基于 gRPC 的高性能 RPC 服务,支持服务发现、负载均衡等
  • 可观测性 :集成 Prometheus 指标监控、OpenTelemetry 链路追踪
  • 性能分析 :内置 pprof 性能分析工具,便于问题排查
  • 权限控制 :支持 RBAC 基于角色的访问控制
  • 错误显示 :支持多语言错误提示和消息翻译
  • 选项模式 :采用函数式选项模式,灵活配置各组件参数

quick start

安装
go get github.com/taluos/Malt
HttpServer 示例
package main

import (
    "github.com/taluos/Malt/server/rest/httpServer"
    "context"
    "github.com/gin-gonic/gin"
)

func main() {
    // 创建 HTTP 服务器
    server := httpServer.NewServer(
        httpServer.WithPort(8080),
        httpServer.WithEnableMetrics(true),
        httpServer.WithEnableTracing(true),
    )

    // 注册路由
    server.GET("/hello", func(c *gin.Context) {
        c.JSON(200, gin.H{"message": "Hello, Malt!"})
    })

    // 启动服务器
    _ = server.Start(context.Background())
}
RpcServer 示例
package main

import (
    "github.com/taluos/Malt/server/rpc/rpcServer"
    "context"
)

func main() {
    // 创建 RPC 服务器
    server := rpcServer.NewServer(
        rpcServer.WithAddress(":50051"),
        rpcServer.WithEnableMetrics(true),
        rpcServer.WithEnableTracing(true),
    )

    // 注册服务
    // pb.RegisterYourServiceServer(server.Server, &YourServiceImpl{})

    // 启动服务器
    _ = server.Start(context.Background())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server interface {
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
}

Directories

Path Synopsis
api
metadata
this file is copied from https://github.com/go-kratos/kratos/blob/main/api/metadata/server.go
this file is copied from https://github.com/go-kratos/kratos/blob/main/api/metadata/server.go
core
resolver/discovery
In this file we define discorveryResolver struct and its methods, to replace the grpc resolver.Resolver interface by your own.
In this file we define discorveryResolver struct and its methods, to replace the grpc resolver.Resolver interface by your own.
trace/exporter/jaeger
this is a modified version of jaeger exporter in https://github.com/zeromicro/go-zero/blob/master/core/trace/agent.go
this is a modified version of jaeger exporter in https://github.com/zeromicro/go-zero/blob/master/core/trace/agent.go
example
GroupStart command
features/trace command
rest command
rpc command
pkg
errors
Package errors provides simple error handling primitives.
Package errors provides simple error handling primitives.
errors/codgen command
log
rest/internal/RBAC/Casbin
a RBAC auth check by casbin
a RBAC auth check by casbin
rest/internal/auth
Basic Auth middleware
Basic Auth middleware
rest/internal/pprof
this is a copy of "https://github.com/gin-contrib/pprof/blob/master/pprof.go
this is a copy of "https://github.com/gin-contrib/pprof/blob/master/pprof.go
rpc/internal/auth
this file is modified from https://github.com/zeromicro/go-zero/blob/master/zrpc/internal/auth/auth.go
this file is modified from https://github.com/zeromicro/go-zero/blob/master/zrpc/internal/auth/auth.go
auth check by jwt

Jump to

Keyboard shortcuts

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