golang 中获取字符串个数 在 golang 中不能直接用 len 函数来统计字符串长度,查看了下源码发现字符串是以 UTF-8 为格式存储的,说明 len 函数是取得包含 byte 的个数 // string is the set of all strings of 8-bit bytes, conventionally but not // necessarily representing UTF-8-encoded text. A string may be empty, but //
Spring Cloud Gateway 获取请求体 一.直接在全局拦截器中获取,伪代码如下 private String resolveBodyFromRequest(ServerHttpRequest serverHttpRequest){ Flux<DataBuffer> body = serverHttpRequest.getBody(); AtomicReference<String> bodyRef = new AtomicReference<>(); bo
结构体: 1.用来自定义复杂数据结构 2.struct里面可以包含多个字段(属性) 3.struct类型可以定义方法,注意和函数的区分 4.strucr类型是值类型 5.struct类型可以嵌套 6.go语言中没有class类型,只有struct类型 struct声明: type 标识符 struct{ field1 type field2 type } 例子: type Student struct{ Name string Age int Score int } struct中字段访问,
golang允许使用匿名结构体,形如 type Test struct { param1 struct { param2 string } } 一般在使用的时候可以直接这样初始化 a := Test{ param1: struct{ param2 string }{param2: "test"}, } 或者 b := new(Test) b.param1.param2 = "test" 但今天遇到一种情况 匿名结构体的成员上有tag声明,形如 type Test s
win7 环境,主要是一开始想在代码中先用exec.Command启动chrome,但始终不能成功监听9222端口,折腾了很长时间, 需要先手工启动chrome监听端口,具体写在代码注释中了. 然后再运行代码,代码只是在开源代码基础上稍作修改,将访问不了的google换成sohu.代码效果就是通过代码将浏览器导航到了sohu.com // Command standalone is a chromedp example demonstrating how to use chromedp // w