longjoy / micro-go-book Goto Github PK
View Code? Open in Web Editor NEW《Go语言高并发与微服务实战》代码
License: MIT License
《Go语言高并发与微服务实战》代码
License: MIT License
请问令牌相关的方法是在哪里实现的呢?
有点晕
这行的语句
tokenService.tokenEnhancer != nil
这句可能会有个坑,关于Interface跟nil做比较,可能得先转换才能做比较
tokenService.tokenEnhancer.(*JwtTokenEnhancer) != nil
举个例子:
func main() {
var a1 *a
b := test{t1:a1}
fmt.Println(b.isT1())
}
type test struct {
t1 test1
}
func (this *test)isT1() bool {
return this.t1 == nil
}
type test1 interface {
t()
}
type a struct {}
func (this *a)t() {}
以上代码输出false,但是吧
this.t1 == nil
改成
this.t1.(*a) == nil
后输出true
为什么我运行main函数总是注册服务失败
ch5-web/gin/main.go中AuthMiddleWare函数的第3行check(token), 编译器无法解析check函数
var tokenService service.TokenService
var tokenGranter service.TokenGranter
var tokenEnhancer service.TokenEnhancer
var tokenStore service.TokenStore
var userDetailsService service.UserDetailsService
var clientDetailsService service.ClientDetailsService
var srv service.Service
tokenEnhancer = service.NewJwtTokenEnhancer("secret")
tokenStore = service.NewJwtTokenStore(tokenEnhancer.(*service.JwtTokenEnhancer))
tokenService = service.NewTokenService(tokenStore, tokenEnhancer)
这里的定义感觉不太好,
service.NewJwtTokenStore(tokenEnhancer.(*service.JwtTokenEnhancer))
这里的形参应该定义成接口,而这里声明部分使用了接口声明,
然后NewJwtTokenEnhancer以后传给接口变量,最后传给NewJwtTokenStore做实参的时候又将接口类型转换成结构体
规范写法应该在NewJwtTokenStore接收的地方就是接口
这样写让看代码的人感觉结构不清晰
ch4-feature/reflection/reflection.go
func (hero *Hero) Run() string {
fmt.Println("I am running at speed " + string(hero.Speed))
return "Running"
}
应该改为
fmt.Println("I am running at speed ", hero.Speed)
同时书中81页的预期输出
I am running at speed d
应改为
I am running at speed 100
希望把秒杀系统代码加进来,想整体学习一下。
文件地址
第46行应该是CreateProductEndpoint
没有在ch8-config文件夹下发现有 config-service项目
想请问作者觉得这本书值得看吗 关于这本书看到了一些好评也看到了不少中评
instanceList, ok := consulClient.instancesMap.Load(serviceName) 这个报错:代码没有实现LOAD()方法和Store()方法等
github上的代码有一部分被注释了, 书上的没注释。我取消注释的话没什么问题吧
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.