Socket
Book a DemoInstallSign in
Socket

github.com/xyy277/gallery

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/xyy277/gallery

Source
Go
Version
v0.3.2
Version published
Created
Source

模块封装

依赖

  • go get github.com/xyy277/gallery

  • Init初始化

代码结构

├── auth
│   ├── luna
│   └── star
├── cache
├── config
├── constant
├── core
├── global
│   ├── request
│   └── response
├── log
├── oss
├── util
└── util

文件夹说明描述
authauth 组件auth 接口
--lunaauth 平台组件auth 平台组件接口
--starauth 业务组件auth 业务组件接口
cachecache组件cache接口
config配置文件组件配置
constantconstant常量constant常量
core核心包核心包
global全局对象全局对象
--request入参结构体接收前端发送到后端的数据。
--response出参结构体返回给前端的数据结构体
log日志组件日志组件接口
ossoss组件oss组件接口
util工具包工具函数封装

ProtoBuf

安装protoc

https://github.com/protocolbuffers/protobuf/releases/

  • linux 安装
    测试protoc -h
  • windwos 安装
    测试 protoc --version

安装protobuf-go

https://github.com/protocolbuffers/protobuf-go

获取 proto包(Go语言的proto API接口)

  • go get -v -u github.com/golang/protobuf/proto
  • go get -v -u github.com/golang/protobuf/protoc-gen-go

编译protoc-gen-go

  • cd $GOPATH/src/github.com/golang/protobuf/protoc-gen-go/
  • go build

将生成的 protoc-gen-go可执行文件,放在/bin目录下

  • sudo cp protoc-gen-go /bin/

或直接下载安装本地

https://github.com/protocolbuffers/protobuf-go/releases

创建.proto文件

定义message格式

编译.proto文件

protoc 编译生成.go文件 编译后的.pb.go文件无法修改

  • protoc --proto_path=IMPORT_PATH --go_out=DST_DIR path/to/file.proto

  • protoc --go_out=. *.proto 将本地当前文件下所有.proto文件全部编译并将结果放在当前文件夹下

--proto_path,指定了 .proto 文件导包时的路径,可以有多个,如果忽略则默认当前目录。

--go_out, 指定了生成的go语言代码文件放入的文件夹

允许使用protoc --go_out=./ *.proto的方式一次性编译多个 .proto 文件

编译时,protobuf 编译器会把 .proto 文件编译成 .pd.go 文件

使用.proto开发

FAQs

Package last updated on 16 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts