Go-Micro rpc调用注册的服务
简介Go-Micro rpc调用注册的服务
1、目录结构
micro-home:项目目录
service:服务目录
model:proto生成的目录
proto:proto定义目录
main.go:入口
make_proto.bat:生成proto
2、要实现调用rpc服务,就直接把服务端的proto文件拷贝的客户端
3、拷贝make_proto.bat到客户端
4、main.go内容
package main
import (
"github.com/gin-gonic/gin"
"github.com/micro/go-micro"
"github.com/micro/go-micro/registry"
"github.com/micro/go-micro/web"
"github.com/micro/go-plugins/registry/consul"
services "micro-home/service/model"
"strconv"
)
func InitMiddleware(service services.StudentListService) gin.HandlerFunc {
return func(context *gin.Context) {
context.Keys = make(map[string]interface{})
context.Keys["student_service"] = service
context.Next()
}
}
func main() {
register := consul.NewRegistry(func(options *registry.Options) {
options.Addrs = []string{
"192.168.1.171:8500",
"192.168.1.177:8500",
"192.168.1.178:8500",
}
})
//微服务需要注册
homeService := micro.NewService(micro.Name("micro-home-client"), micro.Registry(register))
//实例化服务
studentListService := services.NewStudentListService("student-service", homeService.Client())
routers := gin.Default()
routers.Use(InitMiddleware(studentListService)) //使用中间件,将服务传递到context中
routers.GET("/", func(context *gin.Context) {
service := context.Keys["student_service"].(services.StudentListService)
number := context.DefaultQuery("number", "0")
num, err := strconv.Atoi(number)
if err != nil {
num = 1
}
if num <= 0 {
num = 1
}
studentListResponse, err := service.GetStudentListService(context, &services.StudentListRequest{
Num: int32(num),
})
if err != nil {
context.JSON(200, gin.H{
"status": "",
"data": err.Error(),
})
} else {
context.JSON(200, gin.H{
"status": studentListResponse.Status,
"data": studentListResponse.Data,
})
}
})
service := web.NewService(
web.Name("home-service-api"),
web.Address(":8081"),
web.Handler(routers),
web.Registry(register),
)
service.Run()
}
打包出现如下错误:Error: Application entry file "dist\electron\main.js" in the "D:\gui\demo2\build\win-unpacked\resources\app.asar" does not exist. Seems like a wrong configuration.
最近在使用Golang的WEB框架Iris做了一个小的系统,但是里面有一些静态的资源,如css、js、html文件,如果只是通过go build打包的这些静态文件是打包不进去的,所以本文主要记录下如何将所以文件都打包的二进制文件中。
nodejs中使用npm和yarn,使用最新阿里云镜像 aliyun mirror,网上很多还是文章用的是下面这个地址~~yarn config set registry https://registry.npm.taobao.org~~
Nginx作为使用量非常大的Web服务器,但是如果遇到一个访问量比较大的网站,其访问日志会快速的进行增长,如果一直将所有的访问日志存放在一个文件中肯定是不对的,所以我们就需要对访问量大的访问日志进行分割,然后按照一定的时间删除不需要的日志文件。
在做搜索列表分页的时候,需要分页后的页面跳转的url地址中包含搜索的参数,在Laravel中的如何处理呢?
快速生成表格
在使用Git的过程中,不想每次都输入用户名和密码去拉取代码,所以就需要保存这些信息,那么既然有保存了,就必须有清除功能。
在Mac电脑中,如何对Git的用户名和密码进行修改呢?起初不懂Mac,所以整了很久,本文将记录如何对这个进行操作,以便后期使用。
Docker编译镜像出现:fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.12/main: temporary error (try again later)
WARNING: Ignoring APKINDEX.2c4ac24e.tar.gz: No such file or directory问题