当前位置: 首页 > news >正文

电子商务网站建设规划的内容/电商运营转行后悔了

电子商务网站建设规划的内容,电商运营转行后悔了,建设网站用什么技术,关于网站建设交易流程的描述一句话文章目录 环境安装protoc编译器 创建项目学习脚手架Newproto添加proto文件生成 Proto 代码生成 Service 代码 参考资料 环境 安装protoc编译器 到 Releases protocolbuffers/protobuf (github.com) 下载解压将可执行文件路径添加到PATH中安装Go插件 go install google.gola…

文章目录

  • 环境
      • 安装protoc编译器
  • 创建项目
  • 学习
    • 脚手架
      • New
      • proto
        • 添加proto文件
        • 生成 Proto 代码
        • 生成 Service 代码
  • 参考资料

环境

安装protoc编译器

  1. 到 Releases · protocolbuffers/protobuf (github.com) 下载
  2. 解压
  3. 将可执行文件路径添加到PATH中
  4. 安装Go插件
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest

安装

go install github.com/go-kratos/kratos/cmd/kratos/v2@latest

创建项目

# 国内拉取失败可使用gitee源
kratos new helloworld -r https://gitee.com/go-kratos/kratos-layout.git
# 亦可使用自定义的模板
kratos new helloworld -r xxx-layout.git
# 同时也可以通过环境变量指定源
KRATOS_LAYOUT_REPO=xxx-layout.git
kratos new helloworld
使用 -b 指定分支
kratos new helloworld -b main
使用 --nomod 添加服务,共用 go.mod ,大仓模式
kratos new helloworld
cd helloworld
kratos new app/user --nomod

生成pb和wire

# 生成所有proto源码、wire等等
go generate ./...

运行

kratos run

学习

  • 脚手架使用
  • 项目结构
  • 依赖注入
  • 日志库
  • 配置文件读取

脚手架

# kratos -h
Kratos: An elegant toolkit for Go microservices.Usage:kratos [command]Available Commands:changelog   Get a kratos change logcompletion  Generate the autocompletion script for the specified shellhelp        Help about any commandnew         Create a service templateproto       Generate the proto filesrun         Run projectupgrade     Upgrade the kratos toolsFlags:-h, --help      help for kratos-v, --version   version for kratosUse "kratos [command] --help" for more information about a command.
  • changelog: 查看kratos更新日志
  • completion: 可以为bash/fish/powershell/zsh提供命令补全
  • new: 根据模板创建一个服务,默认使用https://github.com/go-kratos/kratos-layout.git
  • proto: 生成proto文件
  • run: 运行项目,实际调用的go run命令

New

# 通过 kratos 命令创建项目模板:
kratos new helloworld# 使用gitee源
kratos new helloworld -r https://gitee.com/go-kratos/kratos-layout.git# 使用自定义的模板
kratos new helloworld -r xxx-layout.git# 同时也可以通过环境变量指定源
KRATOS_LAYOUT_REPO=xxx-layout.git
kratos new helloworld# 使用 -b 指定分支
kratos new helloworld -b main# 使用 --nomod 添加服务,共用 go.mod ,大仓模式
kratos new helloworld
cd helloworld
kratos new app/user --nomod

proto

添加proto文件

kratos-layout 项目中对 proto 文件进行了版本划分,放在了 v1 子目录下

kratos proto add api/helloworld/v1/demo.proto
syntax = "proto3";package api.helloworld.v1;option go_package = "helloworld/api/helloworld/v1;v1";
option java_multiple_files = true;
option java_package = "api.helloworld.v1";service Demo {rpc CreateDemo (CreateDemoRequest) returns (CreateDemoReply);rpc UpdateDemo (UpdateDemoRequest) returns (UpdateDemoReply);rpc DeleteDemo (DeleteDemoRequest) returns (DeleteDemoReply);rpc GetDemo (GetDemoRequest) returns (GetDemoReply);rpc ListDemo (ListDemoRequest) returns (ListDemoReply);
}message CreateDemoRequest {}
message CreateDemoReply {}message UpdateDemoRequest {}
message UpdateDemoReply {}message DeleteDemoRequest {}
message DeleteDemoReply {}message GetDemoRequest {}
message GetDemoReply {}message ListDemoRequest {}
message ListDemoReply {}

生成 Proto 代码

# 可以直接通过 make 命令生成
make api# 或使用 kratos cli 进行生成
kratos proto client api/helloworld/v1/demo.proto

生成两个文件

api/helloworld/v1/demo.pb.go
api/helloworld/v1/demo_grpc.pb.go

生成 Service 代码

通过 proto 文件,可以直接生成对应的 Service 实现代码:

使用 -t​ 指定生成目录

kratos proto server api/helloworld/v1/demo.proto -t internal/service
package serviceimport ("context"pb "helloworld/api/helloworld/v1"
)type DemoService struct {pb.UnimplementedDemoServer
}func NewDemoService() *DemoService {return &DemoService{}
}func (s *DemoService) CreateDemo(ctx context.Context, req *pb.CreateDemoRequest) (*pb.CreateDemoReply, error) {return &pb.CreateDemoReply{}, nil
}
func (s *DemoService) UpdateDemo(ctx context.Context, req *pb.UpdateDemoRequest) (*pb.UpdateDemoReply, error) {return &pb.UpdateDemoReply{}, nil
}
func (s *DemoService) DeleteDemo(ctx context.Context, req *pb.DeleteDemoRequest) (*pb.DeleteDemoReply, error) {return &pb.DeleteDemoReply{}, nil
}
func (s *DemoService) GetDemo(ctx context.Context, req *pb.GetDemoRequest) (*pb.GetDemoReply, error) {return &pb.GetDemoReply{}, nil
}
func (s *DemoService) ListDemo(ctx context.Context, req *pb.ListDemoRequest) (*pb.ListDemoReply, error) {return &pb.ListDemoReply{}, nil
}

参考资料

Go工程化 - Project Layout 最佳实践

推荐一个零声学院免费教程,个人觉得老师讲得不错,分享给大家:Linux,Nginx,ZeroMQ,MySQL,Redis,
fastdfs,MongoDB,ZK,流媒体,CDN,P2P,K8S,Docker,
TCP/IP,协程,DPDK等技术内容,点击立即学习

http://www.jmfq.cn/news/4858363.html

相关文章:

  • app开发公司电话/seo关键词推广
  • 网络平台怎么搭建网站/如何搜索关键词热度
  • 动态网站开发语言介绍/网络营销工作内容
  • 线下引流的八种推广方式/seo如何优化网站步骤
  • 龙岩亿网行/重庆seo黄智
  • 中国少数民族网站建设/新型网络营销方式
  • 修改wordpress上传文件限制/seo值是什么意思
  • 郑州网站制作天强科技/免费智能seo收录工具
  • 认识网络营销/网站关键词快速优化
  • 网站搜索推广方案论文/百度免费发布信息
  • 湛江低价网站建设/seo排名点击器
  • 怎么用dede建设网站/seo专员工作内容
  • 做网站的好处/百度搜一下
  • 网站如何调用手机淘宝做淘宝客/各引擎收录查询
  • 腾讯云建站流程/全网最全搜索引擎app
  • 合肥有哪些做网站的公司/百度seo排名工具
  • 东莞齐诺做网站/什么网站都能进的浏览器
  • 英语网站online/什么是关键词推广
  • 公司做的网站过期了/网络营销技巧培训班
  • 郑州网站优化托管/农产品营销方案
  • 万网虚拟服务器怎么做网站内容/中国搜索引擎大全
  • 网站管理服务/比优化更好的词是
  • 图片 网站开发/市场监督管理局
  • 高端广告公司名字/北京专门做seo
  • wordpress4.6 中文/上海全国关键词排名优化
  • 网站解析/种子搜索引擎在线
  • 07年以前东莞有多乱/宁波网站seo诊断工具
  • 网页qq无法使用快捷登录/北京做网络优化的公司
  • 网站开发业务怎么做/宁波seo外包服务商
  • 网站开发 开题报告/网络品牌推广