mix

package module
v1.21.4 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 55 Imported by: 0

README

mix

Go Reference

mix 是一个开箱即用的 Go 微服务运行时:在同一进程中同时暴露 HTTPgRPC,并内置可观测性、访问日志与优雅关停。

适合与 hopeio/protobuf 工具链配合,快速搭建基于 Protobuf 的云原生服务。

server

特性

  • 同端口多协议 — HTTP/1.1、明文 HTTP/2(gRPC)共用主监听地址;按 Content-Type 自动分发到 gRPC 或 HTTP 处理器
  • HTTP/3 — 基于 quic-go 可选启用
  • 请求上下文 — 通过 mix.Metadata 在 HTTP / gRPC 链路中传递 trace、token、logger 等
  • 访问日志 — HTTP 与 gRPC 均可记录请求/响应体,支持路径前缀过滤
  • OpenTelemetry — HTTP、gRPC 链路追踪与指标,与 hopeio/gox 日志字段对齐
  • 内部端口 — 默认 :8081 暴露 OpenAPI 文档(Redoc)与 pprof 调试端点
  • CORS / 中间件 / TLS — 通过 Option 组合配置
  • 优雅关停 — 监听 SIGINT / SIGTERM,依次停止 gRPC 与 HTTP

架构

                    ┌─────────────────────────────────┐
  Client ──────────►│  :8080  主服务(HTTP + gRPC)    │
                    │  ├─ HTTP  → Gin / ServeMux / …  │
                    │  └─ gRPC  → grpc.Server         │
                    └─────────────────────────────────┘
                    ┌─────────────────────────────────┐
  运维 / 文档 ──────►│  :8081  内部端口                 │
                    │  ├─ /openapi  Redoc 文档        │
                    │  └─ /debug    pprof             │
                    └─────────────────────────────────┘

快速开始

安装
go get github.com/hopeio/mix
最小示例
package main

import (
	"net/http"

	"github.com/hopeio/mix"
	"google.golang.org/grpc"
)

func main() {
	mix.NewServer(
		mix.WithHttpHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			w.Write([]byte("hello"))
		})),
		mix.WithGrpcHandler(func(s *grpc.Server) {
			// pb.RegisterYourServiceServer(s, &impl{})
		}),
	).Run()
}

完整示例见 _example/

go run ./_example

_example 演示了 gRPC 服务注册,以及通过 gox/net/http/grpc/gateway 将 RPC 暴露为 HTTP 接口。

配置选项

Option 说明
WithHttpHandler 主 HTTP 处理器(必填)
WithGrpcHandler 注册 gRPC 服务
WithHttp 自定义 http.Server 字段(地址、超时等)
WithHTTP3 启用 HTTP/3
WithInternalServer 自定义内部端口(OpenAPI / pprof)
WithCors 跨域配置
WithOtel OpenTelemetry
WithMiddleware HTTP 中间件链
WithGrpc gRPC 拦截器与 ServerOption
请求元数据

在 Handler 中通过 context 获取请求元数据:

import "github.com/hopeio/mix"

func handler(ctx context.Context) {
	md := mix.GetMetadata(ctx)
	if md != nil {
		_ = md.TraceId
		_ = md.Token
		md.Set("key", "value")
	}
}
与配置注入框架配合

Server 实现了 BeforeInject / AfterInject,可与 hopeio/initialize 等 DI 框架集成:

global.Conf.Server.WithOptions(
	mix.WithHttpHandler(app),
	mix.WithGrpcHandler(api.GrpcRegister),
).Run()

工具链

mix 本身不负责代码生成,推荐配合 hopeio 系列工具使用:

安装 protoc 插件
  • 安装 protoc
  • 安装 hopeio 工具集:
go run $(go list -m -f {{.Dir}} github.com/hopeio/protobuf)/tools/install_tools.go
生成代码
protogen go -d -e -w -v -i _example/proto -o _example/protobuf
标志 含义
-d OpenAPI 文档
-e 枚举扩展
-w Gin gRPC-Gateway
-v 请求校验代码
-g GraphQL(可选)

也可使用 Docker:

docker run --rm -v $PWD:/work jybl/protogen \
  protogen go -d -e -w -i $proto_path -o $proto_output_path

生成物可对接:

  • Gin Gatewayprotoc-gen-grpc-gin 生成的路由
  • grpc-gateway — 标准 google.api.http 注解

默认端口

端口 用途
:8080 主服务(HTTP + gRPC)
:8081 OpenAPI 文档 / pprof

相关项目

仓库 说明
hopeio/gox 日志、HTTP 工具、gRPC-Gateway 封装
hopeio/protobuf protoc 插件与 protogen CLI
hopeio/scaffold OTel、Prometheus、JWT 等脚手架
hopeio/initialize 配置加载与服务初始化

License

MIT

Documentation

Index

Constants

View Source
const (
	ContentTypeJson     = "json"
	ContentTypeProtobuf = "protobuf"
)
View Source
const ScopeName = "github.com/hopeio/mix"

Variables

View Source
var (
	DefaultMemory int64 = 32 << 20
	CommonTag           = "json"
	Validate            = validator.ValidateStruct
)
View Source
var (
	DefaultUnmarshal UnmarshalFunc = func(ctx context.Context, contentType string, data []byte, v any) error {
		return jsonx.Unmarshal(data, v)
	}

	DefaultMarshal MarshalFunc = func(ctx context.Context, v any) (data []byte, contentType string, err error) {
		switch msg := v.(type) {
		case *CommonAnyResp, *ErrResp:
			data, err = jsonx.Marshal(msg)
		case error:
			data, err = jsonx.Marshal(ErrRespFrom(msg))
		}
		data, err = jsonx.Marshal(&CommonAnyResp{Data: v})
		if err != nil {
			return data, httpx.ContentTypeText, err
		}
		return data, httpx.ContentTypeJson, nil
	}
)
View Source
var ErrHeaderKey errHeaderKey
View Source
var MetadataKey = metadataKey{}

Functions

func Bind added in v1.21.3

func Bind(r *http.Request, v any) error

func CommonBind added in v1.21.3

func CommonBind(s Source, v any) error

unhandle multipart form data currently

func DefaultAccessLog

func DefaultAccessLog(ctx context.Context, param *AccessLogParam)

func DefaultGrpcAccessLog

func DefaultGrpcAccessLog(ctx context.Context, param *GrpcAccessLogParam)

func HandlerWrap added in v1.21.3

func HandlerWrap[REQ, RESP any](service Service[*REQ, *RESP]) http.Handler

func HandlerWrapCommon added in v1.21.3

func HandlerWrapCommon[REQ, RESP any](service types.Service[*REQ, *RESP]) http.Handler

func JsonMarshal added in v1.21.3

func JsonMarshal(ctx context.Context, v any) ([]byte, string, error)

func RegisterErrCode added in v1.21.3

func RegisterErrCode(code ErrCode, msg string)

不是并发安全的,在初始化的时候做

func RegisterErrCodeHttpStatus added in v1.21.3

func RegisterErrCodeHttpStatus(code ErrCode, status int)

func RegisterErrCodeMap added in v1.21.3

func RegisterErrCodeMap(enum map[int32]string)

func RespodWithErrHeader added in v1.21.3

func RespodWithErrHeader(ctx context.Context) context.Context

func Respond added in v1.21.3

func Respond(ctx context.Context, w http.ResponseWriter, data any) (int, error)

func RespondErrCodeMsg added in v1.21.3

func RespondErrCodeMsg(ctx context.Context, w http.ResponseWriter, code ErrCode, msg string)

func RespondError added in v1.21.3

func RespondError(ctx context.Context, w http.ResponseWriter, err error) (int, error)

func RespondSSE added in v1.21.3

func RespondSSE[T ~string](ctx context.Context, w http.ResponseWriter, dataSource iter.Seq[T]) (int, error)

func RespondStream added in v1.21.3

func RespondStream(ctx context.Context, w http.ResponseWriter, dataSource iter.Seq[iox.WriterToCloser]) (int, error)

func RespondSuccess added in v1.21.3

func RespondSuccess(ctx context.Context, w http.ResponseWriter, res any) (int, error)

func Serve added in v1.21.3

func Serve(w http.ResponseWriter, r *http.Request, data any)

func ServeErrCodeMsg added in v1.21.3

func ServeErrCodeMsg(w http.ResponseWriter, r *http.Request, code ErrCode, msg string)

func ServeError added in v1.21.3

func ServeError(w http.ResponseWriter, r *http.Request, err error)

func ServeSuccess added in v1.21.3

func ServeSuccess(w http.ResponseWriter, r *http.Request, res any)

func SetMultipartFrormFile added in v1.21.3

func SetMultipartFrormFile(value reflect.Value, field *reflect.StructField, files []*multipart.FileHeader) (isSet bool, err error)

func StatusFromErrCode added in v1.21.3

func StatusFromErrCode(code ErrCode) int

func UnWrapContext added in v1.21.3

func UnWrapContext(ctx context.Context) any

func WithMetadata

func WithMetadata(ctx context.Context, metadata *Metadata) context.Context

func WrapContext added in v1.21.3

func WrapContext(v any) context.Context

Types

type AccessLog

type AccessLog = func(ctx context.Context, param *AccessLogParam)

type AccessLogConfig

type AccessLogConfig struct {
	RecordFunc      AccessLog
	ExcludePrefixes []string
	IncludePrefixes []string
}

type AccessLogParam

type AccessLogParam struct {
	Method, Url string
	*httpx.Recorder
	Metadata *Metadata
}

type BidiStream added in v1.21.3

type BidiStream[Req, Resp any, ReqPtr ProtoMessage[Req], RespPtr ProtoMessage[Resp]] interface {
	Recv() (ReqPtr, error)
	Send(RespPtr) error
	grpc.ServerStream
}

type BidiStreamHandler added in v1.21.3

type BidiStreamHandler[Req, Resp any, ReqPtr ProtoMessage[Req], RespPtr ProtoMessage[Resp], S BidiStream[Req, Resp, ReqPtr, RespPtr]] func(S) error

type BindFunc added in v1.21.3

type BindFunc func(r Source, v any) error

type Binder added in v1.21.3

type Binder interface {
	Bind(r *http.Request, v any) error
}

type Body

type Body struct {
	ContentType string
	Raw         []byte
	Data        any
}

type ClientSideStream added in v1.21.3

type ClientSideStream[Req, Resp any, ReqPtr ProtoMessage[Req], RespPtr ProtoMessage[Resp]] interface {
	Recv() (ReqPtr, error)
	SendAndClose(RespPtr) error
	grpc.ServerStream
}

type ClientSideStreamHandler added in v1.21.3

type ClientSideStreamHandler[Req, Resp any, ReqPtr ProtoMessage[Req], RespPtr ProtoMessage[Resp], S ClientSideStream[Req, Resp, ReqPtr, RespPtr]] func(S) error

type Codec added in v1.21.3

type Codec interface {
	Marshaler
	Unmarshaler
}

type CommonAnyResp added in v1.21.3

type CommonAnyResp = CommonResp[any]

func NewCommonAnyResp added in v1.21.3

func NewCommonAnyResp(code ErrCode, msg string, data any) *CommonAnyResp

type CommonBinder added in v1.21.3

type CommonBinder interface {
	Bind(r Source, v any) error
}

type CommonProtoResp added in v1.21.3

type CommonProtoResp[T proto.Message] CommonResp[T]

func NewCommonProtoResp added in v1.21.3

func NewCommonProtoResp[T proto.Message](code ErrCode, msg string, data T) *CommonProtoResp[T]

func (*CommonProtoResp[T]) MarshalProto added in v1.21.3

func (r *CommonProtoResp[T]) MarshalProto() ([]byte, error)

func (*CommonProtoResp[T]) UnmarshalProto added in v1.21.3

func (r *CommonProtoResp[T]) UnmarshalProto(data []byte) error

UnmarshalProto 手动解码 protobuf 数据到 CommonProtoResp

type CommonResp added in v1.21.3

type CommonResp[T any] struct {
	Code ErrCode `json:"code"`
	Msg  string  `json:"msg,omitempty"`
	//验证码
	Data T `json:"data,omitempty"`
}

CommonResp 主要用来接收返回,发送请使用 CommonAnyResp

func (*CommonResp[T]) Respond added in v1.21.3

func (res *CommonResp[T]) Respond(ctx context.Context, w http.ResponseWriter) (int, error)

func (*CommonResp[T]) ServeHTTP added in v1.21.3

func (res *CommonResp[T]) ServeHTTP(w http.ResponseWriter, r *http.Request)

type CorsConfig

type CorsConfig struct {
	Enabled bool
	cors.Options
}

type DebugHandlerConfig

type DebugHandlerConfig struct {
	Enabled   bool
	UriPrefix string
}

type Delimited added in v1.21.3

type Delimited interface {
	// Delimiter returns the record separator for the stream.
	Delimiter() []byte
}

Delimited defines the streaming delimiter.

type ErrCode added in v1.21.3

type ErrCode int32
const (
	// SysErr ErrCode = -1
	Success            ErrCode = 0
	Canceled           ErrCode = 1
	Unknown            ErrCode = 2
	InvalidArgument    ErrCode = 3
	DeadlineExceeded   ErrCode = 4
	NotFound           ErrCode = 5
	AlreadyExists      ErrCode = 6
	PermissionDenied   ErrCode = 7
	ResourceExhausted  ErrCode = 8
	FailedPrecondition ErrCode = 9
	Aborted            ErrCode = 10
	OutOfRange         ErrCode = 11
	Unimplemented      ErrCode = 12
	Internal           ErrCode = 13
	Unavailable        ErrCode = 14
	DataLoss           ErrCode = 15
	Unauthenticated    ErrCode = 16
)

func (ErrCode) ErrResp added in v1.21.3

func (x ErrCode) ErrResp() *ErrResp

func (ErrCode) Error added in v1.21.3

func (x ErrCode) Error() string

func (ErrCode) GRPCStatus added in v1.21.3

func (x ErrCode) GRPCStatus() *status.Status

func (ErrCode) Msg added in v1.21.3

func (x ErrCode) Msg(msg string) *ErrResp

func (ErrCode) String added in v1.21.3

func (x ErrCode) String() string

func (ErrCode) Wrap added in v1.21.3

func (x ErrCode) Wrap(err error) *ErrResp

type ErrResp added in v1.21.3

type ErrResp struct {
	Code ErrCode `json:"code"`
	Msg  string  `json:"msg,omitempty"`
}

func ErrRespFrom added in v1.21.3

func ErrRespFrom(err error) *ErrResp

func NewErrResp added in v1.21.3

func NewErrResp(code ErrCode, msg string) *ErrResp

func (*ErrResp) ErrResp added in v1.21.3

func (res *ErrResp) ErrResp() *ErrResp

func (*ErrResp) Error added in v1.21.3

func (x *ErrResp) Error() string

func (*ErrResp) GRPCStatus added in v1.21.3

func (x *ErrResp) GRPCStatus() *status.Status

func (*ErrResp) MarshalJSON added in v1.21.3

func (x *ErrResp) MarshalJSON() ([]byte, error)

func (*ErrResp) Respond added in v1.21.3

func (res *ErrResp) Respond(ctx context.Context, w http.ResponseWriter) (int, error)

func (*ErrResp) ServeHTTP added in v1.21.3

func (res *ErrResp) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Field added in v1.21.3

type Field struct {
	Name  string
	Tags  []Tag
	Index int
	Field *reflect.StructField
}

type GRPCStatus

type GRPCStatus interface {
	GRPCStatus() *status.Status
}

type GrpcAccessLog

type GrpcAccessLog = func(ctx context.Context, param *GrpcAccessLogParam)

type GrpcAccessLogParam

type GrpcAccessLogParam struct {
	Method            string
	Request, Response any
	Err               error
	Metadata          *Metadata
}

type GrpcConfig

type GrpcConfig struct {
	Addr                     string
	RecordFunc               GrpcAccessLog
	Options                  []grpc.ServerOption
	UnaryServerInterceptors  []grpc.UnaryServerInterceptor
	StreamServerInterceptors []grpc.StreamServerInterceptor
}

type GrpcHandler added in v1.21.3

type GrpcHandler[Req, Resp any, ReqPtr ProtoMessage[Req], RespPtr ProtoMessage[Resp]] func(ctx context.Context, in ReqPtr) (RespPtr, error)

type HeaderSource added in v1.21.3

type HeaderSource map[string][]string

func (HeaderSource) Get added in v1.21.3

func (hs HeaderSource) Get(key string) ([]string, bool)

type Http3Config

type Http3Config struct {
	Enabled bool
	http3.Server
	CertFile string
	KeyFile  string
}

type MarshalFunc added in v1.21.3

type MarshalFunc func(ctx context.Context, v any) (data []byte, contentType string, err error)

type Marshaler added in v1.21.3

type Marshaler interface {
	// Marshal marshals "v" into byte sequence.
	Marshal(ctx context.Context, v any) (data []byte, contentType string)
}

Marshaler defines a conversion between byte sequence and gRPC payloads / fields.

type Metadata

type Metadata struct {
	sync.RWMutex
	Logger                *log.Logger
	Data                  any
	DataM                 map[any]any
	TraceId               string
	RequestType           RequestType
	Token                 string
	AuthRaw               []byte
	AuthID                string
	Request               *http.Request
	ResponseWriter        http.ResponseWriter
	RequestAt             time.Time
	IncomingMD            metadata.MD
	ServerTransportStream grpc.ServerTransportStream
	AccessLogFields       []zap.Field
	Baggage               baggage.Baggage // can not edit
}

func GetMetadata

func GetMetadata(ctx context.Context) *Metadata

func (*Metadata) Del

func (m *Metadata) Del(key any)

func (*Metadata) Get

func (m *Metadata) Get(key any) any

func (*Metadata) GetData added in v1.21.3

func (m *Metadata) GetData() any

func (*Metadata) Set

func (m *Metadata) Set(key, value any)

func (*Metadata) SetData added in v1.21.3

func (m *Metadata) SetData(value any)

type MultipartSource added in v1.21.3

type MultipartSource multipart.Form

func (*MultipartSource) TrySet added in v1.21.3

func (ms *MultipartSource) TrySet(value reflect.Value, field *reflect.StructField, key string, opt *kvstruct.Options) (isSet bool, err error)

TrySet tries to set a value by the multipart request with the binding a form file

type OpenapiConfig

type OpenapiConfig struct {
	Enabled        bool
	UriPrefix, Dir string
}

type Option

type Option func(server *Server)

func WithContext

func WithContext(ctx context.Context) Option

func WithCors

func WithCors(handler func(cors *cors.Options)) Option

func WithGrpc

func WithGrpc(handler func(option *GrpcConfig)) Option

func WithGrpcHandler

func WithGrpcHandler(handler func(*grpc.Server)) Option

func WithHTTP3

func WithHTTP3(handler func(s *Http3Config)) Option

func WithHttp

func WithHttp(handler func(s *http.Server)) Option

func WithHttpHandler

func WithHttpHandler(handler http.Handler) Option

func WithInternalServer

func WithInternalServer(handler func(s *http.Server)) Option

func WithMiddleware

func WithMiddleware(mw ...httpx.Middleware) Option

func WithOtel

func WithOtel(handler func(otel *OtelConfig)) Option

type OtelConfig

type OtelConfig struct {
	Enabled      bool
	OtelhttpOpts []otelhttp.Option
	OtelgrpcOpts []otelgrpc.Option
}

func (*OtelConfig) SetOtelgrpcOptions

func (c *OtelConfig) SetOtelgrpcOptions(otelgrpcOpts []otelgrpc.Option)

func (*OtelConfig) SetOtelhttpOptions

func (c *OtelConfig) SetOtelhttpOptions(otelhttpOpts []otelhttp.Option)

type PrometheusConfig

type PrometheusConfig struct {
	Enabled bool
	HttpURI string
	promhttp.HandlerOpts
}

type ProtoMessage added in v1.21.3

type ProtoMessage[T any] interface {
	*T
	proto.Message
}

type QuerySource added in v1.21.3

type QuerySource map[string][]string

func (QuerySource) Get added in v1.21.3

func (req QuerySource) Get(key string) ([]string, bool)

type ReqResp added in v1.21.3

type ReqResp struct {
	*http.Request
	http.ResponseWriter
}

type RequestSource added in v1.21.3

type RequestSource struct {
	*http.Request
}

func (RequestSource) Body added in v1.21.3

func (RequestSource) Header added in v1.21.3

func (s RequestSource) Header() kvstruct.ValuesGetter

func (RequestSource) Query added in v1.21.3

func (RequestSource) Uri added in v1.21.3

func (s RequestSource) Uri() kvstruct.Getter

type RequestType

type RequestType int
const (
	RequestTypeHttp RequestType = iota
	RequestTypeGrpc
)

type Responder added in v1.21.3

type Responder interface {
	Respond(ctx context.Context, w http.ResponseWriter) (int, error)
}

type Response added in v1.21.3

type Response struct {
	Status  int                `json:"status,omitempty"`
	Headers http.Header        `json:"header,omitempty"`
	Body    iox.WriterToCloser `json:"body,omitempty"`
}

func (*Response) Respond added in v1.21.3

func (res *Response) Respond(ctx context.Context, w http.ResponseWriter) (int, error)

func (*Response) ServeHTTP added in v1.21.3

func (res *Response) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ResponseBody added in v1.21.3

type ResponseBody interface {
	ResponseBody() ([]byte, string)
}

type ResponseFile added in v1.21.3

type ResponseFile struct {
	Name        string             `json:"name"`
	Body        iox.WriterToCloser `json:"body"`
	ContentType string
}

func (*ResponseFile) Respond added in v1.21.3

func (res *ResponseFile) Respond(ctx context.Context, w http.ResponseWriter) (int, error)

func (*ResponseFile) ServeHTTP added in v1.21.3

func (res *ResponseFile) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ResponseStream added in v1.21.3

type ResponseStream struct {
	Status  int                          `json:"status,omitempty"`
	Headers http.Header                  `json:"header,omitempty"`
	Body    iter.Seq[iox.WriterToCloser] `json:"body,omitempty"`
}

func (*ResponseStream) Respond added in v1.21.3

func (res *ResponseStream) Respond(ctx context.Context, w http.ResponseWriter) (int, error)

func (*ResponseStream) ServeHTTP added in v1.21.3

func (res *ResponseStream) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ResponseWriter added in v1.21.3

type ResponseWriter interface {
	WriteHeader(code int)
	HeaderX() httpx.Header
	Write([]byte) (int, error)
}

type SSEData added in v1.21.3

type SSEData string

func (SSEData) Close added in v1.21.3

func (data SSEData) Close() error

func (SSEData) WriteTo added in v1.21.3

func (data SSEData) WriteTo(w io.Writer) (int64, error)

type Server

type Server struct {
	http.Server
	CertFile       string
	KeyFile        string
	AccessLog      AccessLogConfig
	HTTP3          Http3Config
	Cors           CorsConfig
	Grpc           GrpcConfig
	InternalServer http.Server
	Openapi        OpenapiConfig
	Otel           OtelConfig

	DebugHandler DebugHandlerConfig
	BaseContext  context.Context
	Middlewares  []httpx.Middleware
	HttpHandler  http.Handler
	GrpcHandler  func(*grpc.Server)
	// contains filtered or unexported fields
}

func NewServer

func NewServer(options ...Option) *Server

func (*Server) AfterInject

func (s *Server) AfterInject()

func (*Server) BeforeInject

func (s *Server) BeforeInject()

implement initialize

func (*Server) Init

func (s *Server) Init()

func (*Server) InternalHandler

func (s *Server) InternalHandler(mux *http.ServeMux)

InternalHandler 往内部端口的私有 mux 上注册 OpenAPI 文档与调试端点

func (*Server) Run

func (s *Server) Run()

func (*Server) StreamAccess

func (s *Server) StreamAccess(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) (err error)

func (*Server) UnaryAccess

func (s *Server) UnaryAccess(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)

func (*Server) WithContext

func (s *Server) WithContext(ctx context.Context) *Server

func (*Server) WithOptions

func (s *Server) WithOptions(options ...Option) *Server

type ServerSideStream added in v1.21.3

type ServerSideStream[Resp any, RespPtr ProtoMessage[Resp]] interface {
	Send(RespPtr) error
	grpc.ServerStream
}

type ServerSideStreamHandler added in v1.21.3

type ServerSideStreamHandler[Req, Resp any, ReqPtr ProtoMessage[Req], RespPtr ProtoMessage[Resp], S ServerSideStream[Resp, RespPtr]] func(ReqPtr, S) error

type Service added in v1.21.3

type Service[REQ, RESP any] func(ctx ReqResp, req REQ) (RESP, *ErrResp)

type Source added in v1.21.3

type Source interface {
	Uri() kvstruct.Getter
	Query() kvstruct.ValuesGetter
	Header() kvstruct.ValuesGetter
	Body() (context.Context, string, io.ReadCloser)
}

type StatusCode added in v1.21.3

type StatusCode interface {
	StatusCode(v any) int
}

type StreamContentType added in v1.21.3

type StreamContentType interface {
	// StreamContentType returns the content type for a stream. This shares the
	// same behaviour as for `Marshaler.ContentType`, but is called, if present,
	// in the case of a streamed response.
	StreamContentType(v any) string
}

StreamContentType defines the streaming content type.

type Tag added in v1.21.3

type Tag struct {
	Key     string
	Value   string
	Options *kvstruct.Options
}

type UnmarshalFunc added in v1.21.3

type UnmarshalFunc func(ctx context.Context, contentType string, data []byte, v any) error

type Unmarshaler added in v1.21.3

type Unmarshaler interface {
	Unmarshal(ctx context.Context, contentType string, data []byte, v any) error
}

type UriSource added in v1.21.3

type UriSource http.Request

func (*UriSource) Get added in v1.21.3

func (req *UriSource) Get(key string) (string, bool)

type XXXResponseBody added in v1.21.3

type XXXResponseBody interface {
	XXX_ResponseBody() any
}

Directories

Path Synopsis
api
client command
contrib
gin

Jump to

Keyboard shortcuts

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