Malt

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2025 License: MIT Imports: 15 Imported by: 0

README

Malt

Malt 是一个基于 gin 和 grpc 的轻量级化的 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

View Source
const (
	Release = "v 0.2.0"
)

Variables

This section is empty.

Functions

func NewContext added in v0.2.1

func NewContext(ctx context.Context, s AppInfo) context.Context

NewContext returns a new Context that carries value.

Types

type App added in v0.2.1

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

func New added in v0.2.1

func New(opts ...Option) *App

func (*App) Endpoint added in v0.2.1

func (a *App) Endpoint() []string

func (*App) ID added in v0.2.1

func (a *App) ID() string

func (*App) Metadata added in v0.2.1

func (a *App) Metadata() map[string]string

func (*App) Name added in v0.2.1

func (a *App) Name() string

func (*App) Run added in v0.2.1

func (app *App) Run() error

服务启动

func (*App) Stop added in v0.2.1

func (app *App) Stop() error

服务停止

func (*App) Version added in v0.2.1

func (a *App) Version() string

type AppInfo added in v0.2.1

type AppInfo interface {
	ID() string
	Name() string
	Version() string
	Metadata() map[string]string
	Endpoint() []string
}

AppInfo is application context value.

func FromContext added in v0.2.1

func FromContext(ctx context.Context) (s AppInfo, ok bool)

FromContext returns the Transport value stored in ctx, if any.

type Option added in v0.2.1

type Option func(*options)

func WithEndpoints added in v0.2.1

func WithEndpoints(endpoints []*url.URL) Option

func WithId added in v0.2.1

func WithId(id string) Option

func WithLogger added in v0.2.1

func WithLogger(logger log.Logger) Option

func WithMetadata added in v0.2.1

func WithMetadata(metadata map[string]string) Option

func WithName added in v0.2.1

func WithName(Name string) Option

func WithRESTServer added in v0.2.1

func WithRESTServer(restserver ...restserver.Server) Option

func WithRPCServer added in v0.2.1

func WithRPCServer(rpcserver ...rpcserver.Server) Option

func WithRegistrar added in v0.2.1

func WithRegistrar(registrar registry.Registrar) Option

func WithRegistrarTimeout added in v0.2.1

func WithRegistrarTimeout(timeout time.Duration) Option

func WithServer added in v0.2.1

func WithServer(server ...malitServer.Server) Option

func WithSignal added in v0.2.1

func WithSignal(signal []os.Signal) Option

func WithStopTimeout added in v0.2.1

func WithStopTimeout(timeout time.Duration) Option

func WithTags added in v0.2.1

func WithTags(tags []string) Option

func WithVersion added in v0.2.1

func WithVersion(version string) Option

type Server

type Server interface {
	// Start 启动服务器
	Start(ctx context.Context) error
	//	Stop 停止服务器
	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
rpc
core
RBAC/Casbin
a RBAC auth check by casbin
a RBAC auth check by casbin
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
auth-jwt
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
errors
Package errors provides simple error handling primitives.
Package errors provides simple error handling primitives.
errors/codgen command
log
rest/rest-fiber/internal/auth
Basic Auth middleware
Basic Auth middleware
rest/rest-fiber/internal/pprof
this is a copy of https://github.com/gofiber/fiber/blob/main/middleware/pprof/config.go
this is a copy of https://github.com/gofiber/fiber/blob/main/middleware/pprof/config.go
rest/rest-gin/internal/auth
Basic Auth middleware
Basic Auth middleware
rest/rest-gin/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
auth check by jwt

Jump to

Keyboard shortcuts

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