基于 Protobuf 的 RPC/REST 迷你框架 pbgo

码农软件 · 软件分类 · REST/RESTful项目 · 2019-03-10 16:28:38

软件介绍

基于Protobuf定义接口规范,通过pbgo提供的插件生成RPC和REST相关代码。

创建hello.proto文件,定义接口规范:

syntax = "proto3";
package hello_pb;

import "github.com/chai2010/pbgo/pbgo.proto";

message String {
    string value = 1;
}

service EchoService {
    rpc Echo (String) returns (String) {
        option (pbgo.rest_api) = {
            get: "/echo/:value"
        };
    }
}

用pbgo插件生成代码:

$ protoc -I=. -I=$(GOPATH)/src --pbgo_out=. hello.proto

创建REST服务:

type EchoService struct{}

func (p *EchoService) Echo(request *hello_pb.String, reply *hello_pb.String) error {
    *reply = *request
    return nil
}

func main() {
    router := hello_pb.EchoServiceHandler(new(EchoService))
    log.Fatal(http.ListenAndServe(":8080", router))
}

测试REST服务:

$ curl localhost:8080/echo/gopher
{"value":"gopher"}

$ curl localhost:8080/echo/gopher?value=cgo
{"value":"cgo"}

详细的例子请参考:https://github.com/chai2010/pbgo/blob/master/examples/hello.p

本文地址:https://codercto.com/soft/d/1051.html

Python 3网络爬虫开发实战

Python 3网络爬虫开发实战

崔庆才 / 人民邮电出版社 / 2018-4 / 99

本书介绍了如何利用Python 3开发网络爬虫,书中首先介绍了环境配置和基础知识,然后讨论了urllib、requests、正则表达式、Beautiful Soup、XPath、pyquery、数据存储、Ajax数据爬取等内容,接着通过多个案例介绍了不同场景下如何实现数据爬取,后介绍了pyspider框架、Scrapy框架和分布式爬虫。 本书适合Python程序员阅读。一起来看看 《Python 3网络爬虫开发实战》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器