httproxy

package module
v0.0.0-...-4e7e9c9 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: Apache-2.0 Imports: 15 Imported by: 1

README

httproxy

http服务反向代理

环境

北极星

单机版安装

go

1.16+

启动

启动grpchttp/example/hello
cd grpchttp/example/hello
go run hello.go -f ./etc/hello.yaml
启动proxy

go run proxy.go

测试

curl --location --request POST '127.0.0.1:2333/hello.Hello/Say' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "test"
}'

使用grpchttp给grpc服务注册HTTP接口 以grpchttp/example/hello为例

注意:使用较新的proto工具生产的桩代码是有可导出的Desc对象的,不需要再执行1、2步

  1. 在stub代码目录下添加文件grpchttp.go(其他合法名字也可以)。
  2. 在grpchttp.go文件中添加可导出对象ServiceDesc代码:
    package hello
    
    var ServiceDesc = _Hello_serviceDesc
    
  3. 在hello.go中注册HTTP接口
    var mux http.ServeMux
    httpgrpc.HandleServices(mux.HandleFunc, "/", reg, nil, nil)
    lis, err := net.Listen("tcp", fmt.Sprintf(":%d", c.HttpPort))
    if err != nil {
        panic(err)
    }
    logx.Infof("http port: %s", lis.Addr().String())
    
    httpServer := http.Server{Handler: &mux}
    go httpServer.Serve(lis)
    defer httpServer.Close()
    

Documentation

Index

Constants

View Source
const (
	ErrMsgKey = errMsgKey

	SnSuffix = snSuffix
)

Variables

This section is empty.

Functions

func New

func New(namespace string, gConsumer api.ConsumerAPI, opts ...Option) *httputil.ReverseProxy

Types

type Option

type Option func(cfg *OptionConf)

func WithProm

func WithProm(namespace string, path string) Option

type OptionConf

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

func (*OptionConf) Report

func (o *OptionConf) Report(pathKey string)

type Res

type Res struct {
	Code   int         `json:"code"`
	Result bool        `json:"result"`
	Info   interface{} `json:"info"`
}

Res 返回

Directories

Path Synopsis
example Module

Jump to

Keyboard shortcuts

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